SVG Definitions

Create Smart Account

Create a Smart Account with Multi-Chain ECDSA validator

When you create a smart account, you can choose from a variety of validators to define how the account validates UserOps. In this tutorial, we will be using the Multi-Chain ECDSA validator, which works like a normal EOA by validating signatures from a ECDSA private key, but also supports sending multiple UserOps across multiple chains using a single signature.


Import

import { createAccountClient } from "@namera-ai/sdk/account";

Usage

To create a smart account, you need a ecdsa validator, a public client, and a bundler client. The ECDSA validator can be one of: EIP1193Provider, WalletClient, LocalAccount, or SmartAccount.

In this example, we will be using the LocalAccount.

index.ts
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
import { publicClient, bundlerClient } from './clients';
import { mainnet } from 'viem/chains';
import { createAccountClient } from '@namera-ai/sdk/account';

const signer = privateKeyToAccount(generatePrivateKey());

const client = await createAccountClient({
  type: "ecdsa",
  bundlerTransport: http("https://public.pimlico.io/v2/1/rpc"), // Public Pimlico RPC
  chain: mainnet,
  client: publicClient,
  entrypointVersion: "0.7",
  kernelVersion: "0.3.2",
  signer,
});

const saAddress = client.account.address; // Smart Account Address

Examples

Create a new ECDSA Smart Account client on Ethereum Mainnet with local signer and paymaster.

index.ts
import { createAccountClient } from "@namera-ai/sdk/account";
import { createPublicClient, http } from "viem";
import { createPaymasterClient } from "viem/account-abstraction";
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";

export const publicClient = createPublicClient({
  chain: mainnet,
  transport: http(),
});

const paymaster = createPaymasterClient({
  transport: http("ZERO_DEV_PAYMASTER_URL"),
});

const signer = privateKeyToAccount(generatePrivateKey());

const client = await createAccountClient({
  type: "ecdsa",
  bundlerTransport: http("https://public.pimlico.io/v2/1/rpc"), // Public Pimlico RPC
  chain: mainnet,
  client: publicClient,
  entrypointVersion: "0.7",
  kernelVersion: "0.3.2",
  paymaster,
  signer,
});

const saAddress = client.account.address; // Smart Account Address

The Bundler URL above is a public endpoint. Please do not use it in production as you will likely be rate-limited. Consider using Pimlico's Bundler, Biconomy's Bundler, or another Bundler service.


Parameters

signer

  • Only required when type="ecdsa"
  • Type: Signer | OneOf<EIP1193Provider, WalletClient, LocalAccount, SmartAccount>
index.ts
const client = await createAccountClient({
  type: "ecdsa",
  signer: walletClient, 
  bundlerTransport: http("https://public.pimlico.io/v2/1/rpc"), // Public Pimlico RPC
  chain: mainnet,
  client: publicClient,
  entrypointVersion: "0.7",
  kernelVersion: "0.3.2",
});

client

  • Type: Client<HttpTransport, Chain, JsonRpcAccount | LocalAccount | undefined>
index.ts
import { createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";

export const publicClient = createPublicClient({
  chain: mainnet,
  transport: http(),
});

bundlerTransport

  • Type: Transport
index.ts
import { createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";

export const publicClient = createPublicClient({
  chain: mainnet,
  transport: http(),
});

chain

  • Type: Chain
index.ts
import { mainnet } from "viem/chains";

entrypointVersion

  • Type: EntrypointVersion => "0.6" | "0.7" | "0.8" | "0.9"
index.ts
import { EntryPointVersion } from 'viem/account-abstraction';  
type EntryPointVersion = "0.6" | "0.7" | "0.8" | "0.9"
const = await createAccountClient({ : "ecdsa", : walletClient, : http("https://public.pimlico.io/v2/1/rpc"), // Public Pimlico RPC : mainnet, : publicClient, : "0.7", : "0.3.2", });

kernelVersion

  • Type: KernelVersion => "0.0.2" | "0.2.2" | "0.2.3" | "0.2.4" | "0.3.1" | "0.3.2" | "0.3.3"

Note: Kernel 0.2.x supports only Entrypoint 0.6. For Kernel 0.3.x, you can use Entrypoint 0.7 or 0.8.

index.ts
const client = await createAccountClient({
  type: "ecdsa",
  signer: walletClient,
  bundlerTransport: http("https://public.pimlico.io/v2/1/rpc"), // Public Pimlico RPC
  chain: mainnet,
  client: publicClient,
  entrypointVersion: "0.7",
  kernelVersion: "0.3.2", 
});

index

index.ts
import { createAccountClient } from "@namera-ai/sdk/account";

const client = await createAccountClient({
  type: "ecdsa",
  signer: walletClient,
  bundlerTransport: http("https://public.pimlico.io/v2/1/rpc"), // Public Pimlico RPC
  chain: mainnet,
  client: publicClient,
  entrypointVersion: "0.7",
  kernelVersion: "0.3.2",
  index: 0n, 
});

paymaster

  • Type: PaymasterClient
index.ts
import { createPaymasterClient } from "viem/account-abstraction";  
import { createAccountClient } from "@namera-ai/sdk/account";

const paymaster = createPaymasterClient({  
  transport: http("ZERO_DEV_PAYMASTER_URL"),  
});  


const client = await createAccountClient({
  type: "ecdsa",
  signer: walletClient,
  bundlerTransport: http("https://public.pimlico.io/v2/1/rpc"), // Public Pimlico RPC
  chain: mainnet,
  client: publicClient,
  entrypointVersion: "0.7",
  kernelVersion: "0.3.2",
  index: 0n,
  paymaster: paymasterClient, 
});

FAQs

When I create a account, is it deployed onchain?

No, accounts are not deployed onchain yet. Your account is deployed automatically when you send the first UserOp. You can create an infinite number of such account objects without paying any gas.

Can I create multiple accounts from the same signer?

Yes, you can do so by providing an index when you create the account object.

index.ts
import { createAccountClient } from "@namera-ai/sdk/account";

const client = await createAccountClient({
  type: "ecdsa",
  signer: walletClient,
  bundlerTransport: http("https://public.pimlico.io/v2/1/rpc"), // Public Pimlico RPC
  chain: mainnet,
  client: publicClient,
  entrypointVersion: "0.7",
  kernelVersion: "0.3.2",
  index: 1n, 
});