viem-goviem-go

sendCalls

Sends a batch of calls (EIP-5792)

Read more about EIP-5792

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

Contract Calls

The Calls property also accepts contract calls with ABI encoding:

import (
"github.com/ChefBingbong/viem-go/abi"
"github.com/ChefBingbong/viem-go/actions/wallet"
)
parsedABI, _ := abi.Parse([]byte(`[{"type":"function","name":"approve",...}]`))
result, err := wallet.SendCalls(ctx, walletClient, wallet.SendCallsParameters{
Calls: []wallet.Call{
{
To: "0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2",
ABI: parsedABI,
FunctionName: "approve",
Args: []any{"0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC", big.NewInt(100)},
},
},
})

Returns

*SendCallsReturnType

An object containing:

  • ID - The identifier for the call batch
  • Capabilities - The wallet capabilities (optional)

Parameters

Configuration options accepted by this action.

Account

Control which account is used to send the batched calls.

  • Type: Account

  • Optional

The account to send from. If nil, uses the client's account.

Calls

Provide the list of calls that will be batched and sent.

  • Type: []wallet.Call

  • Required

An array of calls to be signed and broadcasted.

Each call can have:

  • To - Recipient address (optional)
  • Data - Calldata (optional, or use ABI encoding)
  • Value - Amount of ETH to send (optional)
  • ABI - Contract ABI for encoding (optional)
  • FunctionName - Function name (used with ABI)
  • Args - Function arguments (used with ABI)
  • DataSuffix - Data to append to the end of calldata (optional)
import "math/big"
result, err := wallet.SendCalls(ctx, walletClient, wallet.SendCallsParameters{
Calls: []wallet.Call{
{Data: "0xdeadbeef", To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8"},
{To: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", Value: big.NewInt(69420)},
},
})

ForceAtomic

  • Type: bool

  • Default: false

  • Optional

Force the calls to be executed atomically.

result, err := wallet.SendCalls(ctx, walletClient, wallet.SendCallsParameters{
Calls: []wallet.Call{...},
ForceAtomic: true,
})

ID

  • Type: string

  • Optional

An optional identifier for the call batch.

result, err := wallet.SendCalls(ctx, walletClient, wallet.SendCallsParameters{
Calls: []wallet.Call{...},
ID: "<my-batch-id>",
})

Version

  • Type: string

  • Default: "2.0.0"

  • Optional

The EIP-5792 version.

Capabilities

  • Type: map[string]any

  • Optional

Capability metadata for the calls (e.g. specifying a paymaster).

result, err := wallet.SendCalls(ctx, walletClient, wallet.SendCallsParameters{
Calls: []wallet.Call{...},
Capabilities: map[string]any{
"paymasterService": map[string]any{"url": "https://..."},
},
})

ExperimentalFallback

  • Type: bool

  • Default: false

  • Optional

When true, falls back to eth_sendTransaction if wallet_sendCalls is not supported.

:::warning When using ExperimentalFallback with a wallet that does not support EIP-5792, viem-go will return a custom bundle identifier (id). While this identifier works with viem-go's getCallsStatus action, it cannot be used with the native wallet_getCallsStatus RPC method. :::

ExperimentalFallbackDelay

  • Type: *int

  • Default: 32ms

  • Optional

The delay (in milliseconds) between fallback transactions when using ExperimentalFallback.

JSON-RPC Method