Skip to content

signAuthorization

Signs an EIP-7702 Authorization. The signed Authorization can be used in Transaction APIs like sendTransaction and writeContract to inject the authorized Contract bytecode(s) into an Account at the time of execution.

Usage

A Contract can be authorized by supplying a contractAddress. By default, it will be signed over the Account's next available Nonce and the current Chain ID. You can also explicitly set the nonce and chainId.

example.ts
import { walletClient } from './client'
 
const authorization = await walletClient.signAuthorization({ 
  contractAddress: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', 
}) 
{
chainId: 1,
contractAddress: "0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2",
nonce: 1,
r: "0xf507fb8fa33ffd05a7f26c980bbb8271aa113affc8f192feba87abe26549bda1",
s: "0x1b2687608968ecb67230bbf7944199560fa2b3cffe9cc2b1c024e1c8f86a9e08",
yParity: 0,
}
const hash = await walletClient.sendTransaction({ authorizationList: [authorization], data: '0xdeadbeef', to: walletClient.account.address, })

Explicit Scoping

We can explicitly sign over a provided nonce and/or chainId by supplying them as parameters:

example.ts
import { walletClient } from './client'
 
const authorization = await walletClient.signAuthorization({
  contractAddress: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  chainId: 10, 
  nonce: 420, 
})
{
chainId: 10,
contractAddress: "0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2",
nonce: 420,
r: "0xf507fb8fa33ffd05a7f26c980bbb8271aa113affc8f192feba87abe26549bda1",
s: "0x1b2687608968ecb67230bbf7944199560fa2b3cffe9cc2b1c024e1c8f86a9e08",
yParity: 0,
}
const hash = await walletClient.sendTransaction({ authorizationList: [authorization], data: '0xdeadbeef', to: walletClient.account.address, })

Returns

SignedAuthorization

A signed Authorization object.

Parameters

account

  • Type: Account

Account to use to authorize injection of the Contract (authorization) onto the Account.

Accepts a Local Account (Private Key, etc).

import { privateKeyToAccount } from 'viem/accounts'
import { walletClient } from './client'
 
const authorization = await walletClient.signAuthorization({
  account: privateKeyToAccount('0x...'), 
  contractAddress: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2'
}) 

chainId (optional)

  • Type: Address
  • Default: client.chain.id or Network chain ID

The Chain ID to scope the Authorization to.

import { privateKeyToAccount } from 'viem/accounts'
import { walletClient } from './client'
 
const authorization = await walletClient.signAuthorization({
  account: privateKeyToAccount('0x...'),
  contractAddress: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  chainId: 1, 
}) 

contractAddress

  • Type: Address

The target Contract to inject onto the Account.

import { privateKeyToAccount } from 'viem/accounts'
import { walletClient } from './client'
 
const authorization = await walletClient.signAuthorization({
  account: privateKeyToAccount('0x...'),
  contractAddress: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2'
}) 

delegate (optional)

  • Type: true | Address | Account

Whether the EIP-7702 Transaction will be executed by another Account.

If not specified, it will be assumed that the EIP-7702 Transaction will be executed by the Account that signed the Authorization.

import { privateKeyToAccount } from 'viem/accounts'
import { walletClient } from './client'
 
const authorization = await walletClient.signAuthorization({
  account: privateKeyToAccount('0x...'),
  contractAddress: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  delegate: true, 
}) 

nonce (optional)

  • Type: Address
  • Default: Account's next available nonce.

The nonce to scope the Authorization to.

import { privateKeyToAccount } from 'viem/accounts'
import { walletClient } from './client'
 
const authorization = await walletClient.signAuthorization({
  account: privateKeyToAccount('0x...'),
  contractAddress: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  nonce: 69, 
})