relayGaslessBatch
Relay several gasless actions as one request: one relay-instant submit, one atomic transaction the relayer broadcasts and pays gas for. Describe each action by name — the SDK encodes it, resolves its contract, sequences the nonces, prices the batch and asks for the signatures.
import { relayGaslessBatch, waitForGaslessRequest } from "@symmio/trading-core";
import { parseUnits } from "viem";
// Approve the gateway's fee budget and use it in the same request.
const receipt = await relayGaslessBatch(config, {
account: subAccount,
calls: [
{
functionName: "approveOperationalFeeWithMultiplier",
args: [[gaslessLayerAddress], [parseUnits("5", 18)], [10_000n]],
},
{ functionName: "allocate", args: [parseUnits("100", 18)] },
],
});
const record = await waitForGaslessRequest(config, { requestId: receipt.requestId });Each entry is one of three forms, freely mixed:
- A relayable write by name —
{ functionName, args }. The SDK already knows every relayable write, so no ABI is needed; passabi(the SDK’ssymmioAbi,accountLayerAbiorinstantLayerAbi) only if you hold it anyway.GASLESS_RELAYABLE_FUNCTIONSlists the names and their inputs. - Raw calldata of a relayable write —
{ data }, for arguments you encoded yourself with compile-time checks. - A GaslessWallet call list —
{ walletCalls, walletId }: calls the owner’s gasless wallet makes, as one operation. They run as the wallet contract, not as the SYMMIO account.
The target contract of a write is never passed: it is resolved from the encoded selector — the core diamond, the AccountLayer or the InstantLayer. A call whose selector is not a relayable write throws GASLESS_NOT_RELAYABLE before any network call; run anything else as a walletCalls entry.
What happens
- Every call is encoded and checked — nothing touches the network or the wallet yet.
- Every signer’s delegations are checked in execution order before any prompt (
execution.preflightDelegation, on by default). A valid owner-signed grant earlier in the same batch authorizes later write and wallet entries. A missing selector throwsGASLESS_SIGNER_NOT_DELEGATED, naming the signer and what to grant. Invalid grants throwGASLESS_INVALID_DELEGATION_GRANT. - Fresh nonces are read and sequenced per stream: the account’s InstantLayer nonces for the writes, each wallet id’s own nonces for its wallet entries.
- The batch is priced on-chain (
execution.preflightFee, on by default) — the same previewgetGaslessBatchFeeQuotereturns. A quote the contract refuses throws before any prompt; a quote that fails for transport reasons does not block, because the relayer simulates the full transaction anyway. - Each operation is signed by its call’s signer. In-memory signers such as a session key sign first, then each wallet prompt runs in relay order.
- One request carries them all, with one wallet id per operation —
0for every write.
One signature per call. The protocol has no batch signature: the InstantLayer verifies each operation’s signature
against that operation alone. A browser wallet therefore shows one prompt per call, in order; a session key passed as
from signs them silently. Nothing is submitted until every prompt is signed, so rejecting one abandons the batch and
consumes no nonce.
What a batch buys is shared fate — one revert rolls back every call and every fee — and one request to track. It also changes when the fee is due: the GaslessLayer collects fees after the whole batch executes, so an operational-fee approval early in the batch already covers the calls after it.
The account
account is the sub-account every operation runs under. It is each write’s signerAccount — whose InstantLayer nonces the batch consumes and whose delegations authorize a session key — and the billing account: a virtual account bills its parent. For a wallet entry it also selects the wallet: the GaslessLayer derives it from ownerOf(account), so a sub-account resolves to its owner’s wallets.
Margin writes run under the virtual account’s parent: pass the parent as account and the virtual account as the call’s argument, exactly as the transparent mode does.
Session keys
A session key signs a batch when it holds a delegation for every selector the batch runs, granted on account. getGaslessBatchSelectors builds that set from the calls — for a wallet entry it includes the wallet-execution sentinel.
await grantDelegation(config, {
account: { addr: subAccount, isPartyB: false },
delegatedSigner: sessionKey,
selectors: getGaslessBatchSelectors(calls),
expiryTimestamp,
});
await relayGaslessBatch(config, { account: subAccount, calls, from: sessionKey });A grantDelegation or grantDelegations call must be signed by the account’s owner. The InstantLayer rejects a
delegate-signed grant, so no delegation makes it relayable by a session key.
Mixing signers
Give any entry its own from to have a different signer sign it; entries without one use the batch’s from, or the
configured wallet. Combined with a grant earlier in the same batch, that is the one-signature setup: the owner signs
the grant, and the key it authorizes signs the rest without a prompt.
import { relayGaslessBatch } from "@symmio/trading-core";
import { parseUnits } from "viem";
const account = { addr: subAccount, isPartyB: false };
await relayGaslessBatch(config, {
account: subAccount,
calls: [
// Owner-signed: the one wallet prompt.
{
functionName: "grantDelegations",
args: [
[
{ account, delegatedSigner: sessionKey, selectors: sessionKeySelectors, expiryTimestamp },
{ account, delegatedSigner: tpslExecutor, selectors: tradingSelectors, expiryTimestamp },
],
],
},
// Signed by the key the grant above authorizes: no prompt.
{
functionName: "approveOperationalFee",
args: [[gaslessLayerAddress], [parseUnits("5", 18)]],
from: sessionKey,
},
],
});- Preflight validates grants before counting them. The signer must own the operation account, every grant must name that exact PartyA account, the delegate must differ from the owner, and selectors must be nonempty. Expiry must be later than the latest block timestamp. A valid grant covers only subsequent entries, including wallet entries that require both the execution sentinel and their inner selectors. Delegation reads use the live virtual account’s parent; deleted virtual accounts do not inherit the parent’s permissions.
- In-memory signers sign first. A signer whose wallet client holds a viem
localaccount, such as a session key, signs without a wallet prompt, so its signatures are made first. A local failure then surfaces before the user spends the prompt. The signatures are still sent in relay order. - Every entry supports
from. The signer resolves asentry.from, then the batch’sfrom, then the configured default wallet. Each requested signer is resolved once. When all entries have an explicit signer, no default wallet is needed. The GaslessWallet contract remains the executor of its inner calls, regardless of which key signs. - Build each key’s selectors from the calls it signs.
getGaslessBatchSelectorslists every call’s selector, so pass it only the calls that key signs. - The
approveOperationalFeenamed here is the diamond’s two-argument function: seeapproveOperationalFeeAllowancefor when to use it rather thanapproveOperationalFeeWithMultiplier.
An owner grant can also authorize a session-signed wallet operation in the same batch:
import { getGaslessBatchSelectors, relayGaslessBatch, type GaslessBatchCall } from "@symmio/trading-core";
import { erc20Abi } from "viem";
const sessionCalls: GaslessBatchCall[] = [
{
from: sessionKey,
walletId: 1n,
walletCalls: [{ target: usdc, abi: erc20Abi, functionName: "transfer", args: [recipient, amount] }],
},
];
await relayGaslessBatch(config, {
account: subAccount,
calls: [
{
from: owner,
functionName: "grantDelegation",
args: [
{
account: { addr: subAccount, isPartyB: false },
delegatedSigner: sessionKey,
selectors: getGaslessBatchSelectors(sessionCalls),
expiryTimestamp,
},
],
},
...sessionCalls,
],
});Preflight checks current authority; it does not simulate every state change inside a batch. The relayer simulation
and contracts remain authoritative, including if ownership, expiry, or revocation changes before execution. Setting
execution.preflightDelegation: false skips these SDK authorization reads and grant checks. The separate fee preview
stays read-only and never resolves signers or checks authorization.
Nonces and concurrency
The batch takes every nonce stream it signs on at once, so a concurrent relay on any of them — a transparent write, a gaslessWalletExecute, another batch — waits for it instead of signing the same nonce. As with every relay, the streams are released at the 202, and the next caller waits for the signed nonces lazily. See nonce streams.
The signatures’ deadline is fixed when the call starts, so an attempt started at T can never execute after T + GASLESS_SIGNATURE_LIFETIME_SECONDS (20 minutes).
For a shorter-lived delegation or authorization, pass deadline as an absolute Unix timestamp in seconds (bigint). It applies to every operation in the batch and must be in the future, at most 20 minutes from call time. Without it, the existing 20-minute default is unchanged. Explicit deadlines are checked again before signing and submission; an expiry during a wallet prompt prevents this attempt from being posted.
Persist the absolute deadline alongside your recovery inputs and idempotency key. Do not replace it with a fresh timestamp on retry. Expiry does not prove that an earlier attempt failed: confirm an accepted request by its saved requestId using confirmGaslessRequest, independently of signature expiry. An expired deadline cannot be used for a fresh relayGaslessBatch attempt.
Pass idempotencyKey — one per user action — to make the batch retryable. A later call under the same key never waits for its own earlier submit, returns that submit’s receipt when this config saw it accepted, and is otherwise accepted by the service at most once. Without a key, one is generated for this call alone; replay a submit whose response was lost with resubmitGaslessRequest, never by signing the batch again under a new key. See Recovering gasless writes.
A 202 is the point of no return: the workflow exists server-side and may execute even if polling later fails.
Persist the receipt’s requestId, owner, walletIds and idempotencyKey immediately. React consumers use
useRelayGaslessBatch, which confirms the batch before it resolves and
refreshes what its calls changed.
Parameters
accountAddressrequiredThe sub-account every operation runs under and is billed to. For margin writes, the virtual account’s parent.
callsreadonly GaslessBatchCall[]requiredThe calls, in execution order. An empty list throws GASLESS_EMPTY_BATCH.
calls[].functionNamestringA relayable write’s name, with args and an optional abi.
calls[].dataHexA relayable write as raw calldata.
calls[].walletCallsreadonly GaslessWalletCall[]Calls the owner’s GaslessWallet makes, each raw { target, data } or { target, abi, functionName, args }.
calls[].fromAddressoptionalWho signs this entry, including a wallet entry. Defaults to the batch’s from, then the configured wallet. See mixing signers.
calls[].walletIdbigintdefault 0noptionalWhich of the owner’s GaslessWallets runs a walletCalls entry. Range 0n through 2^256 - 1.
operationTypestringoptionalFree-form label (1–128 characters) stored with the request. Defaults to the calls’ own names joined with +
("approveOperationalFee+allocate"), or "gaslessBatch" when that is too long. Fees are not keyed from it.
metadataRecord<string, unknown>optionalNon-secret client correlation data stored with the request.
deadlinebigintoptionalAbsolute signature expiry in Unix seconds for every batch operation. Defaults to call time plus 20 minutes; an explicit value can shorten, but never lengthen, that window.
fromAddressoptionalThe signer to resolve the wallet client with — a session key, for example.
idempotencyKeystringoptionalYour key for one user action, 1–128 characters, from
generateGaslessIdempotencyKey. Reuse it on every attempt of that
action. Defaults to a key generated for this call alone.
chainIdnumberoptionalTarget chain id. Defaults to the config’s defaultChainId.
Returns
Promise<GaslessSubmitReceipt>The 202 acceptance, with walletIds holding one id per operation (0n for every write). The fields are the same as
relayInstantOperations’ — persist requestId, owner,
walletIds and idempotencyKey together.
Throws
-
SymmError("validation", "GASLESS_BATCH_DEADLINE_INVALID"): an explicit deadline is not a future bigint Unix timestamp within 20 minutes. Rejected before network calls or prompts. -
SymmError("validation", "GASLESS_BATCH_DEADLINE_EXPIRED"): the explicit deadline elapsed during preparation or signing. This attempt was not submitted; an earlier attempt must still be reconciled. -
SymmError("validation", "GASLESS_IDEMPOTENCY_KEY_INVALID"): the key is blank or longer than 128 characters. Thrown before any network call. -
SymmError("config", "GASLESS_NOT_CONFIGURED")/("config", "GASLESS_UNSUPPORTED_CONTRACTS_VERSION"). -
SymmError("validation", "GASLESS_EMPTY_BATCH"),("validation", "GASLESS_NOT_RELAYABLE")or("validation", "GASLESS_WALLET_ID_INVALID"): thrown before any network call. -
Viem’s encoding error when an ABI-level call’s arguments do not encode.
-
SymmError("config", "GASLESS_CONFIG_INCOHERENT"): the GaslessLayer verifies another InstantLayer than the chain config signs for. -
SymmError("validation", "GASLESS_SIGNER_NOT_DELEGATED"): a non-owner signer is missing a selector that no earlier grant in the batch covers. The message names each signer and its missing selectors. -
SymmError("validation", "GASLESS_INVALID_DELEGATION_GRANT"): preflight rejects a grant’s signer, account, PartyB flag, self-delegation, expiry, or empty entries/selectors. The message identifies the entry and reason. -
SymmError("api", "GASLESS_FREE_QUOTA_EXHAUSTED"),("validation", "GASLESS_FEE_QUOTE_REVERTED")or("config", "GASLESS_LAYER_INTERFACE_UNSUPPORTED")from the fee pre-flight, before any prompt. -
SymmError("api", "GASLESS_NONCE_STREAM_BUSY"): an earlier relay on one of the batch’s nonce streams is still unaccounted for. -
SymmApiErrorwith codeGASLESS_RELAY_SUBMIT_FAILEDon HTTP failure, andGASLESS_SUBMIT_UNCONFIRMEDwhen the outcome could not be established — replay it withresubmitGaslessRequest. -
The wallet’s own error when the user rejects a prompt. Nothing is submitted.