@reap-protocol/sdk 0.1.0 → 0.1.1
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/package.json +6 -2
- package/src/README.md +54 -37
- package/src/index.ts +1 -1
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reap-protocol/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"axios": "^1.
|
|
10
|
+
"axios": "^1.13.2",
|
|
11
11
|
"ethers": "^6.0.0"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
@@ -15,5 +15,9 @@
|
|
|
15
15
|
},
|
|
16
16
|
"publishConfig": {
|
|
17
17
|
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/Apriloracle/Reap-protocol-sdk.git"
|
|
18
22
|
}
|
|
19
23
|
}
|
package/src/README.md
CHANGED
|
@@ -1,58 +1,66 @@
|
|
|
1
|
-
|
|
1
|
+
# @reap-protocol/sdk
|
|
2
2
|
|
|
3
|
-
The official TypeScript/Node.js SDK for the
|
|
4
|
-
Enable Autonomous Agents to buy and sell on-chain with zero smart contract knowledge.
|
|
3
|
+
**The official TypeScript/Node.js SDK for the Reap Protocol: The Agentic Commerce Grid.**
|
|
5
4
|
|
|
5
|
+
The Reap Protocol enables AI Agents to search for products, register them on-chain, and execute atomic purchases without needing to understand smart contract ABIs. It acts as the bridge between Web2 products data and Web3 commerce settlement.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
## 📦 Installation
|
|
8
|
+
```bash
|
|
10
9
|
npm install @reap-protocol/sdk ethers axios
|
|
10
|
+
```
|
|
11
11
|
|
|
12
|
+
## 🚀 Quick Start
|
|
12
13
|
|
|
14
|
+
This example demonstrates the full Agentic Commerce Loop: Identity -> Discovery -> Settlement.
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
### 1. Setup
|
|
15
17
|
|
|
16
|
-
1. Setup
|
|
17
18
|
If using TypeScript, ensure your tsconfig.json targets ES2020 or higher.
|
|
18
19
|
|
|
19
|
-
2. The Agent Code
|
|
20
|
-
|
|
21
|
-
TypeScript
|
|
20
|
+
### 2. The Agent Code (agent.ts)
|
|
21
|
+
```typescript
|
|
22
22
|
import { ReapClient } from "@reap-protocol/sdk";
|
|
23
23
|
|
|
24
|
-
//
|
|
24
|
+
// Load your private key securely
|
|
25
25
|
const PRIVATE_KEY = process.env.MY_WALLET_KEY || "";
|
|
26
26
|
|
|
27
27
|
async function main() {
|
|
28
|
-
// 1. Initialize
|
|
28
|
+
// 1. Initialize the Agent
|
|
29
|
+
// (Points to official middleware by default)
|
|
29
30
|
const client = new ReapClient(PRIVATE_KEY);
|
|
30
31
|
console.log("🤖 Agent Online");
|
|
31
32
|
|
|
32
33
|
try {
|
|
33
|
-
// 2. Identity
|
|
34
|
-
//
|
|
34
|
+
// 2. Identity (One-time setup)
|
|
35
|
+
// Registers your wallet as an authorized Agent on the Protocol
|
|
36
|
+
console.log("🆔 Checking Identity...");
|
|
35
37
|
await client.registerIdentity();
|
|
36
38
|
|
|
37
|
-
// 3.
|
|
38
|
-
//
|
|
39
|
-
console.log("📦 Stocking Shelf...");
|
|
40
|
-
const result = await client.stockShelf("
|
|
39
|
+
// 3. JIT Stocking (Discovery)
|
|
40
|
+
// Searches Web2 (Reap Deals), registers items on-chain, and returns inventory
|
|
41
|
+
console.log("📦 Stocking Shelf with 'Gaming Laptop'...");
|
|
42
|
+
const result = await client.stockShelf("Gaming Laptop");
|
|
41
43
|
|
|
42
44
|
const inventory = result.items;
|
|
43
|
-
console.log(` 🔍 Found ${inventory.length} items.`);
|
|
45
|
+
console.log(` 🔍 Found ${inventory.length} items on-chain.`);
|
|
44
46
|
|
|
45
47
|
if (inventory.length > 0) {
|
|
46
|
-
// 4. Decision
|
|
48
|
+
// 4. Decision Logic
|
|
49
|
+
// Example: Pick the first available item
|
|
47
50
|
const target = inventory[0];
|
|
48
|
-
console.log(` 🎯
|
|
51
|
+
console.log(` 🎯 Selected: ${target.name} ($${target.price})`);
|
|
52
|
+
console.log(` ID: ${target.id}`);
|
|
49
53
|
|
|
50
|
-
// 5.
|
|
51
|
-
// Automatically approves USDC and executes the purchase
|
|
52
|
-
console.log("💸
|
|
54
|
+
// 5. Agentic Cart (Settlement)
|
|
55
|
+
// Automatically approves USDC and executes the atomic purchase
|
|
56
|
+
console.log("💸 Buying Item...");
|
|
53
57
|
const receipt = await client.buyProduct(target.id);
|
|
54
58
|
|
|
55
|
-
|
|
59
|
+
if (receipt) {
|
|
60
|
+
console.log(`🎉 SUCCESS! Transaction Hash: ${receipt.hash}`);
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
console.log("❌ No items found.");
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
} catch (e: any) {
|
|
@@ -61,26 +69,35 @@ async function main() {
|
|
|
61
69
|
}
|
|
62
70
|
|
|
63
71
|
main();
|
|
72
|
+
```
|
|
64
73
|
|
|
74
|
+
### 3. Run It
|
|
75
|
+
```bash
|
|
76
|
+
# Install execution tools if you haven't already
|
|
77
|
+
npm install --save-dev ts-node typescript @types/node
|
|
65
78
|
|
|
79
|
+
# Run
|
|
80
|
+
npx ts-node agent.ts
|
|
81
|
+
```
|
|
66
82
|
|
|
67
|
-
|
|
68
|
-
Typed Interfaces: Full TypeScript support for Product Data and Transactions.
|
|
69
|
-
Agentic Cart: Automatically routes purchases through the Protocol's batch processor.
|
|
70
|
-
Protocol Negotiation: Built-in support for HTTP 402 Payment Negotiation loops.
|
|
71
|
-
Gas Optimized: Checks on-chain state before sending registration transactions.
|
|
83
|
+
## 🔧 Configuration
|
|
72
84
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
code
|
|
76
|
-
TypeScript
|
|
85
|
+
You can override defaults for custom RPCs or self-hosted middleware.
|
|
86
|
+
```typescript
|
|
77
87
|
const client = new ReapClient(
|
|
78
88
|
"YOUR_PRIVATE_KEY",
|
|
79
|
-
"https://sepolia.
|
|
89
|
+
"https://base-sepolia.g.alchemy.com/v2/YOUR_KEY", // Custom RPC
|
|
80
90
|
"https://api.reap.deals" // Middleware URL
|
|
81
91
|
);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## ✨ Features
|
|
82
95
|
|
|
96
|
+
* **JIT Stocking**: "Just-In-Time" inventory system. If an agent searches for an item not yet on the blockchain, the Protocol indexes it in real-time.
|
|
97
|
+
* **Agentic Cart**: Automatically routes purchases through the Protocol's batch processor.
|
|
98
|
+
* **Protocol Negotiation**: Built-in support for HTTP 402 Payment Negotiation loops.
|
|
99
|
+
* **Gas Optimized**: Checks on-chain state before sending registration transactions.
|
|
83
100
|
|
|
101
|
+
## License
|
|
84
102
|
|
|
85
|
-
License
|
|
86
103
|
MIT
|
package/src/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ export class ReapClient {
|
|
|
8
8
|
|
|
9
9
|
constructor(
|
|
10
10
|
privateKey: string,
|
|
11
|
-
chainRpc: string = "https://
|
|
11
|
+
chainRpc: string = "https://avalanche-fuji.drpc.org",
|
|
12
12
|
builderUrl: string = "https://api.reap.deals"
|
|
13
13
|
) {
|
|
14
14
|
this.provider = new ethers.JsonRpcProvider(chainRpc);
|