TypedData.encode
Encodes typed data in EIP-712 format: 0x19 ‖ 0x01 ‖ domainSeparator ‖ hashStruct(message)
.
Imports
Named
import { TypedData } from 'ox'
Examples
import { TypedData, Hash } from 'ox'
const data = TypedData.encode({
domain: {
name: 'Ether Mail',
version: '1',
chainId: 1,
verifyingContract: '0x0000000000000000000000000000000000000000',
},
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!',
},
})
'0x19012fdf3441fcaf4f30c7e16292b258a5d7054a4e2e00dbd7b7d2f467f2b8fb9413c52c0ee5d84264471806290a3f2c4cecfc5490626bf912d01f240d7a274b371e' (0x19 ‖ 0x01 ‖ domainSeparator ‖ hashStruct(message)) const hash = Hash.keccak256(data)
Definition
function encode<typedData, primaryType>(
value: encode.Value<typedData, primaryType>,
): Hex.Hex
Source: src/TypedData.ts
Parameters
value
- Type:
encode.Value<typedData, primaryType>
The Typed Data to encode.
Return Type
The encoded Typed Data.
Hex.Hex
Error Type
TypedData.encode.ErrorType