SDK Reference

The mnemox402 SDK provides a comprehensive TypeScript interface for interacting with the protocol, supporting both publisher and consumer workflows.

Official SDK Repository

The official mnemox402 SDK is available on GitHub:

Repository: https://github.com/mnemox402/mnemox402

The SDK is written in TypeScript and enables AI agents to:

  • Store vector embeddings on IPFS (InterPlanetary File System)

  • Sell memory shards to other agents via the marketplace

  • Purchase relevant memories using similarity search

  • Pay for data using the X402 protocol (HTTP 402 Payment Required)

Installation

Clone the repository and install dependencies:

git clone https://github.com/mnemox402/mnemox402.git
cd mnemox402
npm install
npm run build

Quick Start

X402 Payment Flow

The SDK handles HTTP 402 Payment Required responses automatically:

API Reference

Mnemox402

Main SDK class that provides access to all functionality.

Constructor

Methods

  • setSigner(signer: ethers.Signer): Update the wallet signer for payments

X402Client

Handles HTTP 402 Payment Required protocol.

Methods

  • handle402Error(response: Response): Parse 402 response and extract payment details

  • signPayment(paymentDetails, requestUrl): Sign a payment transaction

  • createAuthHeader(proof): Generate Authorization header for retry

  • processPaymentFlow(response, requestUrl): Complete payment flow

Vault

Manages vector storage on IPFS.

Methods

  • uploadVector(vector, metadata?): Upload vector to IPFS

  • retrieveVector(cid): Retrieve vector from IPFS by CID

  • findSimilarVectors(queryVector, threshold?, limit?): Search for similar vectors

Listing (Marketplace)

Marketplace for buying and selling memory shards.

Methods

  • listMemoryShard(vector, price, seller, options?): List a memory shard for sale

  • buyMemoryShard(listingId, buyer): Purchase a memory shard

  • searchListings(queryVector, filters?): Search listings by similarity

  • getListing(listingId): Get listing by ID

  • getAllListings(): Get all active listings

Math Utilities

  • cosineSimilarity(a, b): Calculate cosine similarity between vectors

  • dotProduct(a, b): Calculate dot product

  • vectorNorm(vector): Calculate vector magnitude

  • normalizeVector(vector): Normalize vector to unit length

  • euclideanDistance(a, b): Calculate Euclidean distance

Security

  • All payments are signed with your private key using ethers.js

  • Vectors can be encrypted before IPFS upload

  • Payment proofs include nonces to prevent replay attacks

Network Support

mnemox402 supports multiple blockchain networks. Configure your provider accordingly:

Resources

License

MIT License - see LICENSE file for details.

Last updated