eip712
Generates Solidity code to verify EIP-712 style signatures.
Usage
First, create an abstract contract implementing the functionality you want:
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.11;
abstract contract NameRegistry {
mapping (string => address) public nameToAddress;
mapping (address => string) public addressToName;
// This `claim` function implements the functionality you want to expose
// via an EIP-712 signature.
//
// Importantly, the first argument must be the sender's address, and
// the function must be internal.
function claim(address sender, string memory name) internal {
require(bytes(addressToName[sender]).length == 0, "address already registered");
require(nameToAddress[name] == address(0), "name already registered");
addressToName[sender] = name;
nameToAddress[name] = sender;
}
// You can optionally expose your functionality using `msg.sender`.
function claim(string memory name) external {
claim(msg.sender, name);
}
// Finally, you should declare an abstract function that accepts a signature.
//
// The implementation will be generated for you.
function claim(string memory name, uint8 v, bytes32 r, bytes32 s) external virtual;
}
On the Command Line
Install eip712-cli:
Then run it with:
As a Library
For advanced uses, this crate can be used as a library from Rust or JavaScript.
Rust
use Eip712;
use Write;
JavaScript
import from './eip712.js';
;