Setup
Before you can send transactions, you need to create a smart account. This links your user’s KMS-backed EOA to an ERC-4337 contract account on the target chain.
setupSmartAccount()
Section titled “setupSmartAccount()”const smartAccountAddress = await client.setupSmartAccount();console.log('Smart account:', smartAccountAddress);// "0xAbCd...1234"You must call login() before this. Calling setupSmartAccount() without a logged-in user throws an error.
Calling setupSmartAccount() a second time (within the same session) is safe — it returns the cached address without doing any work.
What happens internally
Section titled “What happens internally”- The SDK wraps
OxGasAuthin anOxGasAuthSigneradapter, which implements theSmartAccountSignerinterface expected by@0xgasless/smart-account. - It calls
createSmartAccountClient()from the smart account SDK, passing the signer, bundler URL, paymaster URL, and chain ID. - The smart account client computes the counterfactual address — the address the contract will have once deployed.
- That address is cached and returned.
The contract is not deployed yet at this point. Deployment happens automatically on the first transaction (it’s bundled in the same UserOperation), so the user pays no separate deployment fee.
Account index
Section titled “Account index”By default, index 0 is used, giving every user a single smart account per chain. You can derive a second account using a different index:
const client = new OxGasClient({ apiKey: 'your-api-key', chainId: 8453, bundlerUrl: '...', paymasterUrl: '...', accountIndex: 1, // Second account for this user});Checking if a smart account is set up
Section titled “Checking if a smart account is set up”if (!client.hasSmartAccount) { await client.setupSmartAccount();}Full initialization pattern
Section titled “Full initialization pattern”const client = new OxGasClient({ /* config */ });
// Step 1: Authenticateconst wallet = await client.login();console.log('EOA:', wallet.address);
// Step 2: Set up smart accountconst saAddress = await client.setupSmartAccount();console.log('Smart account:', saAddress);
// Step 3: Ready to send transactions