viem-goviem-go

sendTransactionSync

Creates, signs, and sends a new transaction to the network synchronously

  • For JSON-RPC accounts, sends via eth_sendTransaction then waits for receipt via WaitForTransactionReceipt.
  • 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 := true
receipt, 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.Second
receipt, err := wallet.SendTransactionSync(ctx, walletClient, wallet.SendTransactionSyncParameters{
Timeout: &timeout,
To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
})

JSON-RPC Methods