viem-goviem-go

signAuthorization

Signs an EIP-7702 authorization

signAuthorization

Signs an EIP-7702 Authorization object.

This action first prepares the authorization (filling in chainId and nonce if needed), then signs it using the account's signAuthorization method.

:::warning This action requires a local account that implements AuthorizationSignableAccount. JSON-RPC accounts are not supported for this action. :::

Import

Import the wallet actions package so you can call this action.

import "github.com/ChefBingbong/viem-go/actions/wallet"

Usage

See how to construct a wallet client and call this action.

import (
"context"
"log"
"github.com/ChefBingbong/viem-go/actions/wallet"
"github.com/ChefBingbong/viem-go/accounts"
"github.com/ChefBingbong/viem-go/client"
"github.com/ChefBingbong/viem-go/client/transport"
"github.com/ChefBingbong/viem-go/chain/definitions"
)
ctx := context.Background()
account, err := accounts.PrivateKeyToAccount("0x...")
if err != nil {
log.Fatal(err)
}
walletClient, err := client.CreateWalletClient(client.WalletClientConfig{
Account: account,
Chain: definitions.Mainnet,
Transport: transport.HTTP("https://eth.llamarpc.com"),
})
if err != nil {
log.Fatal(err)
}
defer func() { _ = walletClient.Close() }()
signed, err := wallet.SignAuthorization(ctx, walletClient, wallet.SignAuthorizationParameters{
ContractAddress: "0xA0Cf798816D4b9b9866b5330EEa46a18382f251e",
})
if err != nil {
log.Fatal(err)
}
log.Printf("Signed authorization: %+v", signed)

Returns

*types.SignedAuthorization

The signed EIP-7702 authorization.

Parameters

All parameters from prepareAuthorization are supported:

Account

Control which account is used to sign the authorization.

  • Type: Account

  • Optional

The account to sign with. If nil, uses the client's account. Must be a local account.

ContractAddress

Specify the contract address that the authorization applies to.

  • Type: string

-- Required

The contract address being authorized.

signed, err := wallet.SignAuthorization(ctx, walletClient, wallet.SignAuthorizationParameters{
ContractAddress: "0xA0Cf798816D4b9b9866b5330EEa46a18382f251e",
})

Address

Optionally provide an alias for the contract address.

  • Type: string

  • Optional

An alias for ContractAddress (for compatibility).

ChainID

Override the chain ID used for the authorization.

  • Type: *int

  • Optional

The chain ID for the authorization. If nil, it will be fetched from the client's chain or via eth_chainId.

Nonce

Override the nonce used for the authorization.

  • Type: *int

  • Optional

The nonce for the authorization. If nil, it will be fetched via eth_getTransactionCount with "pending" block tag.

Executor

Configure who will execute the EIP-7702 transaction.

  • Type: any

  • Optional

Specifies who will execute the EIP-7702 transaction:

  • nil: assumes another account will execute
  • "self": the signing account will execute (nonce += 1)
  • Account: a specific account will execute (nonce += 1 if same as signing account)

JSON-RPC Methods

  • Local Accounts: Signs locally. No JSON-RPC request.
  • JSON-RPC Accounts: Not supported.