Skip to content

Fix EIP-712 signing failure in Farcaster miniapp — BigInt chainId serialization #625

@realproject7

Description

@realproject7

Bug

Agent wallet binding (setAgentWallet) fails in the Farcaster miniapp with:

"Unable to parse chainId from eth_signTypedData_v4 params"

Works fine with MetaMask on desktop.

Root Cause

The EIP-712 domain in AgentManage.tsx and AgentRegister.tsx uses BigInt for chainId:

const EIP712_DOMAIN = {
  chainId: BigInt(BASE_CHAIN_ID),  // BigInt
};

Viem's serializeTypedData() calls its custom stringify() which converts BigInt to string: BigInt(8453).toString()"8453".

The JSON sent to the wallet becomes:

{ "domain": { "chainId": "8453" } }
  • MetaMask: injected provider, lenient parser — accepts string "8453"
  • Farcaster miniapp: JSON-RPC bridge to native Warpcast app, strict parser — expects number 8453, rejects string "8453"

Fix

Change BigInt(BASE_CHAIN_ID) to Number(BASE_CHAIN_ID) in the EIP-712 domain. Number survives JSON.stringify as a number literal (8453), not a string.

const EIP712_DOMAIN = {
  name: "ERC8004IdentityRegistry",
  version: "1",
  chainId: Number(BASE_CHAIN_ID),  // Number, not BigInt
  verifyingContract: ERC8004_REGISTRY,
};

Note: BASE_CHAIN_ID is already a Number (from constants.ts line 14), so BigInt() wrapping was unnecessary.

Files to modify

  • src/components/AgentManage.tsx — line 24: BigInt(BASE_CHAIN_ID)Number(BASE_CHAIN_ID)
  • src/components/AgentRegister.tsx — same change in EIP712_DOMAIN

Branch

task/625-eip712-chainid-fix

Acceptance criteria

  • Agent wallet binding works in Farcaster miniapp (no chainId parse error)
  • Agent wallet binding still works with MetaMask
  • Both AgentManage and AgentRegister updated
  • Build passes

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/T3Assigned to T3 builder agent

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions