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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@b402ai/sdk

v0.2.0

Published

Private on-chain execution for agents. Anonymous wallets, gasless transactions, ZK-proven privacy on Base.

Downloads

274

Readme

@b402ai/sdk

Private on-chain execution for agents on Base.

One private key. Anonymous smart wallet. Gasless transactions. ZK-proven privacy.

Install

npm install @b402ai/sdk

Quick Start

import { B402 } from '@b402ai/sdk'

const b402 = new B402({ privateKey: process.env.WORKER_PRIVATE_KEY })

// Shield — move USDC into privacy pool (breaks on-chain link)
await b402.shield({ token: 'USDC', amount: '100' })

// Private swap — fully private, funded from pool
await b402.privateSwap({ from: 'USDC', to: 'WETH', amount: '10' })

// Earn yield — deposit into Morpho vault
await b402.lend({ token: 'USDC', amount: '50', vault: 'steakhouse' })

// Check everything
const status = await b402.status()

The only required config is privateKey. The SDK derives an anonymous smart wallet, and the b402 facilitator sponsors all gas.

How It Works

Your Key → Incognito EOA → Anonymous Smart Wallet → DeFi
              (derived)        (gasless, untraceable)

Shield deposits tokens into the Railgun privacy pool. Unshield generates a client-side ZK proof and moves tokens to your anonymous smart wallet — no on-chain link between source and destination. From there, lend, swap, and transact — all gasless through the facilitator.

Private operations (privateSwap, privateLend, etc.) go a step further: they unshield directly into a RelayAdapt contract, execute DeFi calls, and shield the output — all in one atomic transaction. On-chain observers see the RelayAdapt contract, never your wallet.

Configuration

const b402 = new B402({
  privateKey: '0x...',              // Required. Derives anonymous wallet.
  zeroXApiKey: '...',               // Optional. Required for swap() only.
  rpcUrl: 'https://...',            // Optional. Default: public Base RPC.
  facilitatorUrl: 'https://...',    // Optional. Default: production facilitator.
  onProgress: (event) => { ... },   // Optional. Step-by-step progress updates.
})

API

Privacy Pool

b402.shield({ token, amount }) — Enter privacy pool

Moves tokens from the smart wallet into the Railgun privacy pool. After shielding, the funding source is untraceable.

const { txHash, indexed } = await b402.shield({ token: 'USDC', amount: '100' })

b402.shieldFromEOA({ token, amount }) — Shield from master EOA

Gasless shield directly from your master EOA using EIP-3009 transferWithAuthorization. Useful for bootstrapping.

await b402.shieldFromEOA({ token: 'USDC', amount: '100' })

b402.unshield({ token, amount }) — Exit privacy pool

Generates a ZK proof (Groth16) client-side and withdraws to the anonymous smart wallet. Supports partial unshields with automatic change note management.

const { txHash, proofTimeSeconds } = await b402.unshield({ token: 'USDC', amount: '50' })
// Pass amount: 'all' to drain all UTXOs

b402.consolidate({ token? }) — Merge UTXOs

Merges fragmented UTXOs into one. Auto-runs before private operations when needed.

Yield (Morpho Vaults)

b402.lend({ token, amount, vault? }) — Deposit into vault

await b402.lend({ token: 'USDC', amount: '100', vault: 'steakhouse' })

| Vault | Name | APY | |-------|------|-----| | steakhouse | Steakhouse USDC | 3-4% | | moonwell | Moonwell Flagship USDC | 3-4% | | gauntlet | Gauntlet USDC Prime | 3-4% | | steakhouse-hy | Steakhouse High Yield | 3-4% |

b402.redeem({ vault?, shares? }) — Withdraw from vault

const { assetsReceived } = await b402.redeem({ vault: 'steakhouse' })

b402.rebalance(minApyDiff?) — Move to highest-yield source

Compares all yield sources (Morpho vaults + Aerodrome LP) and moves capital if APY difference exceeds threshold.

Swaps

b402.swap({ from, to, amount }) — Token swap via 0x

Requires zeroXApiKey in config.

await b402.swap({ from: 'USDC', to: 'WETH', amount: '10' })

Aerodrome LP

b402.addLiquidity({ pool?, amount }) — Add LP

Single-token input (USDC) — SDK splits and swaps half automatically. LP tokens are staked in gauge to earn AERO.

await b402.addLiquidity({ pool: 'weth-usdc', amount: '50' })

b402.removeLiquidity({ pool? }) — Remove LP + claim rewards

const { amountWETH, amountUSDC } = await b402.removeLiquidity({ pool: 'weth-usdc' })

b402.claimRewards({ pool? }) — Claim AERO only

Private Operations (via RelayAdapt)

All private operations execute atomically through Railgun's RelayAdapt contract. On-chain observers see the contract, never your wallet.

b402.privateSwap({ from, to, amount }) — Private token swap

await b402.privateSwap({ from: 'USDC', to: 'WETH', amount: '0.5' })

b402.privateLend({ token?, amount, vault? }) — Private vault deposit

await b402.privateLend({ token: 'USDC', amount: '0.5', vault: 'steakhouse' })

b402.privateRedeem({ vault? }) — Private vault withdrawal

Perpetuals

b402.synfuturesTrade({ instrument, side, notional, margin }) — Open perp (SynFutures V3)

await b402.synfuturesTrade({ instrument: 'BTC', side: 'long', notional: '20', margin: '10' })

b402.synfuturesClose({ instrument }) — Close perp position

b402.privateSynfuturesTrade(...) — Open perp from privacy pool

Speed Markets (Thales)

b402.speedMarket({ asset, direction, amount, duration? }) — Binary option

await b402.speedMarket({ asset: 'ETH', direction: 'up', amount: '10', duration: '10m' })

b402.privateSpeedMarket(...) — Binary option from privacy pool

General

b402.transact(calls) — Arbitrary smart contract calls

Execute any calldata through the anonymous smart wallet. Gasless.

await b402.transact([{ to: '0x...', value: '0', data: '0x...' }])

b402.status() — Wallet state

const s = await b402.status()
// s.smartWallet       — anonymous wallet address
// s.balances          — [{ token: 'USDC', balance: '50.0' }]
// s.shieldedBalances  — [{ token: 'USDC', balance: '25.0' }]
// s.positions         — [{ vault: 'steakhouse', assets: '100.5 USDC', apyEstimate: '3.5%' }]
// s.lpPositions       — [{ pool: 'weth-usdc', usdValue: '500', apyEstimate: '7.6%' }]

Static Helpers

B402.vaults          // available yield vaults
B402.tokens          // supported tokens (USDC, WETH, DAI, AERO)
B402.pools           // Aerodrome LP pools
B402.perpMarkets     // SynFutures instruments
B402.speedMarketAssets // ['ETH', 'BTC']

Supported Tokens

| Token | Address | |-------|---------| | USDC | 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 | | WETH | 0x4200000000000000000000000000000000000006 | | DAI | 0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb | | AERO | 0x940181a94A35A4569E4529A3CDfB74e38FD98631 |

For Agents

Every method takes plain strings and returns plain objects. No ABI encoding, no gas estimation, no nonce management.

const b402 = new B402({ privateKey: agentKey })
await b402.shield({ token: 'USDC', amount: '1000' })
await b402.privateLend({ token: 'USDC', amount: '1000', vault: 'steakhouse' })

For tool-calling agents, each method maps directly to a tool:

{
  "name": "b402_shield",
  "description": "Move tokens into Railgun privacy pool",
  "parameters": {
    "token": { "type": "string", "enum": ["USDC", "WETH", "DAI", "AERO"] },
    "amount": { "type": "string" }
  }
}

Error Handling

All methods throw on failure:

try {
  await b402.lend({ token: 'USDC', amount: '100' })
} catch (err) {
  console.error(err.message)
}

| Error | Cause | |-------|-------| | privateKey or signer is required | Missing private key or signer | | zeroXApiKey required for swaps | Called swap() without API key | | Unknown token: X | Token not supported | | No shares in vault | Called redeem() on empty vault | | No shielded balance | Called unshield/private op without shielding first | | Facilitator verify failed | Invalid UserOp or facilitator issue |

Networks

| Chain | ID | Railgun Contract | Supported Operations | |-------|-----|-----------------|---------------------| | Base | 8453 | 0x2611...4fbE85 | All (shield, unshield, swap, lend, LP, perps, private ops) | | BSC | 56 | 0x9dB0...b04fE | Privacy layer (shield, unshield, transact) |

Default: Base. Set B402_CHAIN=bsc env var for BSC.

All operations use real tokens.

License

MIT