prepareTransactionRequest
Prepares a transaction request for signing
Prepares a transaction request for signing
Import the wallet actions package so you can call this action.
import "github.com/ChefBingbong/viem-go/actions/wallet"See how to construct a wallet client and call this action.
import ( "context" "log" "math/big"
"github.com/ChefBingbong/viem-go/actions/wallet" "github.com/ChefBingbong/viem-go/client" "github.com/ChefBingbong/viem-go/client/transport" "github.com/ChefBingbong/viem-go/chain/definitions")
ctx := context.Background()
walletClient, err := client.CreateWalletClient(client.WalletClientConfig{ Chain: definitions.Mainnet, Transport: transport.HTTP("https://eth.llamarpc.com"),})if err != nil { log.Fatal(err)}defer func() { _ = walletClient.Close() }()
prepared, err := wallet.PrepareTransactionRequest(ctx, walletClient, wallet.PrepareTransactionRequestParameters{ To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", Value: big.NewInt(1000000000000000000),})if err != nil { log.Fatal(err)}log.Printf("Prepared transaction: %+v", prepared)*PrepareTransactionRequestParameters
The fully-prepared transaction request with all required fields populated (nonce, chainId, gas, fees, type).
Configuration options accepted by this action.
Type: Account
Optional
The account to prepare the transaction for. If nil, uses the client's account.
import "github.com/ChefBingbong/viem-go/accounts"
account, err := accounts.PrivateKeyToAccount("0x...")if err != nil { log.Fatal(err)}
prepared, err := wallet.PrepareTransactionRequest(ctx, walletClient, wallet.PrepareTransactionRequestParameters{ Account: account, To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",})Type: []string
Default: ["blobVersionedHashes", "chainId", "fees", "gas", "nonce", "type"]
Optional
Parameters to prepare. For instance, if ["gas", "nonce"] is provided, then only the gas and nonce parameters will be prepared.
prepared, err := wallet.PrepareTransactionRequest(ctx, walletClient, wallet.PrepareTransactionRequestParameters{ Parameters: []string{"gas", "nonce"}, To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",})Type: string
Optional
The transaction recipient or contract address.
prepared, err := wallet.PrepareTransactionRequest(ctx, walletClient, wallet.PrepareTransactionRequestParameters{ To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",})Type: *big.Int
Optional
Value in wei sent with this transaction.
import "math/big"
prepared, err := wallet.PrepareTransactionRequest(ctx, walletClient, wallet.PrepareTransactionRequestParameters{ To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", Value: big.NewInt(1000000000000000000),})Type: string
Optional
A contract hashed method call with encoded args.
prepared, err := wallet.PrepareTransactionRequest(ctx, walletClient, wallet.PrepareTransactionRequestParameters{ Data: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",})Type: *big.Int
Optional
The gas limit of the transaction. If missing and gas is in Parameters, it will be estimated.
import "math/big"
prepared, err := wallet.PrepareTransactionRequest(ctx, walletClient, wallet.PrepareTransactionRequestParameters{ Gas: big.NewInt(21000), To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",})Type: *big.Int
Optional
The price (in wei) to pay per gas. Only applies to Legacy Transactions.
Type: *big.Int
Optional
Total fee per gas (in wei), inclusive of maxPriorityFeePerGas. Only applies to EIP-1559 Transactions. If missing and fees is in Parameters, it will be estimated.
Type: *big.Int
Optional
Max priority fee per gas (in wei). Only applies to EIP-1559 Transactions. If missing and fees is in Parameters, it will be estimated.
Type: *int
Optional
Unique number identifying this transaction. If missing and nonce is in Parameters, it will be fetched from the network.
nonce := 69prepared, err := wallet.PrepareTransactionRequest(ctx, walletClient, wallet.PrepareTransactionRequestParameters{ Nonce: &nonce, To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",})Type: formatters.TransactionType
Optional
The transaction type. Can be "legacy", "eip2930", "eip1559", "eip4844", or "eip7702". If missing and type is in Parameters, it will be inferred from the network or transaction fields.
Type: *int64
Optional
The chain ID. If missing and chainId is in Parameters, it will be fetched from the client's chain or via eth_chainId.
Type: *chain.Chain
Optional
The target chain. Used to infer chain ID and transaction type.
Type: []formatters.AccessListItem
Optional
The access list for EIP-2930 transactions.
Type: []transaction.SignedAuthorization
Optional
Signed EIP-7702 Authorization list.
Type: []string
Optional
Blobs for Blob Transactions (EIP-4844).
Type: []string
Optional
Blob versioned hashes for Blob Transactions (EIP-4844).
Type: *big.Int
Optional
Max fee per blob gas for Blob Transactions (EIP-4844).