recoverMessageAddress โ
Recovers the original signing address from a message & signature.
Useful for obtaining the address of a message that was signed with signMessage
.
Usage โ
ts
import { account, walletClient } from './config'
const signature = await walletClient.signMessage({
account,
message: 'hello world',
})
const address = await recoverMessageAddress({
message: 'hello world',
signature,
})
ts
import { createWalletClient, custom } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
export const walletClient = createWalletClient({
transport: custom(window.ethereum)
})
// JSON-RPC Account
export const [account] = await walletClient.getAddresses()
// Local Account
export const account = privateKeyToAccount('0x...')
Returns โ
The signing address.
Parameters โ
message โ
- Type:
string
The message that was signed.
ts
const address = await recoverMessageAddress({
message: 'hello world',
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c'
})
signature โ
- Type:
Hex | ByteArray
The signature of the message.
ts
const address = await recoverMessageAddress({
message: 'hello world',
signature: '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c'
})