AgentTrust
AgentTrust
Integration guides
Integration guides

x402 facilitator

Add AgentTrust decisions to a Solana x402 service.

This guide is for a facilitator that already accepts x402 payment requests and wants AgentTrust decisions before settlement.

Integration points

StepFacilitator actionAgentTrust call
1parse payer, payee, mint, and amountnone
2check policyPOST /verify or gatePayment()
3return x402 denial or validation needTrustGate header builder
4settle paymentsingle Solana transaction
5emit feedbackTrustGate emit_feedback

Minimal Express mount

import express from "express";
import { mountTrustGate } from "@agenttrust-sdk/trustgate/express";

const app = express();
app.use(express.json());

await mountTrustGate(app, {
  rpcUrl: process.env.SOLANA_RPC_URL!,
  facilitatorKeypair,
  defaultPolicyId: 1,
  network: "solana-devnet",
  atomicityEnforced: true,
});

Verify request

POST /verify
Content-Type: application/json

{
  "payerAgentAsset": "payer-agent-asset-pubkey",
  "payeeAgentAsset": "payee-agent-asset-pubkey",
  "amount": "1000000",
  "mint": "mint-pubkey",
  "policyId": 1
}

Denial response

HTTP/1.1 402 Payment Required
X-Payment-Network: solana-devnet
X-Agent-Trust-Decision: Deny
X-Payment-Required: denied
X-Payment-Reason-Code: 6
X-Payment-Reason-Name: CounterpartyTierBelowMin

Validation response

HTTP/1.1 402 Payment Required
X-Payment-Network: solana-devnet
X-Agent-Trust-Decision: RequireValidation
X-Payment-Required: validation
X-Capability-Required: <32-byte-capability-hash>

Settlement rule

The facilitator must keep the policy gate, token transfer, and feedback emission in one Solana transaction once the settlement builder is wired. The SDK makes that requirement explicit with atomicityEnforced: true.

Source: trustgate/server/src/x402.ts, trustgate/sdk/src/express.ts.

repo github.com/mohit-1710/agenttrustnpm @agenttrust-sdk/trustgateMIT

On this page

⌘I