Docs

Getting Started

Getting started to add ERC-4337 compatible smart accounts to your application easily.

Once set, your application will:

  • Let users connect to their smart account using any personal wallet, including email and local wallets for easy onboarding.
  • Automatically deploy individual account contracts for your users when they do their first onchain transaction.
  • Handle all transaction gas costs via the thirdweb paymaster.

1. Deploy a account factory contract

Deployable via the explore page or build your own ERC 4337 compatible factory contract using the Solidity SDK.

thirdweb offers different kinds of account factories:

Read about the differences between the account factory types here.

2. Get a free API key

You will require an API key to use thirdweb's infrastructure services such as the bundler and paymaster.

Obtain an API key from the thirdweb dashboard Settings page.

The API key lets you access thirdweb's bundler and paymaster infrastructure, which is required for smart accounts to operate and optionally enable gasless transactions.

Learn more about creating an API key and restricting which contracts the smart account can interact with here.

3. Connect smart accounts in your application

Use the following code to integrate account abstraction into your apps. This will:

  • Connect your users to their smart account based on their personal wallet (can be any EOA wallet such as embedded wallet or metamask).
  • Automatically deploy the individual account contracts for your users when they do their first onchain transaction.
  • Handle all transaction gas costs via the thirdweb paymaster.
  • Select your deployed account factory and client ID to get use the thirdweb infrastructure.
import {
ThirdwebProvider,
ConnectWallet,
smartWallet,
embeddedWallet,
} from "@thirdweb-dev/react";
export default function App() {
return (
<ThirdwebProvider
clientId="YOUR_CLIENT_ID"
activeChain="sepolia"
supportedWallets={[
smartWallet(
embeddedWallet(), // any personal wallet
{
factoryAddress: "0x...", // your deployed factory address
gasless: true, // enable or disable gasless transactions
},
),
]}
>
<ConnectWallet />
</ThirdwebProvider>
);
}

Using a Template

Clone these templates to create smart accounts and connect to them quickly.

Node.js Script

A Node.js script to create and interact with smart accounts.

React App

A React app to create and interact with smart accounts.

4. Executing Transactions with Smart Accounts

Once setup, you can use the thirdweb TypeScript, React, React Native and Unity SDKs to deploy contracts, perform transactions, and manipulate wallets like any other wallet.

import {
useAddress,
useContract,
useOwnedNFTs,
Web3Button,
} from "@thirdweb-dev/react";
// The ThirdwebProvider setup above already handles connection to the smart wallet
// Within the provider, you can use the react SDK hooks to interact with the blockchain
export default function MyComponent() {
// Get the connected smart wallet address
const smartWalletAddress = useAddress();
// Fetch owned NFTs
const { contract } = useContract("0x...");
const { data, isLoading } = useOwnedNFTs(
contract,
smartWalletAddress,
);
// Mint a new NFT
return (
<Web3Button
contractAddress={"0x..."}
action={(contract) =>
contract.erc721.mint({
name: "My NFT",
description: "My NFT description",
image: "https://example.com/image.png",
})
}
>
Mint NFT
</Web3Button>
);
}