Overview
Embedded wallets fully support EIP-712 typed data signing, allowing you to sign structured data for applications like permit transactions, meta-transactions, and other advanced use cases. The signing process works seamlessly with the same interface as external wallets while leveraging the security benefits of multi-party computation.Basic EIP-712 Typed Data Signing
- React
- React Native
- Swift
- Flutter
Copy
Ask AI
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isEthereumWallet } from '@dynamic-labs/ethereum';
const SignTypedDataButton = () => {
const { primaryWallet } = useDynamicContext();
const signTypedData = async () => {
if (!primaryWallet || !isEthereumWallet(primaryWallet)) return;
const domain = {
name: 'Example DApp',
version: '1.0.0',
chainId: 1,
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' },
],
};
const message = {
from: {
name: 'Alice',
wallet: primaryWallet.address,
},
to: {
name: 'Bob',
wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
},
contents: 'Hello, this is a signed message!',
};
const typedData = {
primaryType: 'Mail' as const,
domain,
types,
message
};
try {
const walletClient = await primaryWallet.getWalletClient();
const signature = await walletClient.signTypedData(typedData);
console.log('Typed data signature:', signature);
return signature;
} catch (error) {
console.error('Error signing typed data:', error);
throw error;
}
};
return (
<button onClick={signTypedData}>
Sign Typed Data
</button>
);
};
React Native
Copy
Ask AI
// Requires setting up the RN Viem extension
// See: /react-native/wallets/viem
import { dynamicClient } from '<path-to-your-dynamicClient>'; // extended with ViemExtension
export const signTypedData = async () => {
const wallet = dynamicClient.wallets.primary;
if (!wallet) return;
const walletClient = dynamicClient.viem.createWalletClient({ wallet });
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 } as const;
const signature = await walletClient.signTypedData(typedData);
console.log('signature', signature);
}
Coming soon
Coming soon