Skip to content

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.

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.

  1. The SDK wraps OxGasAuth in an OxGasAuthSigner adapter, which implements the SmartAccountSigner interface expected by @0xgasless/smart-account.
  2. It calls createSmartAccountClient() from the smart account SDK, passing the signer, bundler URL, paymaster URL, and chain ID.
  3. The smart account client computes the counterfactual address — the address the contract will have once deployed.
  4. 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.

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
});
if (!client.hasSmartAccount) {
await client.setupSmartAccount();
}
const client = new OxGasClient({ /* config */ });
// Step 1: Authenticate
const wallet = await client.login();
console.log('EOA:', wallet.address);
// Step 2: Set up smart account
const saAddress = await client.setupSmartAccount();
console.log('Smart account:', saAddress);
// Step 3: Ready to send transactions