smartWallet

Creates a ERC4337 smart wallet based on a admin account.

Smart wallets are smart contract wallets that enable multiple benefits for users:

  • Sponsor gas fees for transactions

  • Multiple owners

  • Session keys

  • Batch transactions

  • Predictable addresses

  • Programmable features

Learn more about account abstraction

Example

Connect to a smart wallet

To connect to a smart wallet, you need to provide an admin account as the personalAccount option.

Any wallet can be used as an admin account, including an in-app wallets.

The sponsorGas option is used to enable sponsored gas for transactions automatically.

import { smartWallet, inAppWallet } from "thirdweb/wallets";
import { sepolia } from "thirdweb/chains";
import { sendTransaction } from "thirdweb";
const wallet = smartWallet({
chain: sepolia,
sponsorGas: true, // enable sponsored transactions
});
// any wallet can be used as an admin account
// in this example we use an in-app wallet
const adminWallet = inAppWallet();
const personalAccount = await adminWallet.connect({
client,
chain: sepolia,
strategy: "google",
});
const smartAccount = await wallet.connect({
client,
personalAccount, // pass the admin account
});
// sending sponsored transactions with the smartAccount
await sendTransaction({
account: smartAccount,
transaction,
});

Using a custom account factory

You can pass a custom account factory to the smartWallet function to use a your own account factory.

import { smartWallet } from "thirdweb/wallets";
import { sepolia } from "thirdweb/chains";
const wallet = smartWallet({
chain: sepolia,
sponsorGas: true, // enable sponsored transactions
factoryAddress: "0x...", // custom factory address
});
## Using v0.7 Entrypoint
Both v0.6 (default) and v0.7 ERC4337 Entrypoints are supported. To use the v0.7 Entrypoint, simply pass in a compatible account factory.
You can use the predeployed `DEFAULT_ACCOUNT_FACTORY_V0_7` or deploy your own [AccountFactory v0.7](https://thirdweb.com/thirdweb.eth/AccountFactory_0_7).
```ts
import { smartWallet, DEFAULT_ACCOUNT_FACTORY_V0_7 } from "thirdweb/wallets/smart";
import { sepolia } from "thirdweb/chains";
const wallet = smartWallet({
chain: sepolia,
sponsorGas: true, // enable sponsored transactions
factoryAddress: DEFAULT_ACCOUNT_FACTORY_V0_7, // 0.7 factory address
});

Configuring the smart wallet

You can pass options to the smartWallet function to configure the smart wallet.

import { smartWallet } from "thirdweb/wallets";
import { sepolia } from "thirdweb/chains";
const wallet = smartWallet({
chain: sepolia,
sponsorGas: true, // enable sponsored transactions
factoryAddress: "0x...", // custom factory address
overrides: {
accountAddress: "0x...", // override account address
accountSalt: "0x...", // override account salt
entrypointAddress: "0x...", // override entrypoint address
erc20Paymaster: { ... }, // enable erc20 paymaster
bundlerUrl: "https://...", // override bundler url
paymaster: (userOp) => { ... }, // override paymaster
...
}
});

Refer to SmartWalletOptions for more details.

@wallet

function smartWallet(
createOptions: SmartWalletOptions,
): Wallet<"smart">;

Parameters

The options for creating the wallet. Refer to SmartWalletCreationOptions for more details.

Type

let createOptions: Prettify<
{
chain: Chain;
factoryAddress?: string;
overrides?: {
accountAddress?: string;
accountSalt?: string;
bundlerUrl?: string;
createAccount?: (
factoryContract: ThirdwebContract,
entrypointAddress?: string;
erc20Paymaster?: { address: string; token: string };
execute?: (
accountContract: ThirdwebContract,
transaction: SendTransactionOption,
executeBatch?: (
accountContract: ThirdwebContract,
transactions: Array<SendTransactionOption>,
getAccountNonce?: (
accountContract: ThirdwebContract,
) => Promise<bigint>;
paymaster?: (
userOp: UserOperationV06 | UserOperationV07,
) => Promise<PaymasterResult>;
predictAddress?: (
factoryContract: ThirdwebContract,
) => Promise<string>;
};
} & ({ gasless: boolean } | { sponsorGas: boolean })
>;

Returns

let returnType: Wallet<"smart">;

The created smart wallet.