Sign typed data

This guide will teach you how to sign EIP-712 typed data with your Smart Wallet. Typed data signing provides a more structured and secure way to sign complex data compared to plain text messages.

Prerequisites

  • API key from your dashboard
  • A Smart Wallet with an associated signer

What is typed data signing?

EIP-712 typed data signing allows users to:

  • Sign structured data with clear type definitions
  • Improve user experience with readable signature requests
  • Enhance security through type safety and domain separation

Typed data follows the EIP-712 standard, which provides a way to encode structured data for signing.

Implementation

Required SDK version: ^v4.59.1

See the signTypedData SDK reference for full descriptions of the parameters used in the following example.

1import { client } from "./client";
2
3// Sign typed data
4const typedData = {
5 domain: {
6 name: "MyDApp",
7 version: "1",
8 chainId: 1,
9 verifyingContract: "0x...",
10 },
11 types: {
12 Auth: [
13 { name: "user", type: "address" },
14 { name: "nonce", type: "uint256" },
15 { name: "timestamp", type: "uint256" },
16 ],
17 },
18 primaryType: "Auth",
19 message: {
20 user: "0x...", // wallet address
21 nonce: 12345,
22 timestamp: Date.now(),
23 },
24} as const;
25
26const signature = await client.signTypedData(typedData);
27
28console.log("Typed data signature:", signature);

Typed data structure

EIP-712 typed data consists of four main components:

Domain

The domain provides context and prevents signature reuse across different dApps:

1const domain = {
2 name: "Example DApp",
3 version: "1",
4 chainId: 1,
5 verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
6};

Types

Define the structure of your data:

1const types = {
2 Person: [
3 { name: "name", type: "string" },
4 { name: "wallet", type: "address" },
5 ],
6 Mail: [
7 { name: "from", type: "Person" },
8 { name: "to", type: "Person" },
9 { name: "contents", type: "string" },
10 ],
11};

Primary type

Specify which type is the main type being signed:

1const primaryType = "Mail";

Message

The actual data to sign:

1const message = {
2 from: {
3 name: "Alice",
4 wallet: "0xAaAaAaAaAaAaAaAaAaAAAAAAAAaaaAaAaAaaAaAa",
5 },
6 to: {
7 name: "Bob",
8 wallet: "0xBbBbBbBbBbBbBbBbBbBBBBBBBBbbBbBbBbbBbBb",
9 },
10 contents: "Hello, Bob!",
11};

Next steps

Build more:

Troubleshooting: