6.9 KiB
title, description
| title | description |
|---|---|
| useVerifyMessage | Hook for verify that a message was signed by the provided address. |
useVerifyMessage
Hook 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 { useVerifyMessage } from 'wagmi'
Usage
::: code-group
import { useVerifyMessage } from 'wagmi'
function App() {
const result = useVerifyMessage({
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world',
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})
}
<<< @/snippets/react/config.ts[config.ts] :::
Parameters
import { type UseVerifyMessageParameters } from 'wagmi'
address
Address | undefined
The Ethereum address that signed the original message.
::: code-group
import { useVerifyMessage } from 'wagmi'
function App() {
const result = useVerifyMessage({
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', // [!code focus]
message: 'hello world',
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})
}
<<< @/snippets/react/config.ts[config.ts] :::
message
string | { raw: Hex | ByteArray } | undefined
The message to be verified.
By default, wagmi verifies the UTF-8 representation of the message.
::: code-group
import { useVerifyMessage } from 'wagmi'
function App() {
const result = useVerifyMessage({
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world', // [!code focus]
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})
}
<<< @/snippets/react/config.ts[config.ts] :::
::: 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 { useVerifyMessage } from 'wagmi'
function App() {
const result = useVerifyMessage({
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: { raw: '0x68656c6c6f20776f726c64' } // [!code focus]
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})
}
:::
signature
Hex | ByteArray | undefined
The signature that was generated by signing the message with the address's signer.
::: code-group
import { useVerifyMessage } from 'wagmi'
function App() {
const result = useVerifyMessage({
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world',
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c', // [!code focus]
})
}
<<< @/snippets/react/config.ts[config.ts] :::
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.
::: code-group
import { useVerifyMessage } from 'wagmi'
import { mainnet } from 'wagmi/chains'
function App() {
const result = useVerifyMessage({
chainId: mainnet.id, // [!code focus]
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world',
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})
}
<<< @/snippets/react/config.ts[config.ts] :::
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.
::: code-group
import { useVerifyMessage } from 'wagmi'
import { mainnet } from 'wagmi/chains'
function App() {
const result = useVerifyMessage({
blockNumber: 12345678n, // [!code focus]
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world',
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})
}
<<< @/snippets/react/config.ts[config.ts] :::
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.
::: code-group
import { useVerifyMessage } from 'wagmi'
import { mainnet } from 'wagmi/chains'
function App() {
const result = useVerifyMessage({
blockTag: 'pending', // [!code focus]
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world',
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})
}
<<< @/snippets/react/config.ts[config.ts] :::
config
Config | undefined
Config to use instead of retrieving from the nearest WagmiProvider.
::: code-group
import { useVerifyMessage } from 'wagmi'
import { config } from './config' // [!code focus]
function App() {
const result = useVerifyMessage({
config, // [!code focus]
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world',
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})
}
<<< @/snippets/react/config.ts[config.ts] :::
scopeKey
string | undefined
Scopes the cache to a given context. Hooks that have identical context will share the same cache.
::: code-group
import { useVerifyMessage } from 'wagmi'
import { config } from './config'
function App() {
const result = useVerifyMessage({
scopeKey: 'foo' // [!code focus]
address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
message: 'hello world',
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})
}
<<< @/snippets/react/config.ts[config.ts] :::
Return Type
import { type UseVerifyMessageReturnType } from 'wagmi'