viem-goviem-go

sendCallsSync

Sends a batch of calls synchronously (EIP-5792)

Import

Import the wallet actions package so you can call this action synchronously.

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() }()
status, err := wallet.SendCallsSync(ctx, walletClient, wallet.SendCallsSyncParameters{
SendCallsParameters: wallet.SendCallsParameters{
Calls: []wallet.Call{
{Data: "0xdeadbeef", To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8"},
{To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", Value: big.NewInt(69420)},
},
},
})
if err != nil {
log.Fatal(err)
}
log.Printf("Call status: %+v", status)

Returns

*GetCallsStatusReturnType

The call status with receipts after the calls are included in a block.

Parameters

All parameters from sendCalls are supported, plus:

PollingInterval

Control how frequently the call status is polled.

  • Type: time.Duration

  • Default: client.PollingInterval()

  • Optional

The polling interval to poll for the calls status.

import "time"
status, err := wallet.SendCallsSync(ctx, walletClient, wallet.SendCallsSyncParameters{
SendCallsParameters: wallet.SendCallsParameters{Calls: []wallet.Call{...}},
PollingInterval: 1 * time.Second,
})

Status

Provide a custom function to decide when polling should stop.

  • Type: func(*GetCallsStatusReturnType) bool
  • Default: statusCode == 200 || statusCode >= 300

A function that determines whether to stop polling.

status, err := wallet.SendCallsSync(ctx, walletClient, wallet.SendCallsSyncParameters{
SendCallsParameters: wallet.SendCallsParameters{Calls: []wallet.Call{...}},
Status: func(result *wallet.GetCallsStatusReturnType) bool {
return result.StatusCode == 200 // Only stop on success
},
})

ThrowOnFailure

  • Type: bool

  • Default: false

  • Optional

When true, returns an error if the call bundle fails.

status, err := wallet.SendCallsSync(ctx, walletClient, wallet.SendCallsSyncParameters{
SendCallsParameters: wallet.SendCallsParameters{Calls: []wallet.Call{...}},
ThrowOnFailure: true,
})

Timeout

  • Type: *time.Duration

  • Default: max(chain.blockTime * 3, 5000ms)

  • Optional

The timeout (in milliseconds) to wait for calls to be included in a block.

import "time"
timeout := 20 * time.Second
status, err := wallet.SendCallsSync(ctx, walletClient, wallet.SendCallsSyncParameters{
SendCallsParameters: wallet.SendCallsParameters{Calls: []wallet.Call{...}},
Timeout: &timeout,
})

JSON-RPC Methods