signTransaction
Signs a transaction with the Account's private key
- For local accounts (implementing TransactionSignableAccount), signs locally without an RPC call.
- For JSON-RPC accounts, delegates to the
eth_signTransactionRPC method.
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" "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() }()
signed, err := wallet.SignTransaction(ctx, walletClient, wallet.SignTransactionParameters{ To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", Value: big.NewInt(1000000000000000000),})if err != nil { log.Fatal(err)}log.Printf("Signed transaction: %s", signed)Returns
string
The signed transaction as a hex string.
Parameters
Configuration options accepted by this action.
Account
-
Type:
Account -
Optional
The account to sign with. If nil, uses the client's account.
Chain
-
Type:
*chain.Chain -
Optional
The target chain. If there is a mismatch between the wallet's current chain & the target chain, an error will be thrown.
SkipChainAssertion
-
Type:
bool -
Optional
When true, skips the chain ID mismatch assertion.
Transaction Fields
All transaction fields from sendTransaction are supported:
To- The transaction recipientValue- Value in weiData- Contract call dataGas- Gas limitGasPrice- Gas price (Legacy transactions)MaxFeePerGas- Max fee per gas (EIP-1559)MaxPriorityFeePerGas- Max priority fee per gas (EIP-1559)Nonce- Transaction nonceType- Transaction typeAccessList- Access list (EIP-2930)AuthorizationList- Authorization list (EIP-7702)Blobs- Blobs (EIP-4844)BlobVersionedHashes- Blob versioned hashes (EIP-4844)MaxFeePerBlobGas- Max fee per blob gas (EIP-4844)
JSON-RPC Methods
- JSON-RPC Accounts:
eth_signTransaction - Local Accounts: Signs locally. No JSON-RPC request.