import { createBaseAccountSDK } from '@base-org/account';
import { base } from 'viem/chains';

const sdk = createBaseAccountSDK({
  appName: 'My DApp',
  appLogoUrl: 'https://mydapp.com/logo.png',
  appChainIds: [base.id],
});

const provider = sdk.getProvider();
Defined in the Base Account SDK
Creates a Base Account SDK instance that provides an EIP-1193 compliant Ethereum provider and additional account management functionality. This is the primary entry point for integrating Base Account into your application.

Parameters

params
CreateProviderOptions
required
Configuration options for creating the SDK instance.

Returns

sdk
BaseAccountSDK
SDK instance with provider and sub-account management capabilities.
import { createBaseAccountSDK } from '@base-org/account';
import { base } from 'viem/chains';

const sdk = createBaseAccountSDK({
  appName: 'My DApp',
  appLogoUrl: 'https://mydapp.com/logo.png',
  appChainIds: [base.id],
});

const provider = sdk.getProvider();

Integration Examples

With Viem

import { createWalletClient, custom } from 'viem';
import { base } from 'viem/chains';
import { createBaseAccountSDK } from '@base-org/account';

const sdk = createBaseAccountSDK({
  appName: 'Viem Integration',
  appChainIds: [base.id]
});

const provider = sdk.getProvider();

const client = createWalletClient({
  chain: base,
  transport: custom(provider)
});

With Wagmi

import { createConfig, custom } from 'wagmi';
import { base } from 'wagmi/chains';
import { createBaseAccountSDK } from '@base-org/account';

const sdk = createBaseAccountSDK({
  appName: 'Wagmi Integration',
  appChainIds: [base.id]
});

const provider = sdk.getProvider();

const config = createConfig({
  chains: [base],
  transports: {
    [base.id]: custom(provider),
  },
});

Configuration Options

Attribution

Configure transaction attribution for analytics and tracking:
// Auto-generate attribution from app origin
const sdk = createBaseAccountSDK({
  appName: 'My App',
  preference: {
    attribution: { auto: true }
  }
});

// Custom attribution data
const sdk = createBaseAccountSDK({
  appName: 'My App',
  preference: {
    attribution: { dataSuffix: '0x1234567890123456789012345678901234567890' }
  }
});

Paymaster Integration

Enable gasless transactions with paymaster URLs:
const sdk = createBaseAccountSDK({
  appName: 'Gasless App',
  appChainIds: [8453, 84532],
  paymasterUrls: {
    8453: 'https://paymaster.base.org/api/v1/sponsor',
    84532: 'https://paymaster.base-sepolia.org/api/v1/sponsor'
  }
});

Error Handling

The SDK initialization is synchronous and will validate preferences during creation:
try {
  const sdk = createBaseAccountSDK({
    appName: 'My App',
    appChainIds: [8453],
    subAccounts: {
      toOwnerAccount: invalidFunction // Will throw validation error
    }
  });
} catch (error) {
  console.error('SDK initialization failed:', error);
}

TypeScript Support

The SDK is fully typed for TypeScript development:
import type { 
  CreateProviderOptions, 
  BaseAccountSDK,
  ProviderInterface,
  ToOwnerAccountFn 
} from '@base-org/account';
import { LocalAccount } from 'viem';

const toOwnerAccount: ToOwnerAccountFn = async () => {
  // Your logic to get the owner account
  const ownerAccount: LocalAccount | null = getOwnerAccount();
  return { account: ownerAccount };
};

const options: CreateProviderOptions = {
  appName: 'Typed App',
  appChainIds: [8453],
  subAccounts: {
    toOwnerAccount
  }
};

const sdk: BaseAccountSDK = createBaseAccountSDK(options);
const provider: ProviderInterface = sdk.getProvider();
The SDK automatically manages Cross-Origin-Opener-Policy validation and telemetry initialization. Make sure your application’s headers allow popup windows if using the default wallet interface.
The createBaseAccountSDK function is the primary entry point for Base Account integration. It provides both a standard EIP-1193 provider and advanced features like sub-account management and gasless transactions.