createSubAccounts
Create one or more subaccounts under an affiliate. A direct wallet transaction creates them for that wallet; a gasless operation creates them for the billing account’s owner, including when a delegated session key signs.
import { createSubAccounts, encodeSubAccountHookMetadata, SubAccountIsolationType } from "@symmio/trading-core";
const hash = await createSubAccounts(config, {
affiliate: "0xaff...",
accountsData: [
{
name: "Main",
metadata: encodeSubAccountHookMetadata({ partyBToBind: solverAddress }),
symmioCore: "0xcore...",
isolationType: SubAccountIsolationType.MARKET,
singleVAMode: true,
},
],
});The created addresses are deterministic and returned by the contract call, but they are only readable once the
transaction is mined — take them from the SubAccountCreated events on the receipt, or refetch
getUserSubAccounts.
Hook metadata
The affiliate’s onAccountCreation hook receives each entry’s metadata unchanged and decides its encoding. A blob the
hook rejects reverts the whole call with HookFailed. For the chain’s default affiliate, build the blob with
encodeSubAccountHookMetadata, passing the chain’s solver as
partyBToBind. Its referral code is global and single-use, so never reuse a fixed one. An affiliate with its own hook
needs the blob that hook decodes.
Relaying it without gas
createSubAccounts relays like any other relayable write. The relayer scopes the
AccountLayer call to the billing account’s owner. That owner receives the new accounts even when a delegated
session key signs the operation.
const hash = await createSubAccounts(config, {
affiliate: "0xaff...",
accountsData,
gasless: { enabled: true, account: existingSubAccount },
});This is the one relayable write that requires gasless.account. Every relayed operation is signed under an
account the InstantLayer can resolve on chain, and the subaccounts being created do not exist yet — so an existing
owned subaccount has to sign, and it pays the operational fee. Without it the call throws
GASLESS_ACCOUNT_UNRESOLVED. A wallet with no subaccount at all cannot bootstrap this way; use
settleGaslessDepositNewAccount, which creates the first account
as part of the deposit.
Parameters
affiliateAddressrequiredAffiliate that custodies the new subaccounts. Must be ACTIVE on chain, and each entry’s symmioCore must be
whitelisted and registered for it.
accountsDatareadonly SubAccountCreationData[]requiredOne entry per subaccount to create — name, metadata, symmioCore,
isolationType and singleVAMode. The created addresses come
back in this same order.
chainIdnumberoptionalOptional chain override.
simulateBeforeWritebooleanoptionalDry-run wallet execution via simulateContract first, including wallet fallback (defaults to the config’s setting,
itself true by default).
gaslessboolean | GaslessWriteOptionsoptionalRelay this write through the gasless execution mode instead of the wallet.
gasless.account is required — see the callout above.
Returns
HashRecovering an interrupted creation
A relayed creation can end without a clear answer — a lost response, a closed page, a timed-out wait. Give each user action its own gasless.idempotencyKey, save it before calling, and call again under the same key: the service accepts the key at most once, so the account is never created twice.
import { createSubAccounts, generateGaslessIdempotencyKey } from "@symmio/trading-core";
const key = generateGaslessIdempotencyKey();
await pendingActions.save({ key, affiliate, accountsData, payer });
const hash = await createSubAccounts(config, {
affiliate,
accountsData,
gasless: { account: payer, idempotencyKey: key },
});A key makes the call strictly gasless: it never falls back to the wallet on its own. Recovering gasless writes covers the full lifecycle — what to save, how to read each outcome, and how to reconcile one that stays unknown.