API
@joyid/evm
signTypedData

signTypedData

Signs typed data and calculates an Ethereum-specific signature in EIP-712 (opens in a new tab), return a signature hex string.

The TypedData struct is defined as abitype (opens in a new tab).

Types

function signTypedData(typedData: TypedData, signerAddress?: string): Promise<string>

Example

import { signTypedData } from '@joyid/evm'
 
const typedData = {
  domain: {
    name: 'Ether Mail',
    version: '1',
    chainId: 1,
  verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
  },
  types: {
    Person: [
      { name: 'name', type: 'string' },
      { name: 'wallet', type: 'address' },
    ],
    Mail: [
      { name: 'from', type: 'Person' },
      { name: 'to', type: 'Person' },
      { name: 'contents', type: 'string' },
    ],
  },
  primaryType: 'Mail',
  message: {
    from: {
      name: 'Cow',
      wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
    },
    to: {
      name: 'Bob',
      wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
    },
    contents: 'Hello, Bob!',
  },
}
 
async function signTypedDataOnClick() {
  const signature = await signTypedData(typedData, '<your connected address>')
  console.log(`Signature: ${signature}`)
}