Calls
A batch of calls for a wallet to send in order on one chain, and what the wallet answers (EIP-5792).
import { Effect } from "effect";import { Address } from "@ethect/core";import { type Calls, Wallet } from "@ethect/core/rpc";
const WETH = Address.makeUnsafe("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2");const FRIEND = Address.makeUnsafe("0x70997970C51812dc3A010C7d01b50e0d17dc79C8");
const send = Effect.gen(function* () { const batch: Calls.Calls = { version: "2.0.0", chainId: 1, atomicRequired: true, calls: [ // deposit() on the WETH contract, with one ether { to: WETH, value: 10n ** 18n, data: "0xd0e30db0" }, // then one ether to another account { to: FRIEND, value: 10n ** 18n }, ], }; const result = yield* Wallet.sendCalls(batch); // result: Calls.Result return result.id;});Schemas
Section titled “Schemas”| Schema | Type | Describes | Used by |
|---|---|---|---|
Calls.schema |
Calls.Calls |
a batch of calls | passed to Wallet.sendCalls |
Calls.callSchema |
Calls.Call |
one call of a batch | the calls of a batch |
Calls.resultSchema |
Calls.Result |
the id of the batch | returned by Wallet.sendCalls |
Batch fields
Section titled “Batch fields”Calls.Calls.
| Field | Type | Notes |
|---|---|---|
version |
"2.0.0" |
the only version the type accepts |
id |
string (optional) |
an id of the app’s choosing, unique per sender. The wallet makes one when left out |
from |
Address (optional) |
the sending account. The wallet lets the user choose when left out |
chainId |
number |
the chain every call is sent on |
atomicRequired |
boolean |
whether the wallet must run all the calls or none |
calls |
ReadonlyArray<Calls.Call> |
sent in this order |
capabilities |
WalletCapabilities.Request (optional) |
capabilities asked for the whole batch |
Call fields
Section titled “Call fields”Calls.Call.
| Field | Type | Notes |
|---|---|---|
to |
Address (optional) |
the account or contract to call |
data |
Hex (optional) |
the calldata |
value |
bigint (optional) |
wei to send with the call |
capabilities |
WalletCapabilities.Request (optional) |
capabilities asked for this call only |
Result fields
Section titled “Result fields”Calls.Result.
| Field | Type | Notes |
|---|---|---|
id |
string |
the id to ask for the batch’s status with |
capabilities |
WalletCapabilities (optional) |
what the wallet attached to its answer |
Behavior
Section titled “Behavior”- A result can be the id alone.
Calls.resultSchemareads a bare string as{ id }. atomicRequiredis a demand. Withtrue, the wallet must run all the calls or none, with nothing in between. A wallet that cannot rejects the batch.- A call is not a transaction request. It has
to,dataandvalueonly: no gas, no nonce, no fees. The wallet decides how the calls reach the chain. - The id is a
string. It is not a transaction hash. Pass it toWallet.getCallsStatusto follow the batch. - Quantities are encoded.
chainId: 1is sent as"0x1"andvalueas a hex quantity. See values on the wire.