Biconomy SDK
👋 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: "",
biconomyPaymasterApiKey: "",
});
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 |
biconomyPaymasterApiKey | You can pass in a biconomyPaymasterApiKey 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,
biconomyPaymasterApiKey,
});
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();
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];
const paymasterServiceData = {
mode: PaymasterMode.ERC20,
preferredToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
};
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.