Sign Typed Data in Ethereum/EVM
The Basics
- Installing Dynamic
- Chains / Networks
- Authentication
- Wallets
- Users / VC's
- Design
- Onramps
Beyond The Basics
- Headless
- Cross-ecosystem Connectivity
- Bridge Widget
- Rate Limits
Developer Dashboard
- SDK and API Keys
- Sandbox vs Live
- Analytics
- User Management
- Test Accounts
- Settings
- Admin
- Webhooks
- Configuring Social Providers
Tutorials
- Farcaster
- Telegram
- Features
- Frameworks
- Integrations
- Webhooks
Migrating to Dynamic
- Migrating to Dynamic
- Migration Tutorials
For Wallets & Chains
Hackathons
Sign Typed Data in Ethereum/EVM
Use the Viem SignTypedData method for EIP-712 data.
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
const SignTypedDataButton = () => {
const { primaryWallet } = useDynamicContext();
const signTypedData = async () => {
if (!primaryWallet) return;
const domain = {
name: 'Example Message',
version: '1.0.0',
chainId: 1,
salt: '0',
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC' as `0x${string}`,
};
const types = {
Person: [
{name: 'name', type: 'string'},
{name: 'wallet', type: 'address'},
],
Mail: [
{name: 'from', type: 'Person'},
{name: 'to', type: 'Person'},
{name: 'contents', type: 'string'},
],
EIP712Domain: [
{
name: 'name',
type: 'string',
},
{
name: 'version',
type: 'string',
},
{
name: 'chainId',
type: 'uint256',
},
{
name: 'salt',
type: 'string',
},
{
name: 'verifyingContract',
type: 'string',
},
],
};
const message = {
from: {
name: 'Cow',
wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
},
to: {
name: 'Bob',
wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
},
contents: 'Hello, Bob!',
};
const typedData = {primaryType: 'Mail', domain, types, message};
const walletClient = primaryWallet.getWalletClient();
const signature = await walletClient.signTypedData(typedData);
console.log('signature', signature);
};
return <button onClick={signTypeData}>Sign typed data</button>;
};
Was this page helpful?