/biconomy-client-sdk

Biconomy SDK is a plug & play toolkit for dApps to build transaction legos that enable a highly customised one-click experience for their users

Primary LanguageTypeScriptMIT LicenseMIT

Biconomy SDK

Biconomy SDK TypeScript Test Coverage

👋 Introduction

The Biconomy SDK is your all-in-one toolkit for building decentralized applications (dApps) with ERC4337 Account Abstraction and Smart Accounts. It is designed for seamless user experiences and offers non-custodial solutions for user onboarding, sending transactions (userOps), gas sponsorship and much more.

🛠️ Quickstart

import { createSmartAccountClient } from "@biconomy/account";

const smartAccount = await createSmartAccountClient({
  signer: viemWalletOrEthersSigner,
  bundlerUrl: "", // From dashboard.biconomy.io
  paymasterUrl: "", // From dashboard.biconomy.io
});

const { wait } = await smartAccount.sendTransaction({ to: "0x...", value: 1 });

const {
  receipt: { transactionHash },
  userOpHash,
} = await wait();

🌟 Features

  • ERC4337 Account Abstraction: Simplify user operations and gas payments.
  • Smart Accounts: Enhance user experience with modular smart accounts.
  • Paymaster Service: Enable third-party gas sponsorship.
  • Bundler Infrastructure: Ensure efficient and reliable transaction bundling.

For a step-by-step guide on integrating ERC4337 Account Abstraction and Smart Accounts into your dApp using the Biconomy SDK, refer to the official documentation. You can also start with Quick start here.

📚 Resources

⚙️ installation

npm i @biconomy/account

💼 Example Usages

Key Description
signer This signer will be used for signing userOps for any transactions you build. Will accept ethers.JsonRpcSigner as well as a viemWallet
paymasterUrl You can pass in a paymasterUrl necessary for sponsoring transactions (retrieved from the biconomy dashboard)
bundlerUrl You can pass in a bundlerUrl (retrieved from the biconomy dashboard) for sending transactions
import { createSmartAccountClient } from "@biconomy/account";
import { createWalletClient, http, createPublicClient } from "viem";
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
import { mainnet as chain } from "viem/chains";

const account = privateKeyToAccount(generatePrivateKey());
const signer = createWalletClient({ account, chain, transport: http() });

const smartAccount = await createSmartAccountClient({
  signer,
  bundlerUrl,
  paymasterUrl,
});
Key Description
oneOrManyTx Submit multiple or one transactions
userOpReceipt Returned information about your tx, receipts, userOpHashes etc
const oneOrManyTx = { to: "0x...", value: 1 };

const { wait } = await smartAccount.sendTransaction(oneOrManyTx, {
  mode: PaymasterMode.SPONSORED,
});

const {
  receipt: { transactionHash },
  userOpHash,
} = await wait();
Key Description
buildUseropDto Options for building a userOp
paymasterServiceData PaymasterOptions set in the buildUseropDto
import { encodeFunctionData, parseAbi } from "viem";

const encodedCall = encodeFunctionData({
  abi: parseAbi(["function safeMint(address to) public"]),
  functionName: "safeMint",
  args: ["0x..."],
});

const tx = {
  to: nftAddress,
  data: encodedCall,
};
const oneOrManyTx = [tx, tx]; // Mint twice
const paymasterServiceData = {
  mode: PaymasterMode.ERC20,
  preferredToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
};
const buildUseropDto = { paymasterServiceData };

const { wait } = await smartAccount.sendTransaction(oneOrManyTx, buildUseropDto);

const {
  receipt: { transactionHash },
  userOpHash,
} = await wait();

🤝 Contributing

Community contributions are welcome! For guidelines on contributing, please read our contribution guidelines.

📜 License

This project is licensed under the MIT License. See the LICENSE.md file for details.