Comment on page

Account Abstraction: Biconomy

What is Biconomy?

Biconomy SDK brings blockchain-agnostic, web2-like experiences to your dApp in a non-custodial manner. Built on top of the ERC4337 solution, it offers a wide range of solutions, from user onboarding to sustained engagement, enhancing the overall user experience within your dApp. By leveraging modularity, the SDK offers enhanced customization, security, and functionality. This SDK operates in a non-custodial manner, providing a unified solution that combines simplicity and functionality in the realm of decentralized applications.

Advantages

  • Easy User Onboarding: Simplifies the onboarding process for new users through social login, account creation, and recovery options, seamlessly integrating web2 users into your dApp.
  • Fiat On Ramp: Allows your users to easily and reliably buy or sell cryptocurrencies within your dApp, facilitating the transition between traditional and blockchain-based assets
  • Gasless Transactions: Sponsors gas fees for user interactions, making them as simple as web2 transactions, and improving the overall user experience.
  • Paying Gas Fees In ERC20 Tokens: Enable users to utilize any ERC20 asset in their wallet to pay for gas fees, offering flexibility and convenience.
  • Custom Transaction Bundling: Empower developers to build methods for transaction batching, allowing users to execute multiple actions in a single transaction, even across multiple chains. For example, users can approve and deposit in the same transaction without altering anything in the dApp smart contracts.

Integrating Biconomy

Environment Setup

git clone https://github.com/bcnmy/quickstart.git
yarn install
yarn dev
After running these two commands you should see the printed statement “Hello World!” in your terminal. Any changes made to the index.ts file in the src directory should now automatically run in your terminal upon save.
Then you'll need to set up a .env file in the root of your project, this will need a Private Key of any Externally Owned Account (EOA) you would like to serve as the owner of the smart account we create (this is a private key you can retrieve from wallets like MetaMask, TrustWallet, Coinbase Wallet, all of which have tutorials on exporting Private Keys).
PRIVATE_KEY = '<PRIVATE KEY>'
Let’s give our script the ability to access this environment variable. Delete the console log inside of src/index.ts and replace it with the code below. All of our work for the remainder of the tutorial will be in this file.
import { config } from "dotenv"
config()
Now your code is configured to access the environment variable as needed!

Overview

Integrating Biconomy is easy. Here's an abbreviated overview of what you need to do to get started:
import { config } from "dotenv"
import { IBundler, Bundler } from '@biconomy/bundler'
import { ChainId } from "@biconomy/core-types";
import { BiconomySmartAccount, BiconomySmartAccountConfig, DEFAULT_ENTRYPOINT_ADDRESS } from "@biconomy/account"
import { Wallet, providers, ethers } from 'ethers'
config()
const provider = new providers.JsonRpcProvider('<YOUR_CALDERA_RPC_URL>')
const wallet = new Wallet(process.env.PRIVATE_KEY || "", provider);
const bundler: IBundler = new Bundler({
bundlerUrl: 'https://bundler.biconomy.io/api/v2/80001/nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44,
chainId: '<YOUR_CALDERA_CHAIN_ID>',
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
})
const biconomySmartAccountConfig: BiconomySmartAccountConfig = {
signer: wallet,
chainId: '<YOUR_CALDERA_CHAIN_ID>',
bundler: bundler
}
// We create a new instance of the account using the BiconomySmartAccount class and passing it the configuration.
async function createAccount() {
const biconomyAccount = new BiconomySmartAccount(biconomySmartAccountConfig)
const biconomySmartAccount = await biconomyAccount.init()
console.log("owner: ", biconomySmartAccount.owner)
console.log("address: ", await biconomySmartAccount.getSmartAccountAddress())
return biconomyAccount
}
// Before executing a tx, once you have a smart account address you need to fund it with some test network tokens!
// So, make sure to request tokens from your Caldera Faucet!
async function createTransaction() {
console.log("creating account")
const smartAccount = await createAccount();
const transaction = {
to: '<ADDRESS THIS TX IS DIRECTED TOWARDS>',
data: '0x',
value: ethers.utils.parseEther('0.1'),
}
const userOp = await smartAccount.buildUserOp([transaction])
userOp.paymasterAndData = "0x"
const userOpResponse = await smartAccount.sendUserOp(userOp)
const transactionDetail = await userOpResponse.wait()
console.log("transaction detail below")
console.log(transactionDetail)
}
createTransaction()

Learn more: