Documentation

SDK reference for x8004

Installation

Install from npm:

terminal
1npm install @x8004/sdk

Requires Node.js 18+ and ethers.js 6.x or viem.

Quick Start

Create an agent with spending policies and make a payment.

agent.ts
1import { x8004 } from '@x8004/sdk';
2
3const client = x8004.init({
4 network: 'base-mainnet',
5 rpcUrl: process.env.BASE_RPC_URL,
6});
7
8const agent = await client.createAgent({
9 wallet: myWallet,
10 policy: {
11 budget: { daily: 100, perTransaction: 10 },
12 minProviderScore: 70,
13 },
14});
15
16const result = await agent.pay({
17 endpoint: 'https://api.example.com/v1/data',
18 amount: 0.50,
19 escrow: true,
20});

Policy Engine

Define spending rules with PolicyBuilder.

policy.ts
1import { PolicyBuilder } from '@x8004/sdk';
2
3const policy = new PolicyBuilder()
4 .setDailyBudget(100)
5 .setPerTransactionMax(25)
6 .allowEndpoints(['api.openai.com/*', 'api.anthropic.com/*'])
7 .blockEndpoints(['*.sketchy-api.xyz/*'])
8 .setMinProviderScore(75)
9 .requireApprovalAbove(50)
10 .build();
11
12await agent.updatePolicy(policy);

Options

MethodDescription
setDailyBudget(n)Max USDC per day
setPerTransactionMax(n)Max USDC per transaction
allowEndpoints([])Glob patterns for allowed endpoints
blockEndpoints([])Glob patterns for blocked endpoints
setMinProviderScore(n)Minimum reputation score (0-100)
requireApprovalAbove(n)Human approval for transactions above amount

Escrow

Hold funds until service delivery confirmed.

escrow.ts
1const escrow = await agent.createEscrow({
2 provider: '0x1234...',
3 amount: 10.00,
4 serviceHash: keccak256('fetch data'),
5 timeout: 3600,
6});
7
8// After delivery
9await escrow.release();
10
11// Or if not delivered
12await escrow.dispute('Service not delivered');

States

LOCKEDRELEASEDREFUNDEDDISPUTED

Reputation

Query provider trust scores before payment.

reputation.ts
1const oracle = client.reputation;
2
3const score = await oracle.getScore('0x1234...');
4// { overall: 87, completionRate: 98, disputeRate: 1 }
5
6const meetsThreshold = await oracle.meetsThreshold('0x1234...', 80);

API Reference

Full API documentation.