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

haru

v1.0.0

Published

Minimal Haru SDK - Copy-paste package for balances and swaps

Readme

haru

Minimal Haru SDK package - Copy-paste ready for balances and swaps.

Installation

npm install haru

Quick Start

import { Haru } from 'haru'

// Initialize with your signed config
const haru = new Haru({
  config: {
    sig: '0x...',
    aid: 'your-app-id',
    ts: Date.now(),
    chains: ['ethereum', 'arbitrum'],
    primaryUsd: ['USDC']
  },
  apiBaseUrl: 'https://api.haru.so' // optional, has default
})

// Option 1: Pre-fetch hydrated tokens (recommended for multiple calls)
const tokens = await haru.getHydratedTokens()

// Get balances (uses cached tokens automatically)
const balances = await haru.balances('0xUserAddress...')
console.log('Total USD:', balances.totalUsd)
console.log('Spendable:', balances.spendable.usdTotal)
console.log('Invest:', balances.invest.usdTotal)

// Get swap quote (uses cached tokens automatically)
const quote = await haru.swapQuote({
  userAddress: '0xUserAddress...',
  fromSymbol: 'USDC',
  toSymbol: 'WETH',
  usdValue: '1000', // $1000 worth
  slippageBps: 50  // 0.5% slippage (optional)
})

console.log('Swap Rate:', quote.rate)
console.log('Input:', quote.input.usdValue, quote.input.currency)
console.log('Output:', quote.output.usdValue, quote.output.currency)

// Get Privy call list - one line!
const { calls, metadata } = haru.callList(quote) || {}

if (calls) {
  // Optional: Display metadata in UI
  if (metadata) {
    console.log(`Total steps: ${metadata.totalSteps}`)
    metadata.steps.forEach(step => {
      console.log(`${step.step}: ${step.name} - ${step.description}`)
    })
  }
  
  // Use with Privy - copy-paste → run
  // const { sendTransaction } = usePrivy()
  // const hash = await sendTransaction(calls, { sponsor: true })
}

API Reference

Haru Class

Constructor

new Haru(options: HaruOptions)

Options:

  • config (required): Signed config object
  • apiBaseUrl (optional): API base URL (defaults to https://api.haru.so)

Methods

getHydratedTokens()

Verify config and get hydrated tokens. Caches tokens internally for use in other calls.

const tokens = await haru.getHydratedTokens()

Returns: Promise<(HydratedToken | AbstractedToken)[]>

balances(userAddress: string)

Get user balances across all chains. Automatically uses cached hydrated tokens if available.

const balances = await haru.balances('0xUserAddress...')

Returns: Promise<CategorizedBalanceResult>

Response Structure:

{
  userAddress: string
  totalUsd: string
  spendable: {
    usdTotal: string
    balances: TokenBalanceDetail[]
  }
  invest: {
    usdTotal: string
    balances: TokenBalanceDetail[]
  }
}
swapQuote(params)

Get swap quote. Automatically uses cached hydrated tokens if available.

const quote = await haru.swapQuote({
  userAddress: '0xUserAddress...',
  fromSymbol: 'USDC',
  toSymbol: 'WETH',
  usdValue: '1000',
  slippageBps: 50 // optional, defaults to 50 (0.5%)
})

Parameters:

  • userAddress (required): User's Ethereum address
  • fromSymbol (required): Symbol of token to swap from (e.g., "USDC")
  • toSymbol (required): Symbol of token to swap to (e.g., "WETH")
  • usdValue (required): USD value to swap (e.g., "1000" for $1000)
  • slippageBps (optional): Slippage tolerance in basis points (e.g., 50 = 0.5%)

Returns: Promise<CleanSwapQuote>

Response Structure:

{
  quoteId?: string
  input: {
    usdValue: number
    currency: string
    rawAmount: string
    amountFormatted: string
  }
  output: {
    usdValue: number
    currency: string
    rawAmount: string
    amountFormatted: string
  }
  rate: number
  slippageBps: number
  haruFeeBps: number
  tokens: {
    in: QuoteTokenInfo
    out: QuoteTokenInfo
  }
  txData?: SwapQuoteTxData // Transaction steps including approve and swap
}

txData Structure:

{
  steps: SwapQuoteStep[]
}

// Each step:
{
  step: string        // e.g., "1/2", "2/2" - format is "current/total"
  stage: 'approve' | 'swap'
  kind: 'transaction'
  data: QuoteTransaction  // Transaction data ready to send to wallet
}
callList(quote)

Get Privy call list from swap quote. Returns bare-minimum shape that Privy's smart-wallet accepts.

const quote = await haru.swapQuote({ ... })

// One line - copy-paste → run
const { calls, metadata } = haru.callList(quote) || {}

if (calls) {
  // Optional: Display metadata in UI
  if (metadata) {
    console.log(`Total steps: ${metadata.totalSteps}`)
    // Total steps: 2
    
    console.log('Steps:', metadata.steps)
    // [
    //   { name: 'approve', step: '1/2', description: 'Approve USDC' },
    //   { name: 'swap', step: '2/2', description: 'Swap USDC for WETH' }
    // ]
  }
  
  // Use with Privy - bare minimum, Privy handles gas/chainId
  const { sendTransaction } = usePrivy()
  const hash = await sendTransaction(calls, { sponsor: true })
}

Parameters:

  • quote (required): Swap quote from swapQuote()

Returns: SwapCallList | null

Response Structure:

{
  calls: PrivyCall[]  // Bare-minimum shape for Privy
  metadata?: {        // Optional, for UI only
    totalSteps: number
    steps: Array<{
      name: 'approve' | 'swap'
      step: string        // "1/2", "2/2"
      description: string // "Approve USDC", "Swap USDC for WETH"
    }>
  }
}

PrivyCall Structure (bare-minimum):

{
  to: string
  data: string
  value: bigint  // BigInt (0n format) - Privy handles gas/chainId
}

Note: No gas, maxFeePerGas, chainId, etc. - Privy estimates and attaches them automatically.

steps(quote) (Legacy)

Get legacy steps format with full transaction data (gas fields, chainId). Use callList() instead for Privy integration.

const legacyData = haru.steps(quote)
// Returns: { totalSteps, steps, callList: PrivyTransaction[] }
clearCache()

Clear cached hydrated tokens. Forces refresh on next call that requires tokens.

haru.clearCache()
getConfig()

Get the current config.

const config = haru.getConfig()
setConfig(config: Config)

Update the config (automatically clears cached tokens).

haru.setConfig(newConfig)

Usage Patterns

Pattern 1: Pre-fetch tokens (Recommended)

const haru = new Haru({ config: myConfig })

// Pre-fetch tokens once
await haru.getHydratedTokens()

// All subsequent calls use cached tokens
const balances = await haru.balances(address)
const quote1 = await haru.swapQuote({ ... })
const quote2 = await haru.swapQuote({ ... })

Pattern 2: Auto-fetch tokens

const haru = new Haru({ config: myConfig })

// Tokens are fetched automatically on first call
const balances = await haru.balances(address) // Fetches tokens if needed
const quote = await haru.swapQuote({ ... }) // Uses cached tokens

Pattern 3: Custom API URL

const haru = new Haru({
  config: myConfig,
  apiBaseUrl: 'http://localhost:4000' // Use local API
})

Pattern 4: Executing Swap Transactions with Privy

import { Haru } from 'haru'
import { usePrivy } from '@privy-io/react-auth'

const haru = new Haru({ config: myConfig })
const quote = await haru.swapQuote({
  userAddress: '0x...',
  fromSymbol: 'USDC',
  toSymbol: 'WETH',
  usdValue: '1000'
})

// Get call list - one line!
const { calls, metadata } = haru.callList(quote) || {}

if (calls) {
  const { sendTransaction } = usePrivy()
  
  // Send batch transaction via Privy - copy-paste → run
  const hash = await sendTransaction(calls, { sponsor: true })
  
  console.log(`Transaction hash: ${hash}`)
  
  // Optional: Display progress in UI
  if (metadata) {
    console.log(`Executing ${metadata.totalSteps} steps:`)
    metadata.steps.forEach(step => {
      console.log(`  ${step.step}: ${step.description}`)
    })
  }
}

Features

  • Minimal: Only config + 3 main methods
  • No Service Code: Calls hosted APIs only
  • Automatic Caching: Hydrated tokens cached after first call
  • Type-Safe: Full TypeScript support
  • Copy-Paste Ready: Self-contained package

Requirements

  • Node.js 18+ or Bun
  • TypeScript 5.0+ (for TypeScript projects)

License

MIT