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

4.2.12 • Public • Published

Biconomy License MIT codecov

SDK 🚀

Open in GitHub Codespaces

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.

📚 Table of Contents

🛠️ Quickstart

Installation

  1. Add the package and install dependencies:
bun add @biconomy/account viem
  1. Install dependencies:
bun i
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 },
  success,
} = await wait();

Documentation and Resources

For a comprehensive understanding of our project and to contribute effectively, please refer to the following resources:

💼 Examples

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,
  success,
} = await wait();
Key Description
buildUseropDto Options for building a userOp
paymasterServiceData PaymasterOptions set in the buildUseropDto
import { encodeFunctionData, parseAbi } from "viem";
const preferredToken = "0x747A4168DB14F57871fa8cda8B5455D8C2a8e90a"; // USDC

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

const buildUseropDto = {
  paymasterServiceData: {
    mode: PaymasterMode.ERC20,
    preferredToken,
  },
};

const { wait } = await smartAccount.sendTransaction(
  [tx, tx] /* Mint twice */,
  buildUseropDto
);

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

License

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

Connect with Biconomy 🍊

Website Telegram Twitter LinkedIn Discord YouTube GitHub

Package Sidebar

Install

npm i @biconomy-devx/account

Homepage

biconomy.io

Weekly Downloads

597

Version

4.2.12

License

MIT

Unpacked Size

1.21 MB

Total Files

335

Last publish

Collaborators

  • joepegler
  • vgabriel45
  • aboudjem
  • livingrock7
  • sachin.tomar