@chaoschain/sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +525 -0
- package/dist/index.js +3549 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3484 -0
- package/dist/index.mjs.map +1 -0
- package/dist/providers/compute/index.js +15 -0
- package/dist/providers/compute/index.js.map +1 -0
- package/dist/providers/compute/index.mjs +13 -0
- package/dist/providers/compute/index.mjs.map +1 -0
- package/dist/providers/storage/index.js +286 -0
- package/dist/providers/storage/index.js.map +1 -0
- package/dist/providers/storage/index.mjs +278 -0
- package/dist/providers/storage/index.mjs.map +1 -0
- package/package.json +93 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 ChaosChain
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
# ChaosChain TypeScript SDK
|
|
2
|
+
|
|
3
|
+
**Production-ready TypeScript/JavaScript SDK for building verifiable AI agents with on-chain identity**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@chaoschain/sdk)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://eips.ethereum.org/EIPS/eip-8004)
|
|
8
|
+
|
|
9
|
+
The ChaosChain TypeScript SDK enables developers to build autonomous AI agents with:
|
|
10
|
+
- **ERC-8004 v1.0** ✅ **100% compliant** - on-chain identity, validation and reputation
|
|
11
|
+
- **x402 payments** using Coinbase's HTTP 402 protocol
|
|
12
|
+
- **Pluggable storage** - IPFS, Pinata, Irys, 0G Storage
|
|
13
|
+
- **Type-safe** - Full TypeScript support with exported types
|
|
14
|
+
- **Tree-shakeable** - Optimized bundle size (< 100KB)
|
|
15
|
+
|
|
16
|
+
**Zero setup required** - all ERC-8004 v1.0 contracts are pre-deployed on 5 networks!
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
### Installation
|
|
21
|
+
|
|
22
|
+
#### Basic Installation
|
|
23
|
+
```bash
|
|
24
|
+
# Core SDK with ERC-8004 + x402 + Local IPFS
|
|
25
|
+
npm install @chaoschain/sdk ethers@^6.9.0
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
#### With Optional Storage Providers
|
|
29
|
+
```bash
|
|
30
|
+
# Pinata (cloud IPFS)
|
|
31
|
+
npm install @chaoschain/sdk @pinata/sdk
|
|
32
|
+
|
|
33
|
+
# Irys (Arweave permanent storage)
|
|
34
|
+
npm install @chaoschain/sdk @irys/sdk
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Basic Usage
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { ChaosChainSDK, NetworkConfig, AgentRole } from '@chaoschain/sdk';
|
|
41
|
+
|
|
42
|
+
// Initialize SDK
|
|
43
|
+
const sdk = new ChaosChainSDK({
|
|
44
|
+
agentName: 'MyAgent',
|
|
45
|
+
agentDomain: 'myagent.example.com',
|
|
46
|
+
agentRole: AgentRole.SERVER,
|
|
47
|
+
network: NetworkConfig.BASE_SEPOLIA,
|
|
48
|
+
privateKey: process.env.PRIVATE_KEY,
|
|
49
|
+
enablePayments: true,
|
|
50
|
+
enableStorage: true
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// 1. Register on-chain identity (ERC-8004)
|
|
54
|
+
const { agentId, txHash } = await sdk.registerIdentity();
|
|
55
|
+
console.log(`✅ Agent #${agentId} registered on-chain`);
|
|
56
|
+
|
|
57
|
+
// 2. Execute x402 payment
|
|
58
|
+
const payment = await sdk.executeX402Payment({
|
|
59
|
+
toAgent: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb1',
|
|
60
|
+
amount: '1.5',
|
|
61
|
+
currency: 'USDC'
|
|
62
|
+
});
|
|
63
|
+
console.log(`💰 Payment sent: ${payment.txHash}`);
|
|
64
|
+
|
|
65
|
+
// 3. Store evidence on IPFS
|
|
66
|
+
const cid = await sdk.storeEvidence({
|
|
67
|
+
agentId: agentId.toString(),
|
|
68
|
+
timestamp: Date.now(),
|
|
69
|
+
result: 'analysis complete'
|
|
70
|
+
});
|
|
71
|
+
console.log(`📦 Evidence stored: ipfs://${cid}`);
|
|
72
|
+
|
|
73
|
+
// 4. Give feedback to another agent
|
|
74
|
+
const feedbackTx = await sdk.giveFeedback({
|
|
75
|
+
agentId: 123n,
|
|
76
|
+
rating: 95,
|
|
77
|
+
feedbackUri: `ipfs://${cid}`
|
|
78
|
+
});
|
|
79
|
+
console.log(`⭐ Feedback submitted: ${feedbackTx}`);
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Core Features
|
|
83
|
+
|
|
84
|
+
### **ERC-8004 v1.0 On-Chain Identity** ✅
|
|
85
|
+
|
|
86
|
+
The SDK implements the full [ERC-8004 v1.0 standard](https://eips.ethereum.org/EIPS/eip-8004) with pre-deployed contracts.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
// Register agent identity
|
|
90
|
+
const { agentId, txHash } = await sdk.registerIdentity();
|
|
91
|
+
|
|
92
|
+
// Update agent metadata
|
|
93
|
+
await sdk.updateAgentMetadata(agentId, {
|
|
94
|
+
name: 'MyAgent',
|
|
95
|
+
description: 'AI analysis service',
|
|
96
|
+
capabilities: ['market_analysis', 'sentiment'],
|
|
97
|
+
supportedTrust: ['reputation', 'validation', 'tee-attestation']
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Give feedback (Reputation Registry)
|
|
101
|
+
await sdk.giveFeedback({
|
|
102
|
+
agentId: otherAgentId,
|
|
103
|
+
rating: 95,
|
|
104
|
+
feedbackUri: 'ipfs://Qm...',
|
|
105
|
+
feedbackData: {
|
|
106
|
+
score: 95,
|
|
107
|
+
context: 'excellent_service'
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// Request validation (Validation Registry)
|
|
112
|
+
await sdk.requestValidation({
|
|
113
|
+
validatorAgentId: validatorId,
|
|
114
|
+
requestUri: 'ipfs://Qm...',
|
|
115
|
+
requestHash: 'proof_hash_here'
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Pre-deployed addresses**:
|
|
120
|
+
|
|
121
|
+
#### Sepolia
|
|
122
|
+
- Identity: [`0x8004a6090Cd10A7288092483047B097295Fb8847`](https://sepolia.etherscan.io/address/0x8004a6090Cd10A7288092483047B097295Fb8847)
|
|
123
|
+
- Reputation: [`0x8004B8FD1A363aa02fDC07635C0c5F94f6Af5B7E`](https://sepolia.etherscan.io/address/0x8004B8FD1A363aa02fDC07635C0c5F94f6Af5B7E)
|
|
124
|
+
- Validation: [`0x8004CB39f29c09145F24Ad9dDe2A108C1A2cdfC5`](https://sepolia.etherscan.io/address/0x8004CB39f29c09145F24Ad9dDe2A108C1A2cdfC5)
|
|
125
|
+
|
|
126
|
+
#### Base Sepolia
|
|
127
|
+
- Identity: [`0x8004AA63c570c570eBF15376c0dB199918BFe9Fb`](https://sepolia.basescan.org/address/0x8004AA63c570c570eBF15376c0dB199918BFe9Fb)
|
|
128
|
+
- Reputation: [`0x8004bd8daB57f14Ed299135749a5CB5c42d341BF`](https://sepolia.basescan.org/address/0x8004bd8daB57f14Ed299135749a5CB5c42d341BF)
|
|
129
|
+
- Validation: [`0x8004C269D0A5647E51E121FeB226200ECE932d55`](https://sepolia.basescan.org/address/0x8004C269D0A5647E51E121FeB226200ECE932d55)
|
|
130
|
+
|
|
131
|
+
#### Linea Sepolia
|
|
132
|
+
- Identity: [`0x8004aa7C931bCE1233973a0C6A667f73F66282e7`](https://sepolia.lineascan.build/address/0x8004aa7C931bCE1233973a0C6A667f73F66282e7)
|
|
133
|
+
- Reputation: [`0x8004bd8483b99310df121c46ED8858616b2Bba02`](https://sepolia.lineascan.build/address/0x8004bd8483b99310df121c46ED8858616b2Bba02)
|
|
134
|
+
- Validation: [`0x8004c44d1EFdd699B2A26e781eF7F77c56A9a4EB`](https://sepolia.lineascan.build/address/0x8004c44d1EFdd699B2A26e781eF7F77c56A9a4EB)
|
|
135
|
+
|
|
136
|
+
#### Hedera Testnet
|
|
137
|
+
- **IdentityRegistry**: `0x4c74ebd72921d537159ed2053f46c12a7d8e5923`
|
|
138
|
+
- **ReputationRegistry**: `0xc565edcba77e3abeade40bfd6cf6bf583b3293e0`
|
|
139
|
+
- **ValidationRegistry**: `0x18df085d85c586e9241e0cd121ca422f571c2da6`
|
|
140
|
+
|
|
141
|
+
#### 0G Galileo Testnet
|
|
142
|
+
- **IdentityRegistry**: [`0x80043ed9cf33a3472768dcd53175bb44e03a1e4a`](https://chainscan-galileo.0g.ai/address/0x80043ed9cf33a3472768dcd53175bb44e03a1e4a)
|
|
143
|
+
- **ReputationRegistry**: [`0x80045d7b72c47bf5ff73737b780cb1a5ba8ee202`](https://chainscan-galileo.0g.ai/address/0x80045d7b72c47bf5ff73737b780cb1a5ba8ee202)
|
|
144
|
+
- **ValidationRegistry**: [`0x80041728e0aadf1d1427f9be18d52b7f3afefafb`](https://chainscan-galileo.0g.ai/address/0x80041728e0aadf1d1427f9be18d52b7f3afefafb)
|
|
145
|
+
|
|
146
|
+
### **x402 Crypto Payments**
|
|
147
|
+
|
|
148
|
+
Native integration with Coinbase's x402 HTTP 402 protocol:
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
// Execute payment
|
|
152
|
+
const payment = await sdk.executeX402Payment({
|
|
153
|
+
toAgent: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb1',
|
|
154
|
+
amount: '10.0',
|
|
155
|
+
currency: 'USDC',
|
|
156
|
+
serviceType: 'ai_analysis'
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Create payment requirements (HTTP 402)
|
|
160
|
+
const requirements = sdk.createX402PaymentRequirements(
|
|
161
|
+
'5.0',
|
|
162
|
+
'USDC',
|
|
163
|
+
'Premium AI Analysis'
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
// Calculate costs with fees
|
|
167
|
+
const costs = sdk.calculateTotalCost('10.0', 'USDC');
|
|
168
|
+
console.log(`Amount: ${costs.amount}, Fee: ${costs.fee}, Total: ${costs.total}`);
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
**Features**:
|
|
172
|
+
- ✅ Direct USDC transfers (Base, Ethereum, Linea)
|
|
173
|
+
- ✅ Automatic 2.5% protocol fee to ChaosChain
|
|
174
|
+
- ✅ ETH and USDC support
|
|
175
|
+
- ✅ Payment receipts and verification
|
|
176
|
+
|
|
177
|
+
### **Pluggable Storage Providers**
|
|
178
|
+
|
|
179
|
+
Choose your storage backend:
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
import {
|
|
183
|
+
ChaosChainSDK,
|
|
184
|
+
IPFSLocalStorage,
|
|
185
|
+
PinataStorage
|
|
186
|
+
} from '@chaoschain/sdk';
|
|
187
|
+
|
|
188
|
+
// Local IPFS (default)
|
|
189
|
+
const sdk = new ChaosChainSDK({
|
|
190
|
+
agentName: 'MyAgent',
|
|
191
|
+
network: 'base-sepolia',
|
|
192
|
+
privateKey: process.env.PRIVATE_KEY
|
|
193
|
+
// Uses LocalIPFS by default
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Or use Pinata
|
|
197
|
+
const sdk = new ChaosChainSDK({
|
|
198
|
+
agentName: 'MyAgent',
|
|
199
|
+
network: 'base-sepolia',
|
|
200
|
+
privateKey: process.env.PRIVATE_KEY,
|
|
201
|
+
storageProvider: new PinataStorage({
|
|
202
|
+
jwt: process.env.PINATA_JWT,
|
|
203
|
+
gatewayUrl: 'https://gateway.pinata.cloud'
|
|
204
|
+
})
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// Upload data
|
|
208
|
+
const result = await sdk.storage.upload({ data: 'evidence' });
|
|
209
|
+
console.log(`Uploaded to: ${result.uri}`);
|
|
210
|
+
|
|
211
|
+
// Download data
|
|
212
|
+
const data = await sdk.storage.download(result.cid);
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
**Storage Options**:
|
|
216
|
+
|
|
217
|
+
| Provider | Cost | Setup | Best For |
|
|
218
|
+
|----------|------|-------|----------|
|
|
219
|
+
| **Local IPFS** | 🆓 Free | `ipfs daemon` | Development |
|
|
220
|
+
| **Pinata** | 💰 Paid | API keys | Production |
|
|
221
|
+
| **Irys** | 💰 Paid | Wallet key | Permanent storage |
|
|
222
|
+
|
|
223
|
+
## Supported Networks
|
|
224
|
+
|
|
225
|
+
ERC-8004 v1.0 contracts are **pre-deployed on 5 networks**:
|
|
226
|
+
|
|
227
|
+
| Network | Chain ID | Status | Features |
|
|
228
|
+
|---------|----------|--------|----------|
|
|
229
|
+
| **Ethereum Sepolia** | 11155111 | ✅ Active | ERC-8004 + x402 USDC |
|
|
230
|
+
| **Base Sepolia** | 84532 | ✅ Active | ERC-8004 + x402 USDC |
|
|
231
|
+
| **Linea Sepolia** | 59141 | ✅ Active | ERC-8004 + x402 USDC |
|
|
232
|
+
| **Hedera Testnet** | 296 | ✅ Active | ERC-8004 |
|
|
233
|
+
| **0G Testnet** | 16600 | ✅ Active | ERC-8004 + Storage + Compute |
|
|
234
|
+
|
|
235
|
+
Simply change the `network` parameter - no other configuration needed!
|
|
236
|
+
|
|
237
|
+
## API Reference
|
|
238
|
+
|
|
239
|
+
### ChaosChainSDK
|
|
240
|
+
|
|
241
|
+
Main SDK class with all functionality.
|
|
242
|
+
|
|
243
|
+
#### Constructor Options
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
interface ChaosChainSDKConfig {
|
|
247
|
+
agentName: string; // Your agent's name
|
|
248
|
+
agentDomain: string; // Your agent's domain
|
|
249
|
+
agentRole: AgentRole | string; // 'server', 'client', 'validator', 'both'
|
|
250
|
+
network: NetworkConfig | string; // Network to use
|
|
251
|
+
privateKey?: string; // Wallet private key
|
|
252
|
+
mnemonic?: string; // Or HD wallet mnemonic
|
|
253
|
+
rpcUrl?: string; // Custom RPC URL (optional)
|
|
254
|
+
enablePayments?: boolean; // Enable x402 payments (default: true)
|
|
255
|
+
enableStorage?: boolean; // Enable storage (default: true)
|
|
256
|
+
storageProvider?: StorageProvider; // Custom storage provider
|
|
257
|
+
computeProvider?: ComputeProvider; // Custom compute provider
|
|
258
|
+
walletFile?: string; // Load wallet from file
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
#### Key Methods
|
|
263
|
+
|
|
264
|
+
| Category | Method | Description |
|
|
265
|
+
|----------|--------|-------------|
|
|
266
|
+
| **Identity** | `registerIdentity()` | Register agent on-chain |
|
|
267
|
+
| | `getAgentMetadata(agentId)` | Get agent metadata |
|
|
268
|
+
| | `updateAgentMetadata(agentId, metadata)` | Update metadata |
|
|
269
|
+
| **Reputation** | `giveFeedback(params)` | Submit feedback |
|
|
270
|
+
| | `getAgentStats(agentId)` | Get reputation stats |
|
|
271
|
+
| | `revokeFeedback(feedbackId)` | Revoke feedback |
|
|
272
|
+
| **Validation** | `requestValidation(params)` | Request validation |
|
|
273
|
+
| | `respondToValidation(requestId, approved, uri)` | Respond to validation |
|
|
274
|
+
| | `getValidationStats(agentId)` | Get validation stats |
|
|
275
|
+
| **Payments** | `executeX402Payment(params)` | Execute payment |
|
|
276
|
+
| | `getUSDCBalance()` | Get USDC balance |
|
|
277
|
+
| | `getETHBalance()` | Get ETH balance |
|
|
278
|
+
| **Storage** | `storage.upload(data)` | Upload to storage |
|
|
279
|
+
| | `storage.download(cid)` | Download from storage |
|
|
280
|
+
| | `storeEvidence(data)` | Store evidence (convenience) |
|
|
281
|
+
| **Wallet** | `getAddress()` | Get wallet address |
|
|
282
|
+
| | `getBalance()` | Get native balance |
|
|
283
|
+
| | `signMessage(message)` | Sign message |
|
|
284
|
+
|
|
285
|
+
## Examples
|
|
286
|
+
|
|
287
|
+
### Complete Agent Workflow
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
import { ChaosChainSDK, NetworkConfig, AgentRole } from '@chaoschain/sdk';
|
|
291
|
+
|
|
292
|
+
async function main() {
|
|
293
|
+
// Initialize SDK
|
|
294
|
+
const sdk = new ChaosChainSDK({
|
|
295
|
+
agentName: 'AnalysisAgent',
|
|
296
|
+
agentDomain: 'analysis.example.com',
|
|
297
|
+
agentRole: AgentRole.SERVER,
|
|
298
|
+
network: NetworkConfig.BASE_SEPOLIA,
|
|
299
|
+
privateKey: process.env.PRIVATE_KEY,
|
|
300
|
+
enablePayments: true,
|
|
301
|
+
enableStorage: true
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
// 1. Register on-chain identity
|
|
305
|
+
const { agentId, txHash } = await sdk.registerIdentity();
|
|
306
|
+
console.log(`✅ Agent #${agentId} registered: ${txHash}`);
|
|
307
|
+
|
|
308
|
+
// 2. Update metadata
|
|
309
|
+
await sdk.updateAgentMetadata(agentId, {
|
|
310
|
+
name: 'AnalysisAgent',
|
|
311
|
+
description: 'AI market analysis service',
|
|
312
|
+
capabilities: ['market_analysis', 'sentiment'],
|
|
313
|
+
supportedTrust: ['reputation', 'validation']
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// 3. Perform work and store evidence
|
|
317
|
+
const evidence = {
|
|
318
|
+
agentId: agentId.toString(),
|
|
319
|
+
timestamp: Date.now(),
|
|
320
|
+
analysis: { trend: 'bullish', confidence: 0.87 }
|
|
321
|
+
};
|
|
322
|
+
const cid = await sdk.storeEvidence(evidence);
|
|
323
|
+
console.log(`📦 Evidence stored: ipfs://${cid}`);
|
|
324
|
+
|
|
325
|
+
// 4. Receive payment
|
|
326
|
+
const payment = await sdk.executeX402Payment({
|
|
327
|
+
toAgent: sdk.getAddress(),
|
|
328
|
+
amount: '15.0',
|
|
329
|
+
currency: 'USDC',
|
|
330
|
+
serviceType: 'analysis'
|
|
331
|
+
});
|
|
332
|
+
console.log(`💰 Payment received: ${payment.txHash}`);
|
|
333
|
+
|
|
334
|
+
// 5. Client gives feedback
|
|
335
|
+
await sdk.giveFeedback({
|
|
336
|
+
agentId: agentId,
|
|
337
|
+
rating: 95,
|
|
338
|
+
feedbackUri: `ipfs://${cid}`
|
|
339
|
+
});
|
|
340
|
+
console.log(`⭐ Feedback submitted`);
|
|
341
|
+
|
|
342
|
+
// 6. Check reputation
|
|
343
|
+
const stats = await sdk.getAgentStats(agentId);
|
|
344
|
+
console.log(`📊 Stats: ${stats.totalFeedback} feedbacks, avg rating: ${stats.averageRating}`);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
main().catch(console.error);
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### Using Pinata Storage
|
|
351
|
+
|
|
352
|
+
```typescript
|
|
353
|
+
import { ChaosChainSDK, PinataStorage, NetworkConfig } from '@chaoschain/sdk';
|
|
354
|
+
|
|
355
|
+
const sdk = new ChaosChainSDK({
|
|
356
|
+
agentName: 'MyAgent',
|
|
357
|
+
agentDomain: 'myagent.example.com',
|
|
358
|
+
agentRole: 'server',
|
|
359
|
+
network: NetworkConfig.BASE_SEPOLIA,
|
|
360
|
+
privateKey: process.env.PRIVATE_KEY,
|
|
361
|
+
storageProvider: new PinataStorage({
|
|
362
|
+
jwt: process.env.PINATA_JWT,
|
|
363
|
+
gatewayUrl: 'https://gateway.pinata.cloud'
|
|
364
|
+
})
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
// Upload will now use Pinata
|
|
368
|
+
const result = await sdk.storage.upload({
|
|
369
|
+
data: 'Important evidence',
|
|
370
|
+
timestamp: Date.now()
|
|
371
|
+
});
|
|
372
|
+
console.log(`Stored on Pinata: ${result.uri}`);
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### Event Listening
|
|
376
|
+
|
|
377
|
+
```typescript
|
|
378
|
+
// Listen for new agent registrations
|
|
379
|
+
sdk.onAgentRegistered((agentId, owner, uri) => {
|
|
380
|
+
console.log(`New agent registered: #${agentId} by ${owner}`);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// Listen for feedback events
|
|
384
|
+
sdk.onFeedbackGiven((feedbackId, fromAgent, toAgent, rating) => {
|
|
385
|
+
console.log(`Feedback #${feedbackId}: ${fromAgent} → ${toAgent} (${rating}/100)`);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
// Listen for validation requests
|
|
389
|
+
sdk.onValidationRequested((requestId, requester, validator) => {
|
|
390
|
+
console.log(`Validation requested: #${requestId} from ${requester}`);
|
|
391
|
+
});
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
## Configuration
|
|
395
|
+
|
|
396
|
+
### Environment Variables
|
|
397
|
+
|
|
398
|
+
```bash
|
|
399
|
+
# Network Configuration
|
|
400
|
+
PRIVATE_KEY=your_private_key_here
|
|
401
|
+
BASE_SEPOLIA_RPC_URL=https://sepolia.base.org
|
|
402
|
+
ETHEREUM_SEPOLIA_RPC_URL=https://rpc.sepolia.org
|
|
403
|
+
|
|
404
|
+
# Storage Providers
|
|
405
|
+
PINATA_JWT=your_pinata_jwt
|
|
406
|
+
PINATA_GATEWAY=https://gateway.pinata.cloud
|
|
407
|
+
|
|
408
|
+
# Optional: Custom RPC endpoints
|
|
409
|
+
LINEA_SEPOLIA_RPC_URL=https://rpc.sepolia.linea.build
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
### TypeScript Configuration
|
|
413
|
+
|
|
414
|
+
The SDK is fully typed. Enable strict mode in your `tsconfig.json`:
|
|
415
|
+
|
|
416
|
+
```json
|
|
417
|
+
{
|
|
418
|
+
"compilerOptions": {
|
|
419
|
+
"target": "ES2022",
|
|
420
|
+
"module": "ESNext",
|
|
421
|
+
"moduleResolution": "bundler",
|
|
422
|
+
"strict": true,
|
|
423
|
+
"esModuleInterop": true
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
## Build & Development
|
|
429
|
+
|
|
430
|
+
```bash
|
|
431
|
+
# Install dependencies
|
|
432
|
+
npm install
|
|
433
|
+
|
|
434
|
+
# Build the SDK
|
|
435
|
+
npm run build
|
|
436
|
+
|
|
437
|
+
# Run tests
|
|
438
|
+
npm test
|
|
439
|
+
|
|
440
|
+
# Run tests with coverage
|
|
441
|
+
npm run test:coverage
|
|
442
|
+
|
|
443
|
+
# Lint code
|
|
444
|
+
npm run lint
|
|
445
|
+
|
|
446
|
+
# Format code
|
|
447
|
+
npm run format
|
|
448
|
+
|
|
449
|
+
# Type check
|
|
450
|
+
npm run typecheck
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
## Bundle Size
|
|
454
|
+
|
|
455
|
+
The SDK is optimized for minimal bundle size:
|
|
456
|
+
|
|
457
|
+
- **Core SDK**: ~80KB minified + gzipped
|
|
458
|
+
- **Tree-shakeable**: Import only what you need
|
|
459
|
+
- **Zero dependencies** in production (ethers, axios, dotenv, zod)
|
|
460
|
+
|
|
461
|
+
```typescript
|
|
462
|
+
// Import only what you need
|
|
463
|
+
import { ChaosChainSDK, NetworkConfig } from '@chaoschain/sdk';
|
|
464
|
+
|
|
465
|
+
// Or import storage providers separately
|
|
466
|
+
import { PinataStorage } from '@chaoschain/sdk/providers/storage';
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
## Testing
|
|
470
|
+
|
|
471
|
+
```bash
|
|
472
|
+
# Run all tests
|
|
473
|
+
npm test
|
|
474
|
+
|
|
475
|
+
# Run specific test file
|
|
476
|
+
npm test -- WalletManager.test.ts
|
|
477
|
+
|
|
478
|
+
# Run with coverage
|
|
479
|
+
npm run test:coverage
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
## FAQ
|
|
483
|
+
|
|
484
|
+
**Q: Do I need to deploy contracts?**
|
|
485
|
+
A: No! All ERC-8004 v1.0 contracts are pre-deployed on 5 networks.
|
|
486
|
+
|
|
487
|
+
**Q: What's the difference between Python and TypeScript SDK?**
|
|
488
|
+
A: Both SDKs have feature parity. Use TypeScript for web/Node.js apps, Python for backend services.
|
|
489
|
+
|
|
490
|
+
**Q: How do x402 payments work?**
|
|
491
|
+
A: Real USDC/ETH transfers using Coinbase's HTTP 402 protocol. 2.5% fee goes to ChaosChain treasury.
|
|
492
|
+
|
|
493
|
+
**Q: Which storage provider should I use?**
|
|
494
|
+
A: Local IPFS for development, Pinata for production, Irys for permanent storage.
|
|
495
|
+
|
|
496
|
+
**Q: Can I use this in the browser?**
|
|
497
|
+
A: Yes! The SDK works in Node.js, browsers, React, Next.js, Vue, etc.
|
|
498
|
+
|
|
499
|
+
## Contributing
|
|
500
|
+
|
|
501
|
+
We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
502
|
+
|
|
503
|
+
## License
|
|
504
|
+
|
|
505
|
+
MIT License - see [LICENSE](LICENSE) file.
|
|
506
|
+
|
|
507
|
+
## Links
|
|
508
|
+
|
|
509
|
+
- **Homepage**: [https://chaoscha.in](https://chaoscha.in)
|
|
510
|
+
- **Documentation**: [https://docs.chaoscha.in](https://docs.chaoscha.in)
|
|
511
|
+
- **GitHub**: [https://github.com/ChaosChain/chaoschain-sdk-ts](https://github.com/ChaosChain/chaoschain-sdk-ts)
|
|
512
|
+
- **npm**: [https://www.npmjs.com/package/@chaoschain/sdk](https://www.npmjs.com/package/@chaoschain/sdk)
|
|
513
|
+
- **Python SDK**: [https://pypi.org/project/chaoschain-sdk/](https://pypi.org/project/chaoschain-sdk/)
|
|
514
|
+
- **ERC-8004 Spec**: [https://eips.ethereum.org/EIPS/eip-8004](https://eips.ethereum.org/EIPS/eip-8004)
|
|
515
|
+
- **x402 Protocol**: [https://www.x402.org/](https://www.x402.org/)
|
|
516
|
+
|
|
517
|
+
## Support
|
|
518
|
+
|
|
519
|
+
- **Issues**: [GitHub Issues](https://github.com/ChaosChain/chaoschain-sdk-ts/issues)
|
|
520
|
+
- **Discord**: [ChaosChain Community]
|
|
521
|
+
- **Email**: sumeet.chougule@nethermind.io
|
|
522
|
+
|
|
523
|
+
---
|
|
524
|
+
|
|
525
|
+
**Build verifiable AI agents with on-chain identity and crypto payments. Start in minutes!**
|