verifyTypedData
Verifies a typed data signature
Verify that typed data was signed by the provided address.
Supports verification of:
- Externally Owned Accounts
- Smart Contract Accounts:
Import
Import the public actions package so you can call this action.
import "github.com/ChefBingbong/viem-go/actions/public"Usage
An example showing how to verify an EIP-712 typed data signature against a given address.
import ( "context" "log" "math/big"
"github.com/ethereum/go-ethereum/common" "github.com/ChefBingbong/viem-go/actions/public" "github.com/ChefBingbong/viem-go/utils/signature" "github.com/ChefBingbong/viem-go/client" "github.com/ChefBingbong/viem-go/client/transport" "github.com/ChefBingbong/viem-go/chain/definitions")
ctx := context.Background()
publicClient, err := client.CreatePublicClient(client.PublicClientConfig{ Chain: definitions.Mainnet, Transport: transport.HTTP("https://eth.llamarpc.com"),})if err != nil { log.Fatal(err)}defer func() { _ = publicClient.Close() }()
typedData := signature.TypedDataDefinition{ Domain: signature.TypedDataDomain{ Name: "Ether Mail", Version: "1", ChainId: big.NewInt(1), VerifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC", }, Types: map[string][]signature.TypedDataField{ "Person": { {Name: "name", Type: "string"}, {Name: "wallet", Type: "address"}, }, "Mail": { {Name: "from", Type: "Person"}, {Name: "to", Type: "Person"}, {Name: "contents", Type: "string"}, }, }, PrimaryType: "Mail", Message: map[string]any{ "from": map[string]any{ "name": "Cow", "wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826", }, "to": map[string]any{ "name": "Bob", "wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB", }, "contents": "Hello, Bob!", },}
valid, err := public.VerifyTypedData(ctx, publicClient, public.VerifyTypedDataParameters{ Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"), TypedData: typedData, Signature: "0x...",})if err != nil { log.Fatal(err)}log.Printf("Valid: %v", valid)Returns
bool
Whether the signed typed data is valid for the given address.
Parameters
Configuration options accepted by this action.
Address
- Type:
common.Address - Required
The Ethereum address that signed the original typed data.
import ( "github.com/ethereum/go-ethereum/common" "github.com/ChefBingbong/viem-go/actions/public")
valid, err := public.VerifyTypedData(ctx, publicClient, public.VerifyTypedDataParameters{ Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"), TypedData: typedData, Signature: "0x...",})TypedData
- Type:
signature.TypedDataDefinition - Required
The full EIP-712 typed data definition, including domain, types, primary type, and message.
import ( "math/big" "github.com/ChefBingbong/viem-go/utils/signature")
typedData := signature.TypedDataDefinition{ Domain: signature.TypedDataDomain{ Name: "Ether Mail", Version: "1", ChainId: big.NewInt(1), VerifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC", }, Types: map[string][]signature.TypedDataField{ "Person": { {Name: "name", Type: "string"}, {Name: "wallet", Type: "address"}, }, "Mail": { {Name: "from", Type: "Person"}, {Name: "to", Type: "Person"}, {Name: "contents", Type: "string"}, }, }, PrimaryType: "Mail", Message: map[string]any{ "from": map[string]any{ "name": "Cow", "wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826", }, "to": map[string]any{ "name": "Bob", "wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB", }, "contents": "Hello, Bob!", },}
valid, err := public.VerifyTypedData(ctx, publicClient, public.VerifyTypedDataParameters{ Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"), TypedData: typedData, Signature: "0x...",})Signature
- Type:
any(acceptsstring,[]byte, or*signature.Signature) - Required
The signature of the typed data.
valid, err := public.VerifyTypedData(ctx, publicClient, public.VerifyTypedDataParameters{ Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"), TypedData: typedData, Signature: "0x...",})BlockNumber
- Type:
*uint64 - Optional
Only used when verifying typed data that was signed by a Smart Contract Account. The block number to check if the contract was already deployed.
blockNum := uint64(42069)valid, err := public.VerifyTypedData(ctx, publicClient, public.VerifyTypedDataParameters{ Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"), TypedData: typedData, Signature: "0x...", BlockNumber: &blockNum,})BlockTag
- Type:
BlockTag - Default:
"latest" - Optional
Only used when verifying typed data that was signed by a Smart Contract Account. The block tag to check if the contract was already deployed.
valid, err := public.VerifyTypedData(ctx, publicClient, public.VerifyTypedDataParameters{ Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"), TypedData: typedData, Signature: "0x...", BlockTag: public.BlockTagSafe,})Factory
- Type:
*common.Address - Optional
The ERC-4337 Account Factory address for counterfactual verification. Used with FactoryData for undeployed smart accounts.
factoryAddr := common.HexToAddress("0x...")valid, err := public.VerifyTypedData(ctx, publicClient, public.VerifyTypedDataParameters{ Address: common.HexToAddress("0x..."), TypedData: typedData, Signature: "0x...", Factory: &factoryAddr, FactoryData: factoryCalldata,})FactoryData
- Type:
[]byte - Optional
The calldata to deploy the account via Factory. Used with Factory for undeployed smart accounts.
valid, err := public.VerifyTypedData(ctx, publicClient, public.VerifyTypedDataParameters{ Address: common.HexToAddress("0x..."), TypedData: typedData, Signature: "0x...", Factory: &factoryAddr, FactoryData: factoryCalldata,})ERC6492VerifierAddress
- Type:
*common.Address - Optional
The address of a deployed ERC-6492 signature verifier contract. If provided, uses this contract instead of deployless verification.
verifierAddr := common.HexToAddress("0x...")valid, err := public.VerifyTypedData(ctx, publicClient, public.VerifyTypedDataParameters{ Address: common.HexToAddress("0x..."), TypedData: typedData, Signature: "0x...", ERC6492VerifierAddress: &verifierAddr,})JSON-RPC Method
Underlying JSON-RPC method used by this action.
Uses eth_call to verify signatures onchain via ERC-1271 or ERC-6492.