Skip to content

signAuthorization

Action that 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.

Read more.

WARNING

This is an experimental action that is not supported in most wallets. It is recommended to have a fallback mechanism if using this in production.

Import

ts
import { signAuthorization } from '@wagmi/core/experimental'

Usage

ts
import { parseEther } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { signAuthorization } from '@wagmi/core/experimental'
import { config } from './config'

const authorization = await signAuthorization(config, {
  account: privateKeyToAccount('0x...'),
  contractAddress: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

Parameters

ts
import { type SignAuthorizationParameters } from '@wagmi/core/experimental'

account

Account

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

ts
import { parseEther } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { signAuthorization } from '@wagmi/core/experimental'
import { config } from './config'

const authorization = await signAuthorization(config, {
  account: privateKeyToAccount('0x...'), 
  contractAddress: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

chainId

config['chains'][number]['id'] | undefined

The Chain ID to scope the Authorization to.

ts
import { parseEther } from 'viem'
import { signAuthorization } from '@wagmi/core/experimental'
import { config } from './config'

const authorization = await signAuthorization(config, {
    account: privateKeyToAccount('0x...'),
  contractAddress: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  chainId: 1, 
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

contractAddress

Address

The target Contract to inject onto the Account.

ts
import { parseEther } from 'viem'
import { signAuthorization } from '@wagmi/core/experimental'
import { config } from './config'

const authorization = await signAuthorization(config, {
    account: privateKeyToAccount('0x...'),
  contractAddress: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', 
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

delegate

true | Address | Account | undefined

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.

ts
import { parseEther } from 'viem'
import { signAuthorization } from '@wagmi/core/experimental'
import { config } from './config'

const authorization = await signAuthorization(config, {
    account: privateKeyToAccount('0x...'),
  contractAddress: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  delegate: true, 
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

nonce

Address | undefined

The nonce to scope the Authorization to.

ts
import { parseEther } from 'viem'
import { signAuthorization } from '@wagmi/core/experimental'
import { config } from './config'

const authorization = await signAuthorization(config, {
  account: privateKeyToAccount('0x...'),
  contractAddress: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  nonce: 69, 
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

connector

Connector | undefined

Connector to use to sign the Authorization.

ts
import { parseEther } from 'viem'
import { getConnections } from '@wagmi/core'
import { signAuthorization } from '@wagmi/core/experimental'
import { config } from './config'

const connections = getConnections(config)
const authorization = await signAuthorization(config, {
  account: privateKeyToAccount('0x...'),
  contractAddress: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
  connector: connections[0]?.connector, 
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

Return Type

ts
import { type SignAuthorizationReturnType } from '@wagmi/core/experimental'

SignedAuthorization

A signed Authorization object.

Error

ts
import { type SignAuthorizationErrorType } from '@wagmi/core/experimental'

TanStack Query

ts
import {
  type SignAuthorizationData,
  type SignAuthorizationOptions,
  type SignAuthorizationQueryFnData,
  type SignAuthorizationQueryKey,
  signAuthorizationQueryKey,
  signAuthorizationQueryOptions,
} from '@wagmi/core/experimental/query'

Viem

Released under the MIT License.