Skip to content

hashAuthorization

Calculates an Authorization hash in EIP-7702 format: keccak256('0x05' || rlp([chain_id, address, nonce])).

Import

import { hashAuthorization } from 'viem/experimental'

Usage

import { hashAuthorization } from 'viem/experimental'
 
hashAuthorization({
  address: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
  chainId: 1,
  nonce: 0,
})
// 0xd428ed36e6098e46b40a4cb99b83b930b0ca1f054f40b5996589eda33c295663
## Errors were thrown in the sample, but not included in an error tag These errors were not marked as being expected: 2353. Expected: // @errors: 2353 Compiler Errors: index.ts [2353] 77 - Object literal may only specify known properties, and 'address' does not exist in type 'HashAuthorizationParameters<"hex">'.

Returns

Hash

The hashed Authorization.

Parameters

address

  • Type: Address

Address of the contract to set as code for the Authority.

import { hashAuthorization } from 'viem/experimental'
 
hashAuthorization({
  address: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 
  chainId: 1,
  nonce: 0,
}) 
## Errors were thrown in the sample, but not included in an error tag These errors were not marked as being expected: 2353. Expected: // @errors: 2353 Compiler Errors: index.ts [2353] 77 - Object literal may only specify known properties, and 'address' does not exist in type 'HashAuthorizationParameters<"hex">'.

chainId

  • Type: number

Chain ID to authorize.

import { hashAuthorization } from 'viem/experimental'
 
hashAuthorization({
  address: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
  chainId: 1, 
  nonce: 0,
}) 
## Errors were thrown in the sample, but not included in an error tag These errors were not marked as being expected: 2353. Expected: // @errors: 2353 Compiler Errors: index.ts [2353] 77 - Object literal may only specify known properties, and 'address' does not exist in type 'HashAuthorizationParameters<"hex">'.

nonce

  • Type: number

Nonce of the Authority to authorize.

import { hashAuthorization } from 'viem/experimental'
 
hashAuthorization({
  address: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
  chainId: 1,
  nonce: 0, 
}) 
## Errors were thrown in the sample, but not included in an error tag These errors were not marked as being expected: 2353. Expected: // @errors: 2353 Compiler Errors: index.ts [2353] 77 - Object literal may only specify known properties, and 'address' does not exist in type 'HashAuthorizationParameters<"hex">'.

to

  • Type: "hex" | "bytes"
  • Default: "hex"

Output format.

import { hashAuthorization } from 'viem/experimental'
 
hashAuthorization({
  address: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
  chainId: 1,
  nonce: 0, 
  to: 'bytes', 
}) 
## Errors were thrown in the sample, but not included in an error tag These errors were not marked as being expected: 2353. Expected: // @errors: 2353 Compiler Errors: index.ts [2353] 77 - Object literal may only specify known properties, and 'address' does not exist in type 'HashAuthorizationParameters<"bytes">'.