|
| 1 | +# Batch Reference |
| 2 | + |
| 3 | +`createComposableBatch` is the entry point of the SDK. It returns a `ComposableBatchInstance` — a builder that collects composable calls in order and serialises them for execution. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## createComposableBatch |
| 8 | + |
| 9 | +```ts |
| 10 | +import { createComposableBatch } from 'composable-sdk'; |
| 11 | + |
| 12 | +const batch = createComposableBatch(publicClient, accountAddress); |
| 13 | +``` |
| 14 | + |
| 15 | +**Parameters** |
| 16 | + |
| 17 | +| Parameter | Type | Description | |
| 18 | +|---|---|---| |
| 19 | +| `publicClient` | `PublicClient` | Viem public client for the target chain | |
| 20 | +| `accountAddress` | `Address` | The smart account address that will execute the batch | |
| 21 | + |
| 22 | +**Returns** `ComposableBatchInstance` |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +## ComposableBatchInstance |
| 27 | + |
| 28 | +### Properties |
| 29 | + |
| 30 | +| Property | Type | Description | |
| 31 | +|---|---|---| |
| 32 | +| `publicClient` | `PublicClient` | The public client passed at construction | |
| 33 | +| `accountAddress` | `Address` | The smart account address | |
| 34 | +| `length` | `number` | Number of pending calls currently in the batch | |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +### erc20Token |
| 39 | + |
| 40 | +Returns an `ERC20TokenInstance` for the given token address, bound to the batch's account. |
| 41 | + |
| 42 | +```ts |
| 43 | +erc20Token(tokenAddress: Address): ERC20TokenInstance |
| 44 | +``` |
| 45 | + |
| 46 | +```ts |
| 47 | +const USDC = '0xUsdcAddress'; |
| 48 | +const usdc = batch.erc20Token(USDC); |
| 49 | +``` |
| 50 | + |
| 51 | +See [token.md](./token.md) for all methods on `ERC20TokenInstance`. |
| 52 | + |
| 53 | +--- |
| 54 | + |
| 55 | +### nativeToken |
| 56 | + |
| 57 | +Returns a `NativeTokenInstance` for native ETH, bound to the batch's account. |
| 58 | + |
| 59 | +```ts |
| 60 | +nativeToken(): NativeTokenInstance |
| 61 | +``` |
| 62 | + |
| 63 | +```ts |
| 64 | +const eth = batch.nativeToken(); |
| 65 | +``` |
| 66 | + |
| 67 | +See [token.md](./token.md) for all methods on `NativeTokenInstance`. |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +### contract |
| 72 | + |
| 73 | +Returns a fully typed `ContractInstance` for any contract with a given ABI. |
| 74 | + |
| 75 | +```ts |
| 76 | +contract<TAbi>(address: Address, abi: TAbi): ContractInstance<TAbi> |
| 77 | +``` |
| 78 | + |
| 79 | +```ts |
| 80 | +const myContract = batch.contract('0xContractAddress', MY_ABI); |
| 81 | +``` |
| 82 | + |
| 83 | +See [contract.md](./contract.md) for all methods on `ContractInstance`. |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +### storage |
| 88 | + |
| 89 | +Returns a `StorageInstance` scoped to the batch's account address. |
| 90 | + |
| 91 | +```ts |
| 92 | +storage(): StorageInstance |
| 93 | +``` |
| 94 | + |
| 95 | +```ts |
| 96 | +const storage = batch.storage(); |
| 97 | +``` |
| 98 | + |
| 99 | +See [storage.md](./storage.md) for all methods on `StorageInstance`. |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +### add |
| 104 | + |
| 105 | +Appends one or more calls to the batch. Order is preserved. Accepts a single call, a `Promise` of a call, or an array of either. |
| 106 | + |
| 107 | +```ts |
| 108 | +add( |
| 109 | + calls: ComposableCall | Promise<ComposableCall> | (ComposableCall | Promise<ComposableCall>)[] |
| 110 | +): void |
| 111 | +``` |
| 112 | + |
| 113 | +```ts |
| 114 | +const USDC = '0xUsdcAddress'; |
| 115 | +const amount = parseUnits('10', 6); |
| 116 | + |
| 117 | +const usdc = batch.erc20Token(USDC); |
| 118 | + |
| 119 | +// Single call |
| 120 | +batch.add( |
| 121 | + usdc.write({ functionName: 'transfer', args: ['0xRecipientAddress', amount] }), |
| 122 | +); |
| 123 | + |
| 124 | +// Multiple calls — order is preserved |
| 125 | +batch.add([ |
| 126 | + usdc.check({ |
| 127 | + functionName: 'balanceOf', |
| 128 | + args: ['0xRecipientAddress'], |
| 129 | + constraints: [{ gte: amount }], |
| 130 | + }), |
| 131 | + usdc.write({ functionName: 'transfer', args: ['0xRecipientAddress', amount] }), |
| 132 | +]); |
| 133 | + |
| 134 | +console.log(batch.length); // 3 |
| 135 | +``` |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +### clear |
| 140 | + |
| 141 | +Removes all pending calls from the batch. |
| 142 | + |
| 143 | +```ts |
| 144 | +clear(): void |
| 145 | +``` |
| 146 | + |
| 147 | +```ts |
| 148 | +batch.clear(); |
| 149 | +console.log(batch.length); // 0 |
| 150 | +``` |
| 151 | + |
| 152 | +--- |
| 153 | + |
| 154 | +### toCalls |
| 155 | + |
| 156 | +Resolves all pending calls and returns a `ComposableCall[]`. Use this when your execution client accepts a calls array directly (e.g. MEE). |
| 157 | + |
| 158 | +```ts |
| 159 | +toCalls(): Promise<ComposableCall[]> |
| 160 | +``` |
| 161 | + |
| 162 | +```ts |
| 163 | +const calls = await batch.toCalls(); |
| 164 | + |
| 165 | +const quote = await meeClient.getQuote({ |
| 166 | + instructions: [{ calls, chainId: baseSepolia.id, isComposable: true }], |
| 167 | + feeToken: { address: '0xUsdcAddress', chainId: baseSepolia.id }, |
| 168 | +}); |
| 169 | + |
| 170 | +const { hash } = await meeClient.executeQuote({ quote }); |
| 171 | +await meeClient.waitForSupertransactionReceipt({ hash }); |
| 172 | +``` |
| 173 | + |
| 174 | +--- |
| 175 | + |
| 176 | +### toCalldata |
| 177 | + |
| 178 | +Encodes the full batch as `executeComposable` calldata. Use this when you control the UserOp directly via a bundler (ZeroDev, Alchemy, Pimlico, or any ERC-4337 bundler). |
| 179 | + |
| 180 | +```ts |
| 181 | +toCalldata(): Promise<Hex> |
| 182 | +``` |
| 183 | + |
| 184 | +```ts |
| 185 | +const calldata = await batch.toCalldata(); |
| 186 | + |
| 187 | +const userOpHash = await kernelClient.sendUserOperation({ |
| 188 | + callData: calldata, |
| 189 | +}); |
| 190 | +``` |
0 commit comments