# Calls

A batch of calls for a wallet to send in order on one chain, and what the wallet answers
(EIP-5792).

```ts
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

| Schema | Type | Describes | Used by |
| --- | --- | --- | --- |
| `Calls.schema` | `Calls.Calls` | a batch of calls | passed to [`Wallet.sendCalls`](https://ethect.dev/rpc/wallet/send-calls/) |
| `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`](https://ethect.dev/rpc/wallet/send-calls/) |

## 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`](https://ethect.dev/reference/primitives/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`](https://ethect.dev/rpc/types/wallet-capabilities/) (optional) | capabilities asked for the whole batch |

## Call fields

`Calls.Call`.

| Field | Type | Notes |
| --- | --- | --- |
| `to` | [`Address`](https://ethect.dev/reference/primitives/address/) (optional) | the account or contract to call |
| `data` | [`Hex`](https://ethect.dev/reference/primitives/hex/) (optional) | the calldata |
| `value` | `bigint` (optional) | wei to send with the call |
| `capabilities` | [`WalletCapabilities.Request`](https://ethect.dev/rpc/types/wallet-capabilities/) (optional) | capabilities asked for this call only |

## Result fields

`Calls.Result`.

| Field | Type | Notes |
| --- | --- | --- |
| `id` | `string` | the id to ask for the batch's status with |
| `capabilities` | [`WalletCapabilities`](https://ethect.dev/rpc/types/wallet-capabilities/) (optional) | what the wallet attached to its answer |

## Behavior

- **A result can be the id alone.** `Calls.resultSchema` reads a bare string as `{ id }`.
- **`atomicRequired` is a demand.** With `true`, 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`, `data` and `value` only: 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 to
  [`Wallet.getCallsStatus`](https://ethect.dev/rpc/wallet/calls-status/#getcallsstatus) to follow the batch.
- **Quantities are encoded.** `chainId: 1` is sent as `"0x1"` and `value` as a hex quantity.
  See [values on the wire](https://ethect.dev/rpc/guides/values/).
