sendTransactionSync
Creates, signs, and sends a new transaction to the network synchronously
Creates, signs, and sends a new transaction to the network synchronously
eth_sendTransaction then waits for receipt via WaitForTransactionReceipt.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 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() }()
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)*formatters.TransactionReceipt
The transaction receipt after the transaction is included in a block.
All parameters from sendTransaction are supported, plus:
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",})*booltrueWhen true, throws an error if the transaction was detected as reverted.
throwOnRevert := truereceipt, err := wallet.SendTransactionSync(ctx, walletClient, wallet.SendTransactionSyncParameters{ ThrowOnReceiptRevert: &throwOnRevert, To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",})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",})The underlying JSON-RPC methods invoked by this action.
JSON-RPC Accounts: eth_sendTransaction (with wallet_sendTransaction fallback)
Local Accounts: eth_sendRawTransactionSync (EIP-7966)