sendRawTransactionSync
Sends a signed transaction to the network synchronously
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"
"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.SendRawTransactionSync(ctx, walletClient, wallet.SendRawTransactionSyncParameters{ SerializedTransaction: "0x02f850018203118080825208808080c080a04012522854168b27e5dc3d5839bab5e6b39e1a0ffd343901ce1622e3d64b48f1a04e00902ae0502c4728cbf12156290df99c3ed7de85b1dbfe20b5c36931733a33",})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
Configuration options accepted by this action.
SerializedTransaction
-
Type:
string -
Required
The signed serialized transaction hex string.
receipt, err := wallet.SendRawTransactionSync(ctx, walletClient, wallet.SendRawTransactionSyncParameters{ SerializedTransaction: "0x02f850018203118080825208808080c080a04012522854168b27e5dc3d5839bab5e6b39e1a0ffd343901ce1622e3d64b48f1a04e00902ae0502c4728cbf12156290df99c3ed7de85b1dbfe20b5c36931733a33",})ThrowOnReceiptRevert
-
Type:
*bool -
Default:
true -
Optional
When true, throws an error if the transaction was detected as reverted.
throwOnRevert := truereceipt, err := wallet.SendRawTransactionSync(ctx, walletClient, wallet.SendRawTransactionSyncParameters{ SerializedTransaction: "0x02f850...", ThrowOnReceiptRevert: &throwOnRevert,})Timeout
-
Type:
*int64 -
Optional
The timeout (in milliseconds) for the transaction.
timeout := int64(20000) // 20 seconds in millisecondsreceipt, err := wallet.SendRawTransactionSync(ctx, walletClient, wallet.SendRawTransactionSyncParameters{ SerializedTransaction: "0x02f850...", Timeout: &timeout,})JSON-RPC Method
eth_sendRawTransactionSync(EIP-7966)