Create accounts programmatically
Create a Lighter account for a user and register an API key for your app, with a single wallet signature.
Onboarding a user takes two required steps, followed by optional account setup:
Create the account – the user deposits; Lighter assigns an account index.
Register an API key – your app generates a keypair; the user signs
ChangePubKeyonce with their wallet.Create sub-accounts (optional) – isolate balances and strategies.
Upgrade the tier (optional) – enable the fees and limits your integration needs.
After registration, your app signs orders with the API key. No more wallet pop-ups for ordinary orders.
1. Create the account
There is no "sign-up" call. The first deposit creates the account, allowing you to interact with the exchange without ever needing to touch the front-end. See Deposits, Transfers and Withdrawals for all deposit methods.
Direct Ethereum deposit: credited in a few minutes.
Universal Deposit Address from any supported chain: new accounts are created automatically.
Legacy CCTP route: around 15–20 minutes.
Then look up the master account index with accountsByL1Address (or account):
const r = await fetch(
`${BASE_URL}/api/v1/accountsByL1Address?l1_address=${userAddress}`,
).then(r => r.json());
if (r.code === 21100) {
throw new Error("Account not found: wait for the deposit and retry this lookup");
}
if (r.code !== 200) throw new Error(`Account lookup failed: ${r.code} ${r.message}`);
const master = r.sub_accounts.find((a: { account_type: number }) => a.account_type === 0);
if (!master) throw new Error("Master account not found");
const masterAccountIndex = master.index;You can also read addressToAccountIndex (0xabf6a038) on Lighter's Ethereum contract.
2. Register an API key
Generating a key doesn't need the user's wallet, but registering it for the account does (ChangePubKey with an L1 signature). The TypeScript example below uses the WASM signer from the TypeScript quickstart. With the SDKs, see system_setup.py (Python) or the lighter-go README (Go).
code: 200 only means the API accepted the transaction. It still has to execute before the key can sign orders, so poll apikeys until it returns your public key:
Key storage
Browser
Encrypt at rest (e.g. WebCrypto with a non-extractable key); never send to your server
Mobile
OS keychain / keystore
Server (on behalf of users)
KMS or secrets manager; one key per user; audit access
If a key is lost, just generate and register a new one at the same index.
Multisig / smart-contract wallets
Smart wallets cannot produce an ECDSA personal_sign. Register the key with an on-chain changePubKey call instead. See Multi-signature and smart wallets.
3. Sub-accounts (optional)
Use sub-accounts to isolate strategies or users' positions. Sign with SignCreateSubAccount(skipNonce, nonce, apiKeyIndex, accountIndex) from the master account. Each sub-account needs its own API key registered. The number of sub-accounts depends on the tier: see Account Types.
4. Upgrade the tier (optional)
Partner fees require the user to be on Plus or Premium/Advanced. See Partner Attribution and Account Types.
Last updated
Was this helpful?