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

hak-mppx-hedera-plugin

v1.0.3

Published

Machine Payments Protocol (MPP) plugin for Hedera Agent Kit — charge and session payments with USDC

Downloads

486

Readme

hak-mppx-hedera-plugin

Hedera Agent Kit plugin for the Machine Payments Protocol. Enables AI agents to pay for 402-protected APIs using USDC on Hedera.

npm License: MIT

Install

npm install hak-mppx-hedera-plugin mppx-hedera mppx viem @hiero-ledger/sdk @hashgraph/hedera-agent-kit

Quick start

import { Client, AccountId, PrivateKey } from '@hiero-ledger/sdk';
import { HederaAgentAPI, ToolDiscovery } from '@hashgraph/hedera-agent-kit';
import { mppxHederaPlugin } from 'hak-mppx-hedera-plugin';

// 1. Create Hiero SDK Client
const client = Client.forTestnet();
client.setOperator(
  AccountId.fromString('0.0.12345'),
  PrivateKey.fromStringECDSA(process.env.HEDERA_PRIVATE_KEY),
);

// 2. Register plugin — privateKey in context is required for signing
const context = {
  network: 'testnet',
  privateKey: process.env.HEDERA_PRIVATE_KEY, // 0x-prefixed hex ECDSA key
};
const discovery = new ToolDiscovery([mppxHederaPlugin]);
const tools = discovery.getAllTools(context);

// 3. Create agent and call tools
const agent = new HederaAgentAPI(client, context, tools);

// One-shot charge: pay for weather data
const result = await agent.run('mppx_hedera_charge_fetch_tool', {
  url: 'https://api.example.com/weather',
  maxAmount: '100000', // max 0.10 USDC
});

// Session: open channel, make 100 fast calls, close
await agent.run('mppx_hedera_session_open_tool', { url: 'https://api.example.com', deposit: '0.10' });
await agent.run('mppx_hedera_session_fetch_tool', { url: 'https://api.example.com/data' });
await agent.run('mppx_hedera_session_close_tool', { url: 'https://api.example.com' });

Context

The plugin requires privateKey in the Agent Kit context because the Hiero SDK Client does not expose the raw private key after setOperator(). The plugin needs it for EIP-712 voucher signing (sessions) and native Hedera transaction signing (charges).

const context = {
  network: 'testnet',       // or 'mainnet'
  privateKey: '0x...',      // ECDSA secp256k1 private key (same key used in setOperator)
};

Tools

mppx_hedera_charge_fetch_tool

One-shot: call a 402-protected API, auto-pay with USDC, return the data.

Agent: "Get the weather from api.example.com/weather"
→ Tool fetches URL → gets 402 → pays 0.01 USDC → retries → returns weather data

Parameters: | Name | Type | Default | Description | |------|------|---------|-------------| | url | string | required | API endpoint URL | | method | GET | POST | GET | HTTP method | | body | string | — | Request body for POST | | maxAmount | string | 100000 | Max USDC in base units (6 decimals). 100000 = $0.10 |

mppx_hedera_session_open_tool

Open a payment channel — deposits USDC into an on-chain escrow contract.

Parameters: | Name | Type | Default | Description | |------|------|---------|-------------| | url | string | required | Server base URL | | deposit | string | 0.10 | USDC to deposit (human-readable) |

mppx_hedera_session_fetch_tool

Make an API call using an open session. Signs an off-chain voucher (sub-millisecond, no gas).

Parameters: | Name | Type | Default | Description | |------|------|---------|-------------| | url | string | required | URL to fetch | | method | GET | POST | GET | HTTP method | | body | string | — | Request body for POST |

mppx_hedera_session_close_tool

Settle and close a payment channel. Server settles on-chain, unused deposit is refunded.

Parameters: | Name | Type | Default | Description | |------|------|---------|-------------| | url | string | required | Server URL whose session to close |

How it works

Charge flow (one-shot):

Agent → GET /api → 402 + challenge → pay USDC (native Hedera tx) → retry with credential → 200 + data

Session flow (streaming):

Agent → session-open → deposit USDC into escrow (1 on-chain tx)
Agent → session-fetch × N → off-chain vouchers (<1ms each, no gas)
Agent → session-close → settle on-chain (1 tx), refund unused deposit

N requests = 2 on-chain transactions, regardless of N.

Live demo

node examples/agent-demo.mjs

Spins up a real mppx server, registers the plugin with HederaAgentAPI, and calls all 4 tools with real USDC on Hedera testnet. See examples/agent-demo.mjs.

Testing

# Unit + integration tests (56 tests, no network)
npm test

# Agent Kit integration (real HederaAgentAPI + real Hedera testnet)
node test/agent-kit.test.mjs

# Full E2E (real mppx server + real Hedera)
node test/e2e.test.mjs

Architecture

This plugin wraps mppx-hedera, the native MPP method for Hedera. The SDK provides:

  • Charge: native Hedera TransferTransaction with Attribution memo (challenge-bound, replay-proof)
  • Session: ERC-20 escrow channels with EIP-712 cumulative vouchers

License

MIT