verifyMessage
Action for verify that a message was signed by the provided address. It supports verifying messages that were signed by either a Smart Contract Account or Externally Owned Account.
Import
import { verifyMessage } from '@wagmi/core'
Usage
import { verifyMessage } from '@wagmi/core'
import { config } from './config'
await verifyMessage(config, {
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world',
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
Parameters
import { type VerifyMessageParameters } from '@wagmi/core'
address
Address
The Ethereum address that signed the original message.
import { verifyMessage } from '@wagmi/core'
import { config } from './config'
await verifyMessage(config, {
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world',
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
message
string | { raw: Hex | ByteArray }
The message to be verified.
By default, wagmi verifies the UTF-8 representation of the message.
import { getAccount, verifyMessage } from '@wagmi/core'
import { config } from './config'
await verifyMessage(config, {
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world',
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
TIP
By default, viem signs the UTF-8 representation of the message. To sign the data representation of the message, you can use the raw
attribute.
import { verifyMessage } from '@wagmi/core'
import { config } from './config'
await verifyMessage(config, {
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: { raw: '0x68656c6c6f20776f726c64' }
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})
signature
Hex | ByteArray
The signature that was generated by signing the message with the address's signer.
import { verifyMessage } from '@wagmi/core'
import { config } from './config'
await verifyMessage(config, {
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world',
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
chainId
config['chains'][number]['id'] | undefined
Only used when verifying a message that was signed by a Smart Contract Account. The ID of chain to check if the contract was already deployed.
import { verifyMessage } from '@wagmi/core'
import { mainnet } from '@wagmi/core/chains'
import { config } from './config'
await verifyMessage(config, {
chainId: mainnet.id,
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world',
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
blockNumber
bigint | undefined
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.
import { verifyMessage } from '@wagmi/core'
import { config } from './config'
await verifyMessage(config, {
blockNumber: 12345678n,
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world',
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
blockTag
'latest' | 'earliest' | 'pending' | 'safe' | 'finalized' | undefined
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.
import { verifyMessage } from '@wagmi/core'
import { config } from './config'
await verifyMessage(config, {
blockTag: 'latest',
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world',
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
Return Type
import { type VerifyMessageReturnType } from '@wagmi/core'
boolean
Wheather the signed message is valid for the given address.
Error
import { type VerifyMessageErrorType } from '@wagmi/core'
TanStack Query
import {
type verifyMessageData,
type verifyMessageVariables,
type verifyMessageMutate,
type verifyMessageMutateAsync,
verifyMessageMutationOptions,
} from '@wagmi/core/query'