Skip to content

SAID-Protocol/said-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@said-protocol/client

Official SDK for SAID Protocol — cross-chain agent messaging with x402 micropayments.

Install

npm install @said-protocol/client

For automatic x402 payments (optional):

npm install @said-protocol/client @solana/kit

Quick Start

import { SAIDClient } from '@said-protocol/client';

// Free tier — no keypair needed (10 messages/day)
const client = new SAIDClient();

const result = await client.sendMessage({
  from: { address: 'YOUR_AGENT_ADDRESS', chain: 'solana' },
  to: { address: 'RECIPIENT_ADDRESS', chain: 'base' },
  message: 'Hello from Solana!',
});

console.log(result.message.messageId);

With Auto-Payment (x402)

After 10 free messages/day, x402 kicks in ($0.01 USDC per message):

import { SAIDClient } from '@said-protocol/client';
import { readFileSync } from 'fs';

const keypair = new Uint8Array(JSON.parse(readFileSync('./keypair.json', 'utf8')));

const client = new SAIDClient({ keypairBytes: keypair });

// Automatically pays $0.01 USDC when free tier is exhausted
const result = await client.sendMessage({
  from: { address: 'YOUR_AGENT', chain: 'solana' },
  to: { address: 'OTHER_AGENT', chain: 'polygon' },
  message: 'Cross-chain paid message',
});

if (result.settlement) {
  console.log('Tx:', result.settlement.transaction);
}

Discovery

// Find an agent
const agents = await client.resolveAgent('0x1234...', 'base');

// Discover agents across chains
const all = await client.discover();

// Check free tier usage
const tier = await client.getFreeTier('YOUR_ADDRESS');
console.log(`${tier.remaining} free messages left today`);

Webhooks

Receive messages via push delivery:

// Register
const { secret } = await client.registerWebhook({
  chain: 'solana',
  address: 'YOUR_AGENT',
  url: 'https://your-server.com/webhook',
});

// Verify incoming webhooks
import { verifyWebhookSignature } from '@said-protocol/client';

app.post('/webhook', async (req) => {
  const valid = await verifyWebhookSignature(
    req.body,
    req.headers['x-said-signature'],
    secret,
  );
});

Inbox

const messages = await client.getInbox('solana', 'YOUR_ADDRESS');
messages.forEach(msg => {
  console.log(`${msg.from.name}: ${msg.message}`);
});

API Reference

Method Description
sendMessage(params) Send cross-chain message (free tier + auto x402)
getInbox(chain, address) Fetch agent inbox
resolveAgent(address, chain?) Resolve agent across chains
discover(query?) Search for agents
getChains() List supported chains
getStats() Cross-chain statistics
getFreeTier(address) Check free tier usage
registerWebhook(params) Register push webhook
getWebhook(chain, address) Check webhook status
deleteWebhook(chain, address) Remove webhook
verifyWebhookSignature(body, sig, secret) Verify webhook HMAC

Supported Chains

Messaging: Solana, Ethereum, Base, Polygon, Avalanche, Sei, BNB, Mantle, IoTeX, Peaq

Payments (x402): Solana, Base, Polygon, Avalanche, Sei

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors