import { createWalletClientForWalletAccount } from '@dynamic-labs-sdk/evm/viem';
const signTypedData = async (walletAccount) => {
const walletClient = await createWalletClientForWalletAccount({ walletAccount });
const domain = {
name: 'Example Message',
version: '1.0.0',
chainId: 1,
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
};
const types = {
Person: [
{ name: 'name', type: 'string' },
{ name: 'wallet', type: 'address' },
],
Mail: [
{ name: 'from', type: 'Person' },
{ name: 'to', type: 'Person' },
{ name: 'contents', type: 'string' },
],
};
const message = {
from: { name: 'Cow', wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826' },
to: { name: 'Bob', wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB' },
contents: 'Hello, Bob!',
};
const signature = await walletClient.signTypedData({
domain,
types,
primaryType: 'Mail',
message,
});
console.log('signature', signature);
return signature;
};