signTypedData
Action for signing typed data with connected account.
This is a wrapper around viem's signTypedData
.
import { signTypedData } from '@wagmi/core'
Usage
The following examples use the typed data:
// All properties on a domain are optional
const domain = {
name: 'Ether Mail',
version: '1',
chainId: 1,
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
} as const
// The named list of all type definitions
const types = {
Person: [
{ name: 'name', type: 'string' },
{ name: 'wallet', type: 'address' },
],
Mail: [
{ name: 'from', type: 'Person' },
{ name: 'to', type: 'Person' },
{ name: 'contents', type: 'string' },
],
} as const
const message = {
from: {
name: 'Cow',
wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
},
to: {
name: 'Bob',
wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
},
contents: 'Hello, Bob!',
} as const
From now on, the typed data variables (above) are referenced only by name for brevity.
import { signTypedData } from '@wagmi/core'
const signature = await signTypedData({
domain,
message,
primaryType: 'Mail',
types,
})
Return Value
string
Configuration
domain
Typed data domain.
import { signTypedData } from '@wagmi/core'
const signature = await signTypedData({
domain: {
name: 'Ether Mail',
version: '1',
chainId: 1,
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
},
message,
primaryType: 'Mail',
types,
})
message
Typed data message.
import { signTypedData } from '@wagmi/core'
const signature = signTypedData({
domain,
message: {
from: {
name: 'Cow',
wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
},
to: {
name: 'Bob',
wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
},
contents: 'Hello, Bob!',
},
primaryType: 'Mail',
types,
})
primaryType
The primary type to extract from types
and use in message
.
import { signTypedData } from '@wagmi/core'
const signature = signTypedData({
domain,
message,
primaryType: 'Mail',
types,
})
types
Typed data type definition.
By defining inline or adding a const assertion to types
, TypeScript will infer the correct types value
. See the wagmi TypeScript docs for more information.
import { signTypedData } from '@wagmi/core'
const signature = signTypedData({
domain,
message,
primaryType: 'Mail',
types: {
Person: [
{ name: 'name', type: 'string' },
{ name: 'wallet', type: 'address' },
],
Mail: [
{ name: 'from', type: 'Person' },
{ name: 'to', type: 'Person' },
{ name: 'contents', type: 'string' },
],
},
})