Skip to main content
StartaleAccountClient exposes a small set of actions that cover almost every contract interaction you will write. This page shows how to encode calldata, send a single call, batch multiple calls atomically, and handle the most common errors.

Encode the calldata

Use encodeFunctionData from viem to turn a function call into ABI-encoded 0x bytes. The result becomes the data field of a Call object.
If you already use viem’s getContract or writeContract, you can reuse those ABI fragments directly here.

Send a single call

calls[].value is in wei. The smart account itself does not need to hold ETH unless you set a non-zero value and your paymaster does not cover it.

Batch multiple calls atomically

A single UserOperation can carry many calls. They are executed in order inside the same EVM transaction; if any one reverts, the whole UserOperation reverts and nothing is settled. This is built in to sendUserOperation: just append more entries to the calls array.
Each entry in calls is a { to, value, data } object; ordering is preserved and execution is atomic. A working multi-call example using this exact pattern lives in scs-aa-quickstart/src/startale-minato/demo_install_modules.ts.
Batching is the canonical way to fix the “approve then swap” two-transaction UX. The user signs once, the bundler ships one transaction, and gas accounting is single-shot.

Read state from the same publicClient

The smart account does not change how you read onchain data. Reuse the publicClient you passed to createSmartAccountClient:

Handle errors

sendUserOperation throws when the bundler rejects the UserOperation, when the paymaster declines to sponsor it, or when validation reverts. A small triage helper goes a long way:
The AA** codes come from the EntryPoint contract; their full meaning is documented in the ERC-4337 spec.

Send a transaction-style call

If your code expects the viem sendTransaction shape, the smart account client supports it too. It compiles the call into a single-call UserOperation under the hood:
The return value is still a UserOperation hash; pass it to waitForUserOperationReceipt.

Next steps

Sponsored paymaster

Send the same calls with gas paid by your paymaster.

ERC-20 paymaster

Quote a token, approve it once, and pay gas in tokens.

Parallel transactions

Run independent UserOperations on different nonce lanes.

Smart sessions

Drop the signature prompt for repeated, scoped calls.