viem-goviem-go

verifyMessage

Verifies if a signed message was generated by the provided address

Verify that a message 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 that a message and signature were produced by a given address.

import (
"context"
"log"
"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() }()
valid, err := public.VerifyMessage(ctx, publicClient, public.VerifyMessageParameters{
Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"),
Message: signature.NewSignableMessage("hello world"),
Signature: "0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c",
})
if err != nil {
log.Fatal(err)
}
log.Printf("Valid: %v", valid)

Returns

bool

Whether the signed message 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 message.

import (
"github.com/ethereum/go-ethereum/common"
"github.com/ChefBingbong/viem-go/actions/public"
"github.com/ChefBingbong/viem-go/utils/signature"
)
valid, err := public.VerifyMessage(ctx, publicClient, public.VerifyMessageParameters{
Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"),
Message: signature.NewSignableMessage("hello world"),
Signature: "0x...",
})

Message

  • Type: signature.SignableMessage
  • Required

The message that was signed. Use signature.NewSignableMessage, signature.NewSignableMessageRaw, or signature.NewSignableMessageRawHex to construct this value.

By default, verifies the UTF-8 representation of the message.

import "github.com/ChefBingbong/viem-go/utils/signature"
valid, err := public.VerifyMessage(ctx, publicClient, public.VerifyMessageParameters{
Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"),
Message: signature.NewSignableMessage("hello world"),
Signature: "0x...",
})

To verify the data representation of the message, use signature.NewSignableMessageRaw or signature.NewSignableMessageRawHex.

import "github.com/ChefBingbong/viem-go/utils/signature"
valid, err := public.VerifyMessage(ctx, publicClient, public.VerifyMessageParameters{
Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"),
Message: signature.NewSignableMessageRawHex("0x68656c6c6f20776f726c64"),
Signature: "0x...",
})

Signature

  • Type: any (accepts string, []byte, or *signature.Signature)
  • Required

The signature that was generated by signing the message with the address's signer.

valid, err := public.VerifyMessage(ctx, publicClient, public.VerifyMessageParameters{
Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"),
Message: signature.NewSignableMessage("hello world"),
Signature: "0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c",
})

BlockNumber

  • Type: *uint64
  • Optional

Only used when verifying a message 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.VerifyMessage(ctx, publicClient, public.VerifyMessageParameters{
Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"),
Message: signature.NewSignableMessage("hello world"),
Signature: "0x...",
BlockNumber: &blockNum,
})

BlockTag

  • Type: BlockTag
  • Default: "latest"
  • Optional

Only used when verifying a message that was signed by a Smart Contract Account. The block tag to check if the contract was already deployed.

valid, err := public.VerifyMessage(ctx, publicClient, public.VerifyMessageParameters{
Address: common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"),
Message: signature.NewSignableMessage("hello world"),
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.VerifyMessage(ctx, publicClient, public.VerifyMessageParameters{
Address: common.HexToAddress("0x..."),
Message: signature.NewSignableMessage("hello"),
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.VerifyMessage(ctx, publicClient, public.VerifyMessageParameters{
Address: common.HexToAddress("0x..."),
Message: signature.NewSignableMessage("hello"),
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.VerifyMessage(ctx, publicClient, public.VerifyMessageParameters{
Address: common.HexToAddress("0x..."),
Message: signature.NewSignableMessage("hello"),
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.