A fork of the x402 facilitator service customized for the OpenGradient network, with added support for LLM TEE (Trusted Execution Environment) inference settlement. This service handles payment verification and settlement for x402 payments, plus on-chain settlement of LLM inference input/output hashes for verifiable AI.
The facilitator provides three main endpoints:
/verify: Verifies x402 payment payloads/settle: Settles x402 payments and records LLM inference hashes on-chain/supported: Returns the payment kinds supported by the facilitator
In addition to standard x402 payment settlement, this service supports settling LLM inference results from TEE environments. When an LLM inference is performed in a TEE, the input and output hashes are recorded on-chain via the Settlement contract, providing cryptographic proof of the inference.
Settlement types:
settle: Records input/output hash pair on-chainsettle-metadata: Records hashes with additional model infosettle-batch: Batches multiple settlements into a Merkle tree root (with tree data uploaded to Walrus)
- Node.js v20+ (install via nvm)
- pnpm v10 (install via pnpm.io/installation)
- A valid Ethereum private key (for OpenGradient devnet) and/or Solana private key
- OpenGradient devnet tokens for transaction fees
- Install and build all packages:
pnpm install
pnpm build- Create a
.envfile with the following variables:
# Required (at least one)
EVM_PRIVATE_KEY=0xYourPrivateKey
SVM_PRIVATE_KEY=base58EncodedSolanaPrivateKey
# Required for LLM TEE settlement
X402_SETTLEMENT_CONTRACT=0xYourSettlementContractAddress
# Optional
PORT=3000
SVM_RPC_URL=https://custom-solana-rpc.com
# Optional: Enable async queue processing
REDIS_HOST=localhost
REDIS_PORT=6379
# Optional: Batch settlement config
SETTLEMENT_BATCH_SIZE=20
SETTLEMENT_BATCH_TIMEOUT=60000
WALRUS_PUBLISHER_URL=http://localhost:9002/v1/blobs- Start the server:
pnpm devThe server will start on http://localhost:3000
Returns information the payment kinds that the facilitator supports.
Sample Response
{
"kinds": [
{
"x402Version": 1,
"scheme": "exact",
"network": "og-devnet"
},
{
"x402Version": 1,
"scheme": "exact",
"network": "solana-devnet",
"extra": {
"feePayer": "SolanaAddress"
}
}
]
}Returns information about the verify endpoint.
Verifies an x402 payment payload.
Request body:
{
paymentPayload: PaymentPayload;
paymentRequirements: PaymentRequirements;
}Returns information about the settle endpoint.
Settles an x402 payment by signing and broadcasting the transaction. For LLM TEE inference settlement, include additional headers.
Request body:
{
paymentPayload: PaymentPayload;
paymentRequirements: PaymentRequirements;
}Optional headers for LLM TEE settlement:
x-input-hash: Hash of the LLM inference inputx-output-hash: Hash of the LLM inference outputx-settlement-type: Settlement type (settle,settle-metadata, orsettle-batch)
When Redis is configured, settlement requests are queued and processed asynchronously by a worker. This enables:
- Non-blocking API responses
- Batch settlement of multiple inference results into a single Merkle tree
- Automatic upload of batch data to Walrus for data availability
The SettlementRelay contract (contracts/settlement.sol) emits events for:
Settlement(inputHash, outputHash)- Single inference settlementSettlementWithMetadata(inputHash, outputHash, modelInfo, inputData, outputData)- Settlement with model metadataBatchSettlement(merkleRoot, batchSize)- Batched settlements via Merkle root
- EVM:
og-devnet(OpenGradient devnet, chain ID: 10744) - SVM:
solana-devnet