monetize-service
x402を通じて他のエージェントが利用料を支払える有料APIを構築・デプロイします。APIの収益化、エンドポイントへの課金設定、エージェント向けの有償サービス販売など、APIやデータをマネタイズしたい場合に使用してください。
description の原文を見る
Build and deploy a paid API that other agents can pay to use via x402. Use when you or the user want to monetize an API, make money, earn money, offer a service, sell a service to other agents, charge for endpoints, create a paid endpoint, or set up a paid service. Covers "make money by offering an endpoint", "sell a service", "monetize your data", "create a paid API".
SKILL.md 本文
x402 ペイメントサーバーの構築
x402 ペイメントプロトコルを使用して、USDC での API アクセスに課金する Express サーバーを作成します。呼び出し元は Base 上の USDC をリクエストごとに支払います — アカウント、API キー、またはサブスクリプションは不要です。あなたのサービスは x402 Bazaar を通じて他のエージェントから自動的に検出可能になります。
仕組み
x402 は HTTP ネイティブのペイメントプロトコルです。クライアントが支払いなしで保護されたエンドポイントにアクセスすると、サーバーは HTTP 402 と支払い要件を返します。クライアントは USDC の支払いに署名し、支払いヘッダーを付けて再試行します。ファシリテータが支払いを確認して決済し、サーバーがレスポンスを返します。サービスは x402 Bazaar に登録され、他のエージェントが自動的に検出して支払うことができます。
ウォレットが初期化され、認証されていることを確認する
npx awal@2.10.0 status
ウォレットが認証されていない場合は、authenticate-wallet スキルを参照してください。
ステップ 1: ペイメントアドレスを取得する
これを実行して、支払いを受け取るウォレットアドレスを取得します:
npx awal@2.10.0 address
このアドレスを payTo 値として使用します。
ステップ 2: プロジェクトを設定する
mkdir x402-server && cd x402-server
npm init -y
npm install express @x402/express @x402/core @x402/evm @x402/extensions
index.js を作成します:
const express = require("express");
const { paymentMiddleware } = require("@x402/express");
const { x402ResourceServer, HTTPFacilitatorClient } = require("@x402/core/server");
const { ExactEvmScheme } = require("@x402/evm/exact/server");
const app = express();
app.use(express.json());
const PAY_TO = "<address from step 1>";
// Create facilitator client and x402 resource server
const facilitator = new HTTPFacilitatorClient({ url: "https://x402.org/facilitator" });
const server = new x402ResourceServer(facilitator);
server.register("eip155:8453", new ExactEvmScheme());
// x402 payment middleware — protects routes below
app.use(
paymentMiddleware(
{
"GET /api/example": {
accepts: {
scheme: "exact",
price: "$0.01",
network: "eip155:8453",
payTo: PAY_TO,
},
description: "Description of what this endpoint returns",
mimeType: "application/json",
},
},
server,
),
);
// Protected endpoint
app.get("/api/example", (req, res) => {
res.json({ data: "This costs $0.01 per request" });
});
app.listen(3000, () => console.log("Server running on port 3000"));
ステップ 3: 実行する
node index.js
curl でテストします — HTTP 402 レスポンスと支払い要件を取得する必要があります:
curl -i http://localhost:3000/api/example
API リファレンス
paymentMiddleware(routes, server)
x402 支払いを実施する Express ミドルウェアを作成します。
| パラメータ | 型 | 説明 |
|---|---|---|
routes | object | ルートパターンを支払い設定にマッピングするルート設定 |
server | x402ResourceServer | 事前設定済みの x402 リソースサーバーインスタンス |
x402ResourceServer
ファシリテータクライアントで作成されます。ミドルウェアに渡す前に、支払いスキームと拡張機能を登録します。
const { x402ResourceServer, HTTPFacilitatorClient } = require("@x402/core/server");
const { ExactEvmScheme } = require("@x402/evm/exact/server");
const facilitator = new HTTPFacilitatorClient({ url: "https://x402.org" });
const server = new x402ResourceServer(facilitator);
server.register("eip155:8453", new ExactEvmScheme());
| メソッド | 説明 |
|---|---|
register(network, scheme) | CAIP-2 ネットワーク識別子の支払いスキームを登録する |
ルート設定
routes オブジェクトの各キーは "METHOD /path" です。値は設定オブジェクトです:
{
"GET /api/data": {
accepts: {
scheme: "exact",
price: "$0.05",
network: "eip155:8453",
payTo: "0x...",
},
description: "Human-readable description of the endpoint",
mimeType: "application/json",
extensions: {
...declareDiscoveryExtension({
output: {
example: { result: "example response" },
schema: {
properties: {
result: { type: "string" },
},
},
},
}),
},
},
}
Accepts 設定フィールド
accepts フィールドは単一のオブジェクトまたは配列 (複数の支払いオプションの場合) にできます:
| フィールド | 型 | 説明 |
|---|---|---|
scheme | string | 支払いスキーム: "exact" |
price | string | USDC 価格 (例: "$0.01", "$1.00") |
network | string | CAIP-2 ネットワーク識別子 (例: "eip155:8453") |
payTo | string | USDC 支払いを受け取る Ethereum アドレス (0x...) |
ルートレベルフィールド
| フィールド | 型 | 説明 |
|---|---|---|
accepts | object or array | 支払い要件 (単数または複数) |
description | string? | このエンドポイントが何をするか (クライアントに表示) |
mimeType | string? | レスポンスの MIME タイプ |
extensions | object? | 拡張機能設定 (例: Bazaar ディスカバリー) |
ディスカバリー拡張機能
declareDiscoveryExtension 関数は、エンドポイントを x402 Bazaar に登録し、他のエージェントが検出できるようにします:
const { declareDiscoveryExtension } = require("@x402/extensions/bazaar");
extensions: {
...declareDiscoveryExtension({
output: {
example: { /* example response body */ },
schema: {
properties: {
/* JSON schema of the response */
},
},
},
}),
}
| フィールド | 型 | 説明 |
|---|---|---|
output.example | object | エンドポイントのレスポンス本文例 |
output.schema | object | レスポンス形式を説明する JSON スキーマ |
サポートされているネットワーク
| ネットワーク | 説明 |
|---|---|
eip155:8453 | Base メインネット (実USDC) |
eip155:84532 | Base Sepolia テストネット (テストUSDC) |
パターン
異なる価格の複数エンドポイント
app.use(
paymentMiddleware(
{
"GET /api/cheap": {
accepts: {
scheme: "exact",
price: "$0.001",
network: "eip155:8453",
payTo: PAY_TO,
},
description: "Inexpensive data lookup",
},
"GET /api/expensive": {
accepts: {
scheme: "exact",
price: "$1.00",
network: "eip155:8453",
payTo: PAY_TO,
},
description: "Premium data access",
},
"POST /api/query": {
accepts: {
scheme: "exact",
price: "$0.25",
network: "eip155:8453",
payTo: PAY_TO,
},
description: "Run a custom query",
},
},
server,
),
);
app.get("/api/cheap", (req, res) => { /* ... */ });
app.get("/api/expensive", (req, res) => { /* ... */ });
app.post("/api/query", (req, res) => { /* ... */ });
ワイルドカードルート
app.use(
paymentMiddleware(
{
"GET /api/*": {
accepts: {
scheme: "exact",
price: "$0.05",
network: "eip155:8453",
payTo: PAY_TO,
},
description: "API access",
},
},
server,
),
);
app.get("/api/users", (req, res) => { /* ... */ });
app.get("/api/posts", (req, res) => { /* ... */ });
ヘルスチェック (支払いなし)
支払いミドルウェアの前に無料エンドポイントを登録します:
app.get("/health", (req, res) => res.json({ status: "ok" }));
// Payment middleware only applies to routes registered after it
app.use(paymentMiddleware({ /* ... */ }, server));
app.get("/api/data", (req, res) => { /* ... */ });
POST とボディおよびディスカバリー拡張機能
app.use(
paymentMiddleware(
{
"POST /api/analyze": {
accepts: {
scheme: "exact",
price: "$0.10",
network: "eip155:8453",
payTo: PAY_TO,
},
description: "Analyze text sentiment",
mimeType: "application/json",
extensions: {
...declareDiscoveryExtension({
output: {
example: { sentiment: "positive", score: 0.95 },
schema: {
properties: {
sentiment: { type: "string" },
score: { type: "number" },
},
},
},
}),
},
},
},
server,
),
);
app.post("/api/analyze", (req, res) => {
const { text } = req.body;
// ... your logic
res.json({ sentiment: "positive", score: 0.95 });
});
エンドポイントごとの複数の支払いオプション
同じエンドポイントで複数のネットワークでの支払いを受け入れます:
"GET /api/data": {
accepts: [
{
scheme: "exact",
price: "$0.01",
network: "eip155:8453",
payTo: EVM_ADDRESS,
},
{
scheme: "exact",
price: "$0.01",
network: "eip155:84532",
payTo: EVM_ADDRESS,
},
],
description: "Data endpoint accepting Base mainnet or testnet",
}
CDP ファシリテータの使用 (認証済み)
Coinbase ファシリテータでの本番環境での使用 (メインネットをサポート):
npm install @coinbase/x402
const { facilitator } = require("@coinbase/x402");
const { HTTPFacilitatorClient } = require("@x402/core/server");
const facilitatorClient = new HTTPFacilitatorClient(facilitator);
const server = new x402ResourceServer(facilitatorClient);
server.register("eip155:8453", new ExactEvmScheme());
これには CDP_API_KEY_ID と CDP_API_KEY_SECRET 環境変数が必要です。これらは https://portal.cdp.coinbase.com から取得できます。
pay-for-service スキルでのテスト
サーバーが実行されたら、pay-for-service スキルを使用して支払いをテストします:
# Check the endpoint's payment requirements
npx awal@2.10.0 x402 details http://localhost:3000/api/example
# Make a paid request
npx awal@2.10.0 x402 pay http://localhost:3000/api/example
価格設定ガイドライン
| ユースケース | 推奨価格 |
|---|---|
| シンプルなデータ参照 | $0.001 - $0.01 |
| API プロキシ / エンリッチメント | $0.01 - $0.10 |
| 計算量の多いクエリ | $0.10 - $0.50 |
| AI 推論 | $0.05 - $1.00 |
チェックリスト
-
npx awal@2.10.0 addressでウォレットアドレスを取得する -
express,@x402/express,@x402/core,@x402/evm,@x402/extensionsをインストールする - ファシリテータクライアントで
x402ResourceServerを作成し、eip155:8453のExactEvmSchemeを登録する - 価格、説明、ディスカバリー拡張機能を含むルートを定義する (ルートが宣言されると Bazaar が自動登録される)
- 保護されたルートの前に支払いミドルウェアを登録する
- ヘルス/ステータスエンドポイントを支払いミドルウェアの前に保つ
-
curl(HTTP 402 を取得する必要があります) とnpx awal@2.10.0 x402 pay(HTTP 200 を取得する必要があります) でテストする - 他のエージェントがサービスを検出して使用できるようにアナウンスする
ライセンス: MIT(寛容ライセンスのため全文を引用しています) · 原本リポジトリ
詳細情報
- 作者
- coinbase
- ライセンス
- MIT
- 最終更新
- 不明
Source: https://github.com/coinbase/agentic-wallet-skills / ライセンス: MIT
関連スキル
doubt-driven-development
重要な判断はすべて、本番環境への展開前に新しい視点から対抗的レビューを実施します。速度より正確性が重要な場合、不慣れなコードを扱う場合、本番環境・セキュリティに関わるロジック・取り消し不可の操作など影響度が高い場合、または後でバグを修正するよりも今検証する方が効率的な場合に活用してください。
apprun-skills
TypeScriptを使用したAppRunアプリケーションのMVU設計に関する総合的なガイダンスが得られます。コンポーネントパターン、イベントハンドリング、状態管理(非同期ジェネレータを含む)、パラメータと保護機能を備えたルーティング・ナビゲーション、vistestを使用したテストに対応しています。AppRunコンポーネントの設計・レビュー、ルートの配線、状態フローの管理、AppRunテストの作成時に活用してください。
desloppify
コードベースのヘルスチェックと技術負債の追跡ツールです。コード品質、技術負債、デッドコード、大規模ファイル、ゴッドクラス、重複関数、コードスメル、命名規則の問題、インポートサイクル、結合度の問題についてユーザーが質問した場合に使用してください。また、ヘルススコアの確認、次の改善項目の提案、クリーンアップ計画の作成をリクエストされた際にも対応します。29言語に対応しています。
debugging-and-error-recovery
テストが失敗したり、ビルドが壊れたり、動作が期待と異なったり、予期しないエラーが発生したりした場合に、体系的な根本原因デバッグをガイドします。推測ではなく、根本原因を見つけて修正するための体系的なアプローチが必要な場合に使用してください。
test-driven-development
テスト駆動開発により実装を進めます。ロジックの実装、バグの修正、動作の変更など、あらゆる場面で活用できます。コードが正常に動作することを証明する必要がある場合、バグ報告を受けた場合、既存機能を修正する予定がある場合に使用してください。
incremental-implementation
変更を段階的に実施します。複数のファイルに影響する機能や変更を実装する場合に使用してください。大量のコードを一度に書こうとしている場合や、タスクが一度では完結できないほど大きい場合に活用します。