viem-goviem-go

createAccessList

Creates an access list for a transaction

Creates an access list for a transaction.

Import

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

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

Usage

An example showing how to construct a public client and generate an access list for a transaction.

import (
"context"
"log"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ChefBingbong/viem-go/actions/public"
"github.com/ChefBingbong/viem-go/client"
"github.com/ChefBingbong/viem-go/client/transport"
"github.com/ChefBingbong/viem-go/chain/definitions"
)
ctx := context.Background()
publicClient, err := client.CreatePublicClient(client.PublicClientConfig{
Chain: definitions.Mainnet,
Transport: transport.HTTP("https://eth.llamarpc.com"),
})
if err != nil {
log.Fatal(err)
}
defer func() { _ = publicClient.Close() }()
accessList, err := public.CreateAccessList(ctx, publicClient, public.CreateAccessListParameters{
To: common.HexToAddress("0x..."),
Data: []byte{0x12, 0x34, 0x56},
})

Returns

*CreateAccessListReturnType

An access list object containing:

  • AccessList types.AccessList - The access list
  • GasUsed *big.Int - The gas used

Parameters

Configuration options accepted by this action.

To

  • Type: *common.Address
  • Optional

The transaction recipient.

import (
"github.com/ethereum/go-ethereum/common"
"github.com/ChefBingbong/viem-go/actions/public"
)
to := common.HexToAddress("0x70997970C51812dc3A010C7d01b50e0d17dc79C8")
accessList, err := public.CreateAccessList(ctx, publicClient, public.CreateAccessListParameters{
To: &to,
})

Data

  • Type: []byte
  • Optional

Transaction data.

import "github.com/ChefBingbong/viem-go/actions/public"
accessList, err := public.CreateAccessList(ctx, publicClient, public.CreateAccessListParameters{
Data: []byte{0xc0, 0x2a, 0xaa, 0x39},
})

Account

  • Type: *common.Address
  • Optional

The account to execute the transaction from.

import (
"github.com/ethereum/go-ethereum/common"
"github.com/ChefBingbong/viem-go/actions/public"
)
account := common.HexToAddress("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266")
accessList, err := public.CreateAccessList(ctx, publicClient, public.CreateAccessListParameters{
Account: &account,
})

BlockNumber

  • Type: *uint64
  • Optional

The block number to create the access list at.

import "github.com/ChefBingbong/viem-go/actions/public"
blockNum := uint64(12345)
accessList, err := public.CreateAccessList(ctx, publicClient, public.CreateAccessListParameters{
BlockNumber: &blockNum,
})

BlockTag

  • Type: BlockTag
  • Optional

The block tag to create the access list at.

import "github.com/ChefBingbong/viem-go/actions/public"
accessList, err := public.CreateAccessList(ctx, publicClient, public.CreateAccessListParameters{
BlockTag: public.BlockTagSafe,
})

JSON-RPC Method

Underlying JSON-RPC method used by this action.

eth_createAccessList