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.
CAUTION
Since the top-level struct type's name and the domain.name
are presented to the user prominently in the confirmation, consider your contract name, the top-level struct name, and the struct keys to be a user-facing security interface. Ensure your contract is as readable as possible to the user.
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.
IMPORTANT
Don't use this method to display binary data, because the user wouldn't be able to understand what they're agreeing to.
If using this method for a signature challenge, think about what would prevent a phisher from reusing the same challenge and impersonating your site. Add text referring to your domain, or the current time, so the user can easily verify if this challenge is legitimate.
Example
The following is an example of using eth_sign
with Sender.
Last updated