Skip to main content

eth_signTypedData_v4

Enables passport users to sign EIP-712 structured messages off-chain.

Params

  1. Address: string. The address that will sign the message.
  2. TypedData: string | Object. A JSON in either string or object form that conforms to the EIP-712 TypedData JSON schema.

Result

Returns a Promise that resolves with a string, representing the resulting hex-encoded signature. For an example on validating the authenticity of this signature, check out this guide.

Example

const address = '0xabb12d14E1d89014F795bA359bBA6De724F5936E'
const typedData = {
domain: {
name: 'Ether Mail',
version: '1',
chainId,
verifyingContract: address,
},
message: {
from: {
name: 'Cow',
wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
},
to: {
name: 'Bob',
wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
},
contents: 'Hello, Bob!',
},
primaryType: 'Mail',
types: {
EIP712Domain: [
{
name: 'name',
type: 'string',
},
{
name: 'version',
type: 'string',
},
{
name: 'chainId',
type: 'uint256',
},
{
name: 'verifyingContract',
type: 'address',
},
],
Person: [
{
name: 'name',
type: 'string',
},
{
name: 'wallet',
type: 'address',
},
],
Mail: [
{
name: 'from',
type: 'Person',
},
{
name: 'to',
type: 'Person',
},
{
name: 'contents',
type: 'string',
},
],
},
}
const signature = await provider.request({
method: 'eth_signTypedData_v4',
params: [address, typedData]
})
console.log(signature) // '0x...'