Documentation
Plugins

Pimlico

The Pimlico plugin for BuildBear Sandboxes brings powerful Alto bundler functionality tailored for Account Abstraction (AA), along with seamless support for Pimlico’s Verifying and ERC20 Paymasters.

Overview

The Pimlico plugin for BuildBear Sandboxes brings powerful Alto bundler functionality tailored for Account Abstraction (AA), along with seamless support for Pimlico’s Verifying and ERC20 Paymasters. Written in TypeScript, Pimlico Alto is a high-performance, type-safe ERC-4337 bundler designed for reliability and efficiency.

This documentation provides step-by-step guidance on installing, configuring, and using the plugin to seamlessly integrate it into your development workflow. With support for standard JSON-RPC requests and compatibility with permissionless.js, this plugin ensures straightforward integration into Web3 applications, empowering developers to build and test with ease.

Features

  • Unlocked Faucets: Unlimited access to both native tokens and ERC-20 tokens for seamless development and testing.
  • Seamless Integration: Works effortlessly with BuildBear Sandboxes, enabling developers to test and experiment with Account Abstraction (AA) features in controlled environments.
  • Permissionless.js Support: High-level API for deploying and managing ERC-4337 smart accounts, bundlers, and paymasters, built on viem for modularity and extensibility.
  • Paymaster Support: Built-in support for two types of paymasters to abstract away gas fees:
    • Verifying Paymaster: A truly gasless paymaster that sponsors gas fees for users.
    • ERC20 Paymaster: Allows users to pay for gas fees using ERC-20 tokens.
  • JSON-RPC Support: Standard methods like eth_sendUserOperation, eth_estimateUserOperationGas, and more.

How to Use

Set Up Your Sandbox

  1. Create a new BuildBear sandbox or use an existing one.
  2. Navigate to the Plugin tab in your sandbox dashboard. Plugin Installation

Install the Pimlico Plugin

  1. Locate the Pimlico plugin from the list of available plugins.
  2. Click Install to add it to your sandbox environment.

Verify Installation

Ensure the plugin appears as installed in the marketplace or the Installed tab.

Prerequisites

  • Copy your BuildBear Sandbox RPC URL, which also serves as the Pimlico Client API endpoint.
  • Install all Pimlico dependencies i.e permissionless.js, viem.
const buildbearSandboxUrl = "https://rpc.buildbear.io/<YOUR-SANDBOX-ID>";

Configuring the BuildBear Sandbox Network

const BBSandboxNetwork = /*#__PURE__*/ defineChain({
  id: <SANDBOX_ID>, // Replace with your sandbox's chain ID
  name: "BuildBear x Polygon Mainnet Sandbox",
  nativeCurrency: { name: "MATIC", symbol: "MATIC", decimals: 18 },
  rpcUrls: { default: { http: [buildbearSandboxUrl] } },
  blockExplorers: {
    default: {
      name: "BuildBear Explorer",
      url: "https://explorer.buildbear.io/<YOUR-SANDBOX-ID>",
      apiUrl: "https://api.buildbear.io/<YOUR-SANDBOX-ID>/api",
    },
  },
});

Setting up Clients

Public Client

export const publicClient = createPublicClient({
  chain: BBSandboxNetwork,
  transport: http(buildbearSandboxUrl),
});

Pimlico Client

const pimlicoClient = createPimlicoClient({
  transport: http(buildbearSandboxUrl),
  entryPoint: { address: entryPoint07Address, version: "0.7" },
});

Smart Account & Smart Account Client

const signer = privateKeyToAccount(privateKey);
const account = await toSafeSmartAccount({
  client: publicClient,
  owners: [signer],
  entryPoint: { address: entryPoint07Address, version: "0.7" },
  version: "1.4.1",
});
const smartAccountClient = createSmartAccountClient({
  account,
  chain: BBSandboxNetwork,
  paymaster: pimlicoClient, // Optional
  bundlerTransport: http(buildbearSandboxUrl),
  userOperation: {
    estimateFeesPerGas: async () => (await pimlicoClient.getUserOperationGasPrice()).fast,
  },
});

Funding the Smart Account

Users must fund their wallets before sending transactions.

Native Token Faucet Example

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "buildbear_nativeFaucet",
  "params": [{ "address": "0xYourAddress", "balance": "100" }]
}

ERC20 Token Faucet Example

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "buildbear_ERC20Faucet",
  "params": [{ "address": "0xYourAddress", "balance": "100", "token": "0xTokenAddress" }]
}

Sending a Transaction with a Paymaster

Verifying Paymaster (Gasless Transactions)

const txHash = await smartAccountClient.sendUserOperation({
  account,
  calls: [
    {
      to: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
      value: parseEther("1"),
    },
  ],
});

ERC20 Paymaster (Users Pay with ERC-20 Tokens)

const txHash = await smartAccountClient.sendUserOperation({
  account,
  calls: [
    {
      to: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063", // Payment token for gas
      abi: parseAbi(["function approve(address,uint)"]),
      functionName: "approve",
      args: ["0xPaymasterAddress", parseEther("1")],
    },
    {
      to: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
      value: parseEther("1"),
    },
  ],
  paymasterContext: {
    token: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063", // DAI
  },
});

Conclusion

Install the Pimlico plugin in your BuildBear Sandbox to easily test and implement Account Abstraction (AA) features for your smart contracts, just as you would on Mainnet or any supported network.