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.
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
import { signAuthorization } from '@wagmi/core/experimental'
Usage
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',
})
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
import { type SignAuthorizationParameters } from '@wagmi/core/experimental'
account
Account
Account to use to authorize injection of the Contract (authorization) onto the Account.
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',
})
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.
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,
})
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.
import { parseEther } from 'viem'
import { signAuthorization } from '@wagmi/core/experimental'
import { config } from './config'
const authorization = await signAuthorization(config, {
account: privateKeyToAccount('0x...'),
contractAddress: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
})
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.
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,
})
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.
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,
})
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.
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,
})
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
import { type SignAuthorizationReturnType } from '@wagmi/core/experimental'
SignedAuthorization
A signed Authorization object.
Error
import { type SignAuthorizationErrorType } from '@wagmi/core/experimental'
TanStack Query
import {
type SignAuthorizationData,
type SignAuthorizationOptions,
type SignAuthorizationQueryFnData,
type SignAuthorizationQueryKey,
signAuthorizationQueryKey,
signAuthorizationQueryOptions,
} from '@wagmi/core/experimental/query'