A tutorial that teaches how to implement Account Abstraction into a Base project using Biconomy paymasters, bundlers, and smart accounts.
This page will guide you through the process of implementing Account Abstraction in your Base projects using Biconomy paymasters, bundlers, and smart accounts.
By the end of this tutorial you should be able to do the following:
create next-app
This tutorial requires you to have Foundry installed.
curl -L https://foundry.paradigm.xyz | bash
foundryup
, to install the latest (nightly) build of FoundryFor more information, see the Foundry Book installation guide.
This tutorial requires you to have a wallet. You can create a wallet by downloading the Coinbase Wallet browser extension:
To complete this tutorial, you will need to fund a wallet with ETH on Base Goerli.
The ETH is required for covering gas fees associated with deploying smart contracts to the network.
Biconomy is a toolkit that offers a full-stack solution for Account Abstraction, including smart accounts, paymasters for sponsoring gas fees, and bundlers for bundling user operations into a single transaction.
Account Abstraction (ERC-4337) allows users to use Smart Contract wallets instead of traditional Externally Owned Account (EOA) wallets.
A smart account (also known as a smart contract wallet) is a wallet that stores and manages digital assets (ERC-20 tokens, NFTs, etc.) using a smart contract.
A user operation is a pseudo-transaction object sent by a smart account that describes a transaction to be sent. Multiple user operations are eventually bundled together and initiated as a single real transaction by a bundler.
A paymaster is a special smart contract that allows applications to “sponsor user operations”, meaning it will pay for the gas fees associated with the resulting transaction.
A special node that monitors a mempool of user operations and bundles multiple user operations into a single transaction.
Biconomy’s Paymaster is a service that allows you to sponsor gas fees for your users, enabling gasless transactions. Learn more in the Biconomy documentation.
Before you begin, you need to set up a smart contract development environment using Foundry.
To create a new project, first create a new directory named myproject
, and change it to your current working directory:
Next, within the myproject
directory create a new directory named contracts
, and change it to your current working directory:
Then create a new Foundry project by running the following command:
This will create a Foundry project with the following basic layout:
The command creates a boilerplate Solidity smart contract file named src/Counter.sol
. This is the primary contract you will use for this tutorial.
Compile the smart contract to ensure it builds without any errors.
To compile your smart contract, run:
Before you can deploy your smart contract to various chains you will need to set up a wallet to be used as the deployer.
To do so, you can use the cast wallet import
command to import the private key of the wallet into Foundry’s securely encrypted keystore:
After running the command above, you will be prompted to enter your private key, as well as a password for signing transactions.
For instructions on how to get your private key from Coinbase Wallet, visit the Coinbase Wallet documentation. It is critical that you do NOT commit this to a public repo.
To confirm that the wallet was imported as the deployer
account in your Foundry project, run:
To deploy the smart contract, you can use the forge create
command. The command requires you to specify the smart contract you want to deploy, an RPC URL of the network you want to deploy to, and the account you want to deploy with.
Your wallet must be funded with ETH on the Base Goerli testnet to cover the gas fees associated with the smart contract deployment. Otherwise, the deployment will fail.
To get testnet ETH, see the prerequisites.
To deploy the smart contract to the Base Goerli testnet, run the following command:
When prompted, enter the password that you set earlier, when you imported your wallet’s private key.
After running the command above, the contract will be deployed on the Base Goerli test network. You can view the deployment status and contract by using a block explorer.
To setup the paymaster and bundler for your project, you will need to visit the Biconomy Dashboard and complete the following steps.
Add and register a Paymaster by completing the following steps:
You should now have a registered Biconomy paymaster.
The API Key and Paymaster URL for the paymaster are provided under the Overview tab in the Biconomy Dashboard.
Set up and fund the paymaster’s gas tank by completing the following steps:
ETH should now be deposited into the gas tank for your paymaster. You can visit the Withdraw tab at a later time if you wish to withdraw the funds.
Set up and fund the paymaster’s gas tank by completing the following steps:
At the time of writing this tutorial, the Bundler service is still under development, however a Bundler URL is provided for testing out UserOperations on test networks. You can specify the chain ID 84531 to use the Bundler URL on Base Goerli testnet.
After you set up your paymaster and bundler from the Biconomy Dashboard, the next step is to create a Next.js project for your app’s frontend.
From the root of the myproject
directory of your project, create a new Next.js project by running the following command:
To use the paymaster and bundler that were setup from the Biconomy Dashboard, you will need to add a few dependencies to your Next.js project.
To install Biconomy as a dependency to your project, run the following command:
Creating Biconomy smart accounts requires a signer from an EIP-1193 provider. Biconomy works with a variety of different social login and embedded wallet onboarding solutions that provide access to a signer that can be used for creating smart accounts. In this tutorial, you will use Particle Network for user authentication and getting a smart account signer.
To install Particle Network as a dependency to your project, run the following command:
The main page (page.tsx
) of the Next.js project created when running the yarn create next-app
command contains a Home
component. This component comes with a lot of code that is unnecessary for this tutorial.
Replace the content of the page.tsx
file with the following simplified code:
To get started adding social login into the app using Particle Network, import and initialize the Biconomy Particle Auth module in the page.tsx
file as shown below:
You will need to sign up for a Particle Network account and replace the values of PARTICLE_PROJECT_ID
, PARTICLE_CLIENT_ID
, and PARTICLE_APP_ID
.
If you encounter issues with Paymaster integration, ensure your API keys are correct and your contract is whitelisted in the Biconomy dashboard.
A tutorial that teaches how to implement Account Abstraction into a Base project using Biconomy paymasters, bundlers, and smart accounts.
This page will guide you through the process of implementing Account Abstraction in your Base projects using Biconomy paymasters, bundlers, and smart accounts.
By the end of this tutorial you should be able to do the following:
create next-app
This tutorial requires you to have Foundry installed.
curl -L https://foundry.paradigm.xyz | bash
foundryup
, to install the latest (nightly) build of FoundryFor more information, see the Foundry Book installation guide.
This tutorial requires you to have a wallet. You can create a wallet by downloading the Coinbase Wallet browser extension:
To complete this tutorial, you will need to fund a wallet with ETH on Base Goerli.
The ETH is required for covering gas fees associated with deploying smart contracts to the network.
Biconomy is a toolkit that offers a full-stack solution for Account Abstraction, including smart accounts, paymasters for sponsoring gas fees, and bundlers for bundling user operations into a single transaction.
Account Abstraction (ERC-4337) allows users to use Smart Contract wallets instead of traditional Externally Owned Account (EOA) wallets.
A smart account (also known as a smart contract wallet) is a wallet that stores and manages digital assets (ERC-20 tokens, NFTs, etc.) using a smart contract.
A user operation is a pseudo-transaction object sent by a smart account that describes a transaction to be sent. Multiple user operations are eventually bundled together and initiated as a single real transaction by a bundler.
A paymaster is a special smart contract that allows applications to “sponsor user operations”, meaning it will pay for the gas fees associated with the resulting transaction.
A special node that monitors a mempool of user operations and bundles multiple user operations into a single transaction.
Biconomy’s Paymaster is a service that allows you to sponsor gas fees for your users, enabling gasless transactions. Learn more in the Biconomy documentation.
Before you begin, you need to set up a smart contract development environment using Foundry.
To create a new project, first create a new directory named myproject
, and change it to your current working directory:
Next, within the myproject
directory create a new directory named contracts
, and change it to your current working directory:
Then create a new Foundry project by running the following command:
This will create a Foundry project with the following basic layout:
The command creates a boilerplate Solidity smart contract file named src/Counter.sol
. This is the primary contract you will use for this tutorial.
Compile the smart contract to ensure it builds without any errors.
To compile your smart contract, run:
Before you can deploy your smart contract to various chains you will need to set up a wallet to be used as the deployer.
To do so, you can use the cast wallet import
command to import the private key of the wallet into Foundry’s securely encrypted keystore:
After running the command above, you will be prompted to enter your private key, as well as a password for signing transactions.
For instructions on how to get your private key from Coinbase Wallet, visit the Coinbase Wallet documentation. It is critical that you do NOT commit this to a public repo.
To confirm that the wallet was imported as the deployer
account in your Foundry project, run:
To deploy the smart contract, you can use the forge create
command. The command requires you to specify the smart contract you want to deploy, an RPC URL of the network you want to deploy to, and the account you want to deploy with.
Your wallet must be funded with ETH on the Base Goerli testnet to cover the gas fees associated with the smart contract deployment. Otherwise, the deployment will fail.
To get testnet ETH, see the prerequisites.
To deploy the smart contract to the Base Goerli testnet, run the following command:
When prompted, enter the password that you set earlier, when you imported your wallet’s private key.
After running the command above, the contract will be deployed on the Base Goerli test network. You can view the deployment status and contract by using a block explorer.
To setup the paymaster and bundler for your project, you will need to visit the Biconomy Dashboard and complete the following steps.
Add and register a Paymaster by completing the following steps:
You should now have a registered Biconomy paymaster.
The API Key and Paymaster URL for the paymaster are provided under the Overview tab in the Biconomy Dashboard.
Set up and fund the paymaster’s gas tank by completing the following steps:
ETH should now be deposited into the gas tank for your paymaster. You can visit the Withdraw tab at a later time if you wish to withdraw the funds.
Set up and fund the paymaster’s gas tank by completing the following steps:
At the time of writing this tutorial, the Bundler service is still under development, however a Bundler URL is provided for testing out UserOperations on test networks. You can specify the chain ID 84531 to use the Bundler URL on Base Goerli testnet.
After you set up your paymaster and bundler from the Biconomy Dashboard, the next step is to create a Next.js project for your app’s frontend.
From the root of the myproject
directory of your project, create a new Next.js project by running the following command:
To use the paymaster and bundler that were setup from the Biconomy Dashboard, you will need to add a few dependencies to your Next.js project.
To install Biconomy as a dependency to your project, run the following command:
Creating Biconomy smart accounts requires a signer from an EIP-1193 provider. Biconomy works with a variety of different social login and embedded wallet onboarding solutions that provide access to a signer that can be used for creating smart accounts. In this tutorial, you will use Particle Network for user authentication and getting a smart account signer.
To install Particle Network as a dependency to your project, run the following command:
The main page (page.tsx
) of the Next.js project created when running the yarn create next-app
command contains a Home
component. This component comes with a lot of code that is unnecessary for this tutorial.
Replace the content of the page.tsx
file with the following simplified code:
To get started adding social login into the app using Particle Network, import and initialize the Biconomy Particle Auth module in the page.tsx
file as shown below:
You will need to sign up for a Particle Network account and replace the values of PARTICLE_PROJECT_ID
, PARTICLE_CLIENT_ID
, and PARTICLE_APP_ID
.
If you encounter issues with Paymaster integration, ensure your API keys are correct and your contract is whitelisted in the Biconomy dashboard.