npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@hazbase/smartwallet

v0.0.3

Published

A lightweight helper to work with ERC‑4337 Smart Accounts using minimal code

Readme

@hazbase/smartwallet

npm version License

Overview

@hazbase/smartwallet is a lightweight helper to work with ERC‑4337 Smart Accounts using minimal code.

Highlights

  • Chain‑aware SmartWallet.connect(...) that auto‑fills defaults (Factory / EntryPoint / Provider)
  • Fluent UserOperation builder: execute(...).withGasLimits(...).buildAndSend()
  • Bundler integration with X-Api-Key header and path‑based routing (https://<host>/<chainId>)
  • Optional Paymaster middleware to inject paymasterAndData
  • Signer adapter: asSigner() exposes an ethers‑compatible AbstractSigner

Requirements

  • Node.js: 18+
  • ethers: v6 (uses JsonRpcProvider and FetchRequest)
  • Bundler must implement eth_sendUserOperation and eth_getUserOperationReceipt (and optionally route by /chainId).
  • (Optional) Paymaster API that accepts POST { userOp, chainId } and returns { data: { paymasterAndData } }.

Installation

npm i @hazbase/smartwallet ethers

Configuration

This package expects explicit configuration in code (it does not read .env).

  • bundlerUrl: e.g., https://bundler.example.com (the library appends /{chainId} internally)
  • apiKey: value for the X-Api-Key header sent to your bundler
  • owner: an ethers Signer with a connected Provider
  • entryPoint / factory / provider: resolved by connect() per chain; throws if unsupported

Quick start

1) Minimal call via UserOperation

import { ethers } from "ethers";
import { SmartWallet } from "@hazbase/smartwallet";

async function main() {
  // 1) Prepare owner signer with a provider
  const provider = new ethers.JsonRpcProvider(process.env.RPC_URL!);
  const owner = new ethers.Wallet(process.env.OWNER_KEY!, provider);

  // 2) Connect SmartWallet (factory/entryPoint/provider are auto-filled by chainId)
  const sw = await SmartWallet.connect({
    owner,
    factory    : "0x0",                      // placeholder (auto-resolved)
    entryPoint : "0x0",                      // placeholder (auto-resolved)
    bundlerUrl : "https://bundler.example.com",
    apiKey     : process.env.BUNDLER_API_KEY || "",
    usePaymaster: false
  });

  // 3) Send a 0 ETH call (or set a real value)
  const to = "0x000000000000000000000000000000000000dEaD";
  const value = 0n;
  const data = "0x";                         // empty calldata

  // Build & send → returns tx hash after inclusion
  const txHash = await sw.execute(to, value, data)
                          .withGasLimits({ call: 200_000n })
                          .buildAndSend();

  console.log("txHash:", txHash);
}

main().catch(console.error);

2) ERC‑20 transfer

import { SmartWallet } from "@hazbase/smartwallet";

async function transferErc20(sw: SmartWallet, token: string, to: string, amount: bigint) {
  const txHash = await sw.transferERC20(token, to, amount).buildAndSend();
  console.log("erc20 transfer txHash:", txHash);
}

3) Gas‑sponsored flow with a Paymaster (optional)

import { SmartWallet, paymasterMiddleware } from "@hazbase/smartwallet";

const chainId = 11155111; // sepolia
const sw = await SmartWallet.connect({
  owner,
  factory    : "0x0",
  entryPoint : "0x0",
  bundlerUrl : "https://bundler.example.com",
  apiKey     : process.env.BUNDLER_API_KEY || "",
  usePaymaster: true,                         // enable default
  middlewares: [
    paymasterMiddleware("https://paymaster.example.com", chainId)
  ]
});

4) Use as an ethers Signer

import { ethers } from "ethers";

const signer = sw.asSigner(); // AbstractSigner-compatible

const resp = await signer.sendTransaction({
  to: "0x000000000000000000000000000000000000dEaD",
  value: 0n,
  data: "0x"
});

console.log("userOp hash:", resp.hash);
const receipt = await resp.wait(1); // internally polls eth_getUserOperationReceipt
console.log("included tx:", receipt.transactionHash);

Routing & Headers (Bundler)

  • The library requests bundlerUrl + "/" + chainId:
    • e.g., https://bundler.example.com/11155111
    • e.g., https://bundler.example.com/80002
  • If apiKey is provided, requests include X-Api-Key: <your-key> automatically.

Public API (selected)

SmartWallet.connect(cfg: SmartWalletConfig): Promise<SmartWallet>

  • Role: Construct a wallet with chain defaults (Factory / EntryPoint / Provider), route bundler by /{chainId}, and attach middlewares.
  • Args
    • owner: Signer (must have Provider)
    • bundlerUrl: string (e.g., https://bundler.example.com)
    • apiKey?: string (adds X-Api-Key header)
    • usePaymaster?: boolean / middlewares?: Middleware[]
    • factory? / entryPoint? / provider? (optional; will be auto‑resolved per chain)
  • Returns: SmartWallet

address(): Promise<Address>

  • Role: Predict (or return) the SmartAccount address via factory.predictAddress(owner, salt).
  • Returns: Address

isDeployed(): Promise<boolean>

  • Role: Check if the account is deployed using factory.usedKey(keccak(owner,salt)).
  • Returns: boolean

createAccount(): Promise<TransactionReceipt>

  • Role: Deploy the account via factory.createAccount(owner,salt).
  • Returns: Deployment tx receipt
  • Throws: If already deployed

deposit(amount): Promise<TransactionReceipt>

  • Role: Deposit native token (ETH) to EntryPoint for this account (depositTo(address)).
  • Args: bigint | string | number (string/number parsed via parseEther)
  • Returns: Tx receipt

getDeposit(): Promise<bigint>

  • Role: Read EntryPoint deposit (uses balanceOf, falls back to deposits for older EP).
  • Returns: wei balance

withdraw(to, amount): Promise<Hash>

  • Role: Execute EntryPoint.withdrawTo(to, amount) via a userOp.
  • Returns: L1 tx hash after inclusion

getNonce(key=0n): Promise<bigint>

  • Role: Read EntryPoint.getNonce(account, key) (defaults to key=0).
  • Returns: nonce

execute(to, value, data): UserOpBuilder

  • Role: Compose SmartAccount.execute(to, value, data) userOp.
  • Returns: UserOpBuilder (withGasLimits().build().buildAndSend())

transferERC20(token, to, amount): UserOpBuilder

  • Role: Shortcut to call ERC‑20 transfer(to, amount) via userOp.

sign(uo): Promise<UserOperation>

  • Role: Run beforeSign middlewares → EntryPoint.getUserOpHash(uo)owner.signMessage.
  • Returns: Signed UserOperation (signature populated)

send(uo): Promise<Hash>

  • Role: sign() → Bundler eth_sendUserOperationwait()afterSend middlewares.
  • Returns: L1 tx hash once included

wait(hash, intervalMs=500, maxAttempts=30): Promise<Log>

  • Role: Poll eth_getUserOperationReceipt until present or timeout.
  • Returns: Inclusion log (has transactionHash)
  • Throws: If not found within the limit

asSigner(provider?): SmartAccountSigner

  • Role: Return an ethers AbstractSigner to integrate with existing tooling.

getOwner(): Signer

  • Role: Expose the underlying EOA signer.

Troubleshooting

  • AA23 reverted: deposit fail
    The account or Paymaster deposit is insufficient. Top up with depositTo(...).
  • invalid paymaster signature
    The paymasterAndData signature scheme or signer does not match the Paymaster contract.
  • UserOp receipt not found
    Increase wait() attempts or ensure the Bundler retains receipts long enough.
  • CORS (browser usage)
    Allow Access-Control-Allow-* headers on your HTTPS reverse proxy.

Tips

  • The library automatically sets X-Api-Key when apiKey is provided.
  • L1 gas is ultimately paid by the Account deposit or the Paymaster deposit.

License

Apache-2.0