Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.phantom.com/llms.txt

Use this file to discover all available pages before exploring further.

Sign structured, typed data using the EIP-712 standard. This provides a better user experience by showing human-readable data in the wallet.
import { useEthereum } from "@phantom/react-sdk";

function SignTypedData() {
  const { ethereum } = useEthereum();

  const sign = async () => {
    const accounts = await ethereum.getAccounts();

    const typedData = {
      types: {
        EIP712Domain: [
          { name: "name", type: "string" },
          { name: "version", type: "string" },
          { name: "chainId", type: "uint256" },
          { name: "verifyingContract", type: "address" },
        ],
        Order: [
          { name: "from", type: "address" },
          { name: "to", type: "address" },
          { name: "amount", type: "uint256" },
          { name: "nonce", type: "uint256" },
        ],
      },
      primaryType: "Order",
      domain: {
        name: "My App",
        version: "1",
        chainId: 1,
        verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
      },
      message: {
        from: accounts[0],
        to: "0x742d35Cc6634C0532925a3b8D4C8db86fB5C4A7E",
        amount: "1000000000000000000",
        nonce: 1,
      },
    };

    const { signature } = await ethereum.signTypedData(typedData, accounts[0]);
    console.log("Signature:", signature);
    return signature;
  };

  return <button onClick={sign}>Sign Order</button>;
}

Verify with viem

import { verifyTypedData } from "viem";

const isValid = await verifyTypedData({
  address: signerAddress,
  domain: typedData.domain,
  types: typedData.types,
  primaryType: typedData.primaryType,
  message: typedData.message,
  signature,
});