Agents pay for APIs without knowing if they're any good. There's no verified track record, no tamper-proof history of whether an API actually delivered results. You trust the description on the marketplace page and hope for the best.
ERC-8004 fixes that. The @relai-fi/x402 SDK now ships four plugins and utilities that let you publish, record, and read verifiable on-chain reputation — before and after every payment.
What Is ERC-8004?
ERC-8004 is a standard for AI agent identity and reputation. It defines two on-chain registries:- IdentityRegistry — mints a non-transferable NFT representing the agent or API
- ReputationRegistry — records structured feedback over time: success rate, response time, and any tagged metric
- EVM (SKALE Base Sepolia) — zero-gas transactions via the ERC-8004 Solidity contracts; used by
feedback()andscore() - Solana — native implementation via the
8004-solanaprogram using MPL Core NFTs as agent identity anchors; used bysolanaFeedback()
assetPubkey on Solana.
The Four Tools
1. score() — Show reputation before payment
Before an agent decides whether to pay, it should know what it's paying for. The score() plugin injects your API's live on-chain reputation directly into the 402 response:
import Relai from '@relai-fi/x402/server'
import { score } from '@relai-fi/x402/plugins'
const relai = new Relai({
network: 'base',
plugins: [
score({ agentId: process.env.ERC8004_AGENT_ID! }),
],
})
Every agent that receives your 402 challenge now sees:
{
"x402Version": 2,
"accepts": [...],
"extensions": {
"score": {
"agentId": "5",
"feedbackCount": 142,
"successRate": 98.6,
"avgResponseMs": 312
}
}
}
The score is fetched directly from the SKALE RPC — no REST API, no third-party dependency. Results are cached for 5 minutes by default.
2. feedback() — Build your reputation automatically
The feedback() plugin submits successRate and responseTime on-chain after every settled x402 payment. This is what populates the score that score() reads. It runs fire-and-forget — your response is never blocked.
import Relai from '@relai-fi/x402/server'
import { score, feedback } from '@relai-fi/x402/plugins'
const relai = new Relai({
network: 'base',
plugins: [
score({ agentId: process.env.ERC8004_AGENT_ID! }),
feedback({ agentId: process.env.ERC8004_AGENT_ID! }),
],
})
The feedback wallet needs CREDIT tokens on SKALE Base for gas — but since SKALE transactions are free, CREDIT is just the access token. Get it from the SKALE sFUEL station.
Over time, every API call contributes to a rolling on-chain average that any agent or marketplace can verify independently.
3. solanaFeedback() — Native Solana reputation
For APIs registered via the native 8004-solana program (Solana MPL Core NFT registry), there's a dedicated Solana feedback plugin. It works the same way as feedback() but uses the assetPubkey of the Solana agent NFT instead of an EVM agentId.
import Relai from '@relai-fi/x402/server'
import { solanaFeedback } from '@relai-fi/x402/plugins'
const relai = new Relai({
network: 'solana',
plugins: [
solanaFeedback({
assetPubkey: process.env.SOLANA_AGENT_ASSET!,
}),
],
})
Requires npm install 8004-solana. The plugin uses dynamic import so it doesn't affect bundle size if you're not using it.
Both base58 and JSON array formats are supported for the wallet private key, matching how Solana keypairs are typically stored.
4. submitRelayFeedback() — Reputation from the relay's perspective
Relay servers and marketplaces have a unique vantage point: they observe many API calls across many providers. submitRelayFeedback lets them record their own observations on-chain — from a separate wallet, to avoid self-feedback restrictions.
This isn't a plugin. It's a standalone utility you call from your own code after each external API call:
import { submitRelayFeedback } from '@relai-fi/x402/relay-feedback'
const start = Date.now()
const result = await callExternalApi('/v1/data')
submitRelayFeedback({
agentId: '5',
success: result.ok,
responseTimeMs: Date.now() - start,
endpoint: '/v1/data',
})
The relay uses FEEDBACK_WALLET_PRIVATE_KEY — a different key from the API owner's wallet. Multiple independent sources submitting feedback for the same agentId makes the on-chain record harder to game.
Why This Matters for Agents
The ERC-8004 standard was designed for exactly this scenario: autonomous agents making economic decisions without human oversight. An agent calling a paid API has no recourse if the API underperforms after payment. With on-chain reputation:
- Before payment: check
extensions.scorein the 402 response — live success rate and response time from the chain - After payment: reputation updates automatically — future agents benefit from your experience
- Cross-marketplace: the same agentId is readable by any chain client, not just RelAI
Setup in Five Minutes
npm install @relai-fi/x402
# .env — EVM / SKALE (for score() and feedback())
ERC8004_IDENTITY_REGISTRY=0x8724C768547d7fFb1722b13a84F21CCF5010641f
ERC8004_REPUTATION_REGISTRY=0xe946A7F08d1CC0Ed0eC1fC131D0135d9c0Dd7d9D
ERC8004_RPC_URL=https://base-sepolia-testnet.skalenodes.com/v1/jubilant-horrible-ancha
ERC8004_AGENT_ID=5
BACKEND_WALLET_PRIVATE_KEY=0x... # needs CREDIT tokens on SKALE Base
SOLANA_AGENT_ASSET=GH93tGR8... # MPL Core NFT pubkey
SOLANA_8004_FEEDBACK_KEY=... # base58 or JSON array
SOLANA_8004_CLUSTER=mainnet-beta
SOLANA_8004_RPC_URL=https://... # Helius / QuickNode recommended
Your ERC8004_AGENT_ID is visible on the API page sidebar under On-chain Identity and in the Dashboard under the Endpoints tab.
Full Reference
See the SDK Plugins documentation for the complete configuration reference, environment variable list, and examples for all four plugins.
