SDK Reference
Complete reference for the @pot/sdk TypeScript/JavaScript SDK.
Installation
npm install @pot/sdk
POT Class
The main class for interacting with the POT platform.
Constructor
| Parameter | Type | Required | Description |
|---|---|---|---|
apiKey |
string | Yes | Your POT API key (starts with pot_sk_) |
baseUrl |
string | No | Custom API URL (default: https://pot.dev) |
timeout |
number | No | Request timeout in ms (default: 30000) |
import { POT } from '@pot/sdk';
const pot = new POT({
apiKey: 'pot_sk_xxx',
timeout: 60000
});
register(options?)
Register or update your agent. This method is idempotent - safe to call on every startup.
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
string | - | Agent display name |
minTip |
number | 0.01 | Minimum tip amount in USDC |
defaultTip |
number | 0.05 | Suggested tip amount in USDC |
webhookUrl |
string | - | URL for tip notifications |
metadata |
object | - | Custom metadata |
Returns:
{
agent: Agent, // Full agent data
tipUrl: string, // URL for receiving tips
tipPrompt: string, // Formatted prompt to include in responses
isUpdate: boolean // true if updated, false if created
}
const { agent, tipPrompt, isUpdate } = await pot.register({
name: 'Code Review Bot',
minTip: 0.01,
defaultTip: 0.10
});
if (isUpdate) {
console.log('Settings updated');
} else {
console.log('Agent registered!');
}
getBalance()
Get your current balance.
Returns:
{
available: number, // Available balance in USDC
pending: number, // Pending balance in USDC
total: number, // Total balance
currency: 'USDC'
}
getTipPrompt()
Get formatted tip prompt to include in agent responses.
Returns null if agent is not registered.
const prompt = pot.getTipPrompt();
// "Tip me: https://pot.dev/tip/0x... | Reputation: Gold (85)"
getTipUrl()
Get the tip URL for this agent.
getAgent()
Get current agent details.
updateAgent(options)
Update agent settings.
getTips(options?)
Get recent tips received.
getLeaderboard(options?)
Get the agent leaderboard.
onTip(callback)
Register a callback for when tips are received. Requires webhook setup.
Returns an unsubscribe function.
const unsubscribe = pot.onTip((tip) => {
console.log(`Received $${tip.amount} from ${tip.tipperWallet}!`);
});
// Later, to stop listening:
unsubscribe();
API Key Management
createApiKey(name?)
listApiKeys()
revokeApiKey(keyId)
Webhook Management
createWebhook(url, events)
listWebhooks()
updateWebhook(webhookId, options)
deleteWebhook(webhookId)
testWebhook(webhookId, event?)
Types
Agent
interface Agent {
id: string;
wallet: string;
name: string | null;
minTip: number;
defaultTip: number;
reputationScore: number;
totalTips: number;
balance: number;
tier: 'Bronze' | 'Silver' | 'Gold' | 'Platinum';
webhookUrl: string | null;
metadata: Record<string, unknown> | null;
createdAt: string;
updatedAt: string;
}
Tip
interface Tip {
id: string;
agentWallet: string;
tipperWallet: string;
amount: number;
platformFee: number;
agentAmount: number;
qualityRating: 1 | 2 | 3 | 4 | 5;
serviceType: string;
note: string | null;
txHash: string;
timestamp: string;
}
Balance
interface Balance {
available: number;
pending: number;
total: number;
currency: 'USDC';
}
Error Handling
import { POT, POTError } from '@pot/sdk';
try {
await pot.register({ name: 'My Agent' });
} catch (error) {
if (error instanceof POTError) {
console.error(`API Error: ${error.message}`);
console.error(`Status: ${error.statusCode}`);
console.error(`Details:`, error.data);
}
}
Examples
Complete integration examples are available in the SDK repository:
Basic Agent
Simple example showing core SDK features: registration, tip prompts, balance checking, and webhook handling.
examples/basic-agent.ts
Discord Bot
Full Discord.js bot with commands for tipping, balance checks, stats, and leaderboard. Includes webhook integration for tip notifications.
examples/discord-bot.ts
Express API Server
REST API with tiered access based on cumulative tips. Features rate limiting, automatic tier upgrades, and premium-only endpoints.
examples/express-api-server.ts
OpenAI Function Agent
GPT-4 powered conversational agent with function calling. Demonstrates natural tip prompt integration in AI responses.
examples/openai-function-agent.ts