@arcpaylabs/somnia-x402-agent-starter 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.md +21 -0
- package/README.md +45 -0
- package/package.json +39 -0
- package/src/agent-client.mjs +63 -0
- package/src/env.example +3 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Henry Sammarfo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this starter kit and associated documentation files (the "Starter Kit"), to deal
|
|
7
|
+
in the Starter Kit without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Starter Kit, and to permit persons to whom the Starter Kit 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 Starter Kit.
|
|
14
|
+
|
|
15
|
+
THE STARTER KIT 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 STARTER KIT OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE STARTER KIT.
|
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# ArcPay Somnia x402 Agent Starter
|
|
2
|
+
|
|
3
|
+
This starter shows how a developer can integrate with ArcPay's live Somnia x402 server.
|
|
4
|
+
|
|
5
|
+
It covers:
|
|
6
|
+
|
|
7
|
+
- reading a payment quote
|
|
8
|
+
- requesting a protected agent resource
|
|
9
|
+
- checking HTTP 402 requirements
|
|
10
|
+
- verifying an order id
|
|
11
|
+
- deriving the agent id locally
|
|
12
|
+
|
|
13
|
+
It does not hold private keys by default. Wallet payment is intentionally left to your app or operator wallet.
|
|
14
|
+
|
|
15
|
+
## Setup
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install
|
|
19
|
+
cp src/env.example .env
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Commands
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
node src/agent-client.mjs quote research-agent
|
|
26
|
+
node src/agent-client.mjs locked research-agent
|
|
27
|
+
node src/agent-client.mjs verify 0xORDER_ID research-agent
|
|
28
|
+
node src/agent-client.mjs unlock research-agent 0xORDER_ID
|
|
29
|
+
node src/agent-client.mjs agent-id research-agent
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Live Server
|
|
33
|
+
|
|
34
|
+
```text
|
|
35
|
+
https://x402.20.208.46.195.nip.io
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Payment Flow
|
|
39
|
+
|
|
40
|
+
1. `quote` the agent slug.
|
|
41
|
+
2. Create an order in `AgentOrderBook` with the quoted `agentId`, `requestUri`, and `amountWei`.
|
|
42
|
+
3. Provider fulfills the order.
|
|
43
|
+
4. `unlock` the resource with `orderId`.
|
|
44
|
+
|
|
45
|
+
See the main docs at `../../mintlify/x402-agent-payments.mdx`.
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arcpaylabs/somnia-x402-agent-starter",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Starter client for integrating with ArcPay Somnia x402 paid agent endpoints.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"author": "Henry Sammarfo <jasonneil4040@gmail.com>",
|
|
9
|
+
"homepage": "https://arcpay-somnia.vercel.app/docs/x402-agent-payments",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/ArcPayLabs/arcpay-somnia.git",
|
|
13
|
+
"directory": "starter-kits/somnia-x402-agent"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"arcpay-somnia-x402-agent": "src/agent-client.mjs"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE.md",
|
|
21
|
+
"src"
|
|
22
|
+
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"quote": "node src/agent-client.mjs quote research-agent",
|
|
28
|
+
"locked": "node src/agent-client.mjs locked research-agent",
|
|
29
|
+
"agent-id": "node src/agent-client.mjs agent-id research-agent",
|
|
30
|
+
"pack:dry": "npm pack --dry-run"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"dotenv": "^16.4.7",
|
|
34
|
+
"ethers": "^6.13.5"
|
|
35
|
+
},
|
|
36
|
+
"overrides": {
|
|
37
|
+
"ws": "^8.20.1"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "dotenv/config";
|
|
3
|
+
import { id } from "ethers";
|
|
4
|
+
|
|
5
|
+
const serverUrl = (process.env.ARCPAY_X402_SERVER_URL || "https://x402.20.208.46.195.nip.io").replace(/\/+$/, "");
|
|
6
|
+
const [, , command = "help", arg1 = "research-agent", arg2 = "research-agent"] = process.argv;
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
if (command === "quote") {
|
|
10
|
+
const body = await getJson(`/x402/payment-requirements/${encodeURIComponent(arg1)}`);
|
|
11
|
+
print(body);
|
|
12
|
+
} else if (command === "locked") {
|
|
13
|
+
const response = await fetch(`${serverUrl}/agent/${encodeURIComponent(arg1)}/work`);
|
|
14
|
+
const body = await response.json();
|
|
15
|
+
print({ status: response.status, body });
|
|
16
|
+
} else if (command === "verify") {
|
|
17
|
+
const body = await postJson("/x402/verify", { orderId: arg1, agentSlug: arg2 });
|
|
18
|
+
print(body);
|
|
19
|
+
} else if (command === "unlock") {
|
|
20
|
+
const body = await getJson(`/agent/${encodeURIComponent(arg1)}/work?orderId=${encodeURIComponent(arg2)}`);
|
|
21
|
+
print(body);
|
|
22
|
+
} else if (command === "agent-id") {
|
|
23
|
+
console.log(id(arg1));
|
|
24
|
+
} else {
|
|
25
|
+
console.log([
|
|
26
|
+
"ArcPay Somnia x402 Agent Starter",
|
|
27
|
+
"",
|
|
28
|
+
"Commands:",
|
|
29
|
+
" node src/agent-client.mjs quote <agentSlug>",
|
|
30
|
+
" node src/agent-client.mjs locked <agentSlug>",
|
|
31
|
+
" node src/agent-client.mjs verify <orderId> <agentSlug>",
|
|
32
|
+
" node src/agent-client.mjs unlock <agentSlug> <orderId>",
|
|
33
|
+
" node src/agent-client.mjs agent-id <agentSlug>",
|
|
34
|
+
].join("\n"));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function getJson(path) {
|
|
39
|
+
const response = await fetch(`${serverUrl}${path}`);
|
|
40
|
+
const body = await response.json();
|
|
41
|
+
if (!response.ok && response.status !== 402) throw new Error(body.error || `HTTP ${response.status}`);
|
|
42
|
+
return body;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function postJson(path, payload) {
|
|
46
|
+
const response = await fetch(`${serverUrl}${path}`, {
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers: { "content-type": "application/json" },
|
|
49
|
+
body: JSON.stringify(payload),
|
|
50
|
+
});
|
|
51
|
+
const body = await response.json();
|
|
52
|
+
if (!response.ok) throw new Error(body.error || `HTTP ${response.status}`);
|
|
53
|
+
return body;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function print(value) {
|
|
57
|
+
console.log(JSON.stringify(value, null, 2));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
main().catch((error) => {
|
|
61
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
62
|
+
process.exitCode = 1;
|
|
63
|
+
});
|
package/src/env.example
ADDED