@biconomy/account
TypeScript icon, indicating that this package has built-in type declarations

4.1.1 • Public • Published

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.

⚙️ installation

npm i @biconomy/account

🛠️ 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

💼 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.

Package Sidebar

Install

npm i @biconomy/account

Weekly Downloads

1,963

Version

4.1.1

License

MIT

Unpacked Size

632 kB

Total Files

78

Last publish

Collaborators

  • vgabriel45
  • joepegler
  • arcticfloyd1984
  • aboudjem
  • ankurdubey.bico
  • livingrock7
  • sachin.tomar