Skip to content

verifySiweMessage

Verifies EIP-4361 formatted message was signed.

See createSiweMessage for info on how to create a EIP-4361 formatted message.

Usage

example.ts
import { account, walletClient, publicClient } from './client'
import { message } from './message'
 
const signature = await walletClient.signMessage({ account, message })

const valid = await publicClient.verifySiweMessage({
  message,
  signature,
})
true

Returns

boolean

Whether the signed message is valid for the given address.

Parameters

message

  • Type: string

EIP-4361 formatted message to be verified.

const valid = await publicClient.verifySiweMessage({
  message: createSiweMessage({ 
    address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', 
    chainId: 1, 
    domain: 'example.com', 
    nonce: generateSiweNonce(), 
    uri: 'https://example.com/path', 
    version: '1', 
  }), 
  signature:
    '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})

signature

  • Type: Hex

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

const valid = await publicClient.verifySiweMessage({
  message,
  signature:
    '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c', 
})

address (optional)

  • Type: Address

Ethereum address to check against.

const valid = await publicClient.verifySiweMessage({
  address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', 
  message,
  signature:
    '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})

blockNumber (optional)

  • Type: number

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.

const valid = await publicClient.verifySiweMessage({
  blockNumber: 42069n, 
  message,
  signature:
    '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})

blockTag (optional)

  • Type: 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'
  • Default: 'latest'

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.

const valid = await publicClient.verifySiweMessage({
  blockTag: 'safe', 
  message,
  signature:
    '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})

domain (optional)

  • Type: string

RFC 3986 authority to check against.

const valid = await publicClient.verifySiweMessage({
  domain: 'viem.sh', 
  message,
  signature:
    '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})

nonce (optional)

  • Type: string

Random string to check against.

const valid = await publicClient.verifySiweMessage({
  nonce: generateSiweNonce(), 
  message,
  signature:
    '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})

scheme (optional)

  • Type: string

RFC 3986 URI scheme to check against.

const valid = await publicClient.verifySiweMessage({
  scheme: 'https', 
  message,
  signature:
    '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})

time (optional)

  • Type: Date
  • Default: new Date()

Current time to check optional expirationTime and notBefore message fields.

const valid = await publicClient.verifySiweMessage({
  time: new Date(), 
  message,
  signature:
    '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})