Sign Data
You can use the following RPC methods to request cryptographic signatures from users:
eth_signTypedData_v4
- Use this method to request the most human-readable signatures that are efficient to process on-chain. We recommend this for most use cases.eth_sign
- Use this method for the easiest way to request human-readable signatures that don't need to be efficiently processed on-chain.
Use eth_signTypedData_v4
eth_signTypedData_v4
provides the most human-readable signatures that are efficient to process on-chain. It follows the EIP-712 specification to allow users to sign typed structured data that can be verified on-chain. It renders the structured data as usefully as possible to the user (for example, displaying known account names in place of addresses).
An eth_signTypedData_v4
payload uses a standard format of encoding structs, but has a different format for the top-level struct that is signed, which includes some metadata about the verifying contract to provide replay protection of these signatures between different contract instances.
We recommend using eth-sig-util
to generate and validate signatures. You can use eip712-codegen
to generate most of the Solidity required to verify these signatures on-chain. It currently doesn't generate the top-level struct verification code, so you must write that part manually.
Example
Use eth_sign
eth_sign
is the easiest way to request human-readable signatures that don't need to be efficiently processed on-chain. It's often used for signature challenges that are authenticated on a web server, such as Sign-In with Ethereum.
Example
The following is an example of using eth_sign
with Sender.
Last updated