sendTransactionSync
Creates, signs, and sends a new transaction to the network synchronously
- For JSON-RPC accounts, sends via
eth_sendTransactionthen waits for receipt viaWaitForTransactionReceipt. - For local accounts, prepares, signs locally, and sends via
sendRawTransactionSync(EIP-7966).
:::warning
This Action is only recommended to be used on chains with low block times and fast finality (most chains apart from mainnet).
:::
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() }()
receipt, err := wallet.SendTransactionSync(ctx, walletClient, wallet.SendTransactionSyncParameters{ To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", Value: big.NewInt(1000000000000000000),})if err != nil { log.Fatal(err)}log.Printf("Transaction receipt: %+v", receipt)Returns
*formatters.TransactionReceipt
The transaction receipt after the transaction is included in a block.
Parameters
All parameters from sendTransaction are supported, plus:
PollingInterval
-
Type:
time.Duration -
Default:
client.PollingInterval() -
Optional
The polling interval to poll for the transaction receipt.
import "time"
receipt, err := wallet.SendTransactionSync(ctx, walletClient, wallet.SendTransactionSyncParameters{ PollingInterval: 1 * time.Second, To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",})ThrowOnReceiptRevert
- Type:
*bool - Default:
true
When true, throws an error if the transaction was detected as reverted.
throwOnRevert := truereceipt, err := wallet.SendTransactionSync(ctx, walletClient, wallet.SendTransactionSyncParameters{ ThrowOnReceiptRevert: &throwOnRevert, To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",})Timeout
-
Type:
*time.Duration -
Default:
max(chain.blockTime * 3, 5000ms) -
Optional
The timeout to wait for a response.
import "time"
timeout := 20 * time.Secondreceipt, err := wallet.SendTransactionSync(ctx, walletClient, wallet.SendTransactionSyncParameters{ Timeout: &timeout, To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",})JSON-RPC Methods
-
The underlying JSON-RPC methods invoked by this action.
-
JSON-RPC Accounts:
eth_sendTransaction(withwallet_sendTransactionfallback) -
Local Accounts:
eth_sendRawTransactionSync(EIP-7966)