Boop SDK
The Boop SDK is a TypeScript library for interaction with the Boop account abstraction stack.
It provides easy type-safe access to the Boop Submitter's REST API as well as useful functions when working with boops.
Installation
To install the Boop SDK in your project, use your preferred package manager:
npm install @happy.tech/boop-sdk
Example
Here's an example that shows you how to create an account and send a transaction using the SDK. Refer to the API reference for more details.
We use the viem library to provide auxiliary functions.
import { BoopClient, Onchain } from "@happy.tech/boop-sdk"
import type { BoopWithOptionalFields } from "@happy.tech/boop-sdk"
import { encodeFunctionData, zeroAddress } from "viem"
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"
import { happychainTestnet } from "viem/chains"
import { parseAbi } from "viem/utils"
const ownerPrivateKey = generatePrivateKey()
const owner = privateKeyToAccount(ownerPrivateKey)
const boopClient = new BoopClient({
submitterUrl: "https://submitter.happy.tech",
rpcUrl: "https://rpc.testnet.happy.tech/http",
})
const { address, error: error1 }
= await boopClient.createAccount({ owner: owner.publicKey })
if (address) {
console.log("Your account address is: ", address)
} else {
throw Error("Could not create account: " + error1)
}
const unsignedBoop = {
// mock ERC20 contract deployed on HappyChain Sepolia
dest: "0x02206fac6469b2f59fc2bb9d3bc181fbe703f8b7",
account: address,
nonceTrack: 0n,
nonceValue: 0n, // first one!
value: 0n,
payer: zeroAddress, // the HappyChain submitter will pay for it
callData: encodeFunctionData({
abi: parseAbi(["function mint(address _account, uint256 _amount)"]),
functionName: "mint",
args: [address, 100n],
}),
validatorData: "0x",
extraData: "0x",
} satisfies BoopWithOptionalFields
const signature = await owner.sign({
hash: boopClient.computeBoopHash(happychainTestnet.id, unsignedBoop)
})
const boop = { ...unsignedBoop, validatorData: signature }
// No need to estimate gas or simulate — the submitter takes care of it!
const { receipt, error: error2 } = await boopClient.execute({ boop })
if (receipt?.status === Onchain.Success) {
console.log(
"You are now 100 MockTokenA richer! " +
"Here's a receipt to prove it: ", receipt)
} else {
throw Error("Could not execute boop: " + error2)
}
API Overview
See the API reference for a full reference.
The most important part of the API is the BoopClient
. You instantiate it with a submitter URL and a RPC URL (the RPC
URL requirement will be removed soon), and then you can invoke its methods to make calls to the
submitter's REST API.
The following methods are available, refer to the [submitter] and [REST API] documentation pages for more details:
The SDK also exports all the types and status codes necessary to interpret the return values of these methods.
Additionally, the package exposes utility methods to manipulate boops, namely:
The purpose of these various methods can be understood from reading the rest of the docs (if in doubt, use the search box!).
updateBoopFromSimulation
deserves a special explanation: it is used for the flow where you simulate a transaction
before submitting it (either via execute
or submit
). This flow is mandatory for self-payout boops, where you have to
sign over the fees and gas limits — which you can retrieve via simulate
.
You can then pass in the (successful) simulation results and the simulated boop into the function to obtain an updated version of the boop suitable for signing and submitting.