diff --git a/sdk/create-client.mdx b/sdk/create-client.mdx index 5df2a78..cc1dd71 100644 --- a/sdk/create-client.mdx +++ b/sdk/create-client.mdx @@ -96,6 +96,85 @@ const extended = client.extend( const payments = await extended.query.getPayerPayments(payerAddress) ``` +### ERC-8004 plugin + +The `erc8004Actions()` plugin adds on-chain identity, reputation, and service discovery. Registry addresses are resolved automatically from the chain config, but you can override them via options. + +```typescript +import { createX402r, erc8004Actions } from '@x402r/sdk' + +const client = createX402r({ publicClient, walletClient, operatorAddress: '0x...' }) + .extend(erc8004Actions()) + +// Identity +const isReg = await client.identity.isRegistered('0xABC...') +const txHash = await client.identity.register('https://example.com/agent.json') +const verified = await client.identity.verifyAgentId(7n, '0xABC...') +const agent = await client.identity.resolveAgent(7n) + +// Reputation +await client.reputation.rate(7n, 90) +const summary = await client.reputation.getSummary(7n, ['0xReviewer1...']) +await client.reputation.giveFeedback(7n, { + value: 500n, + valueDecimals: 2, + tag1: 'quality', + tag2: 'x402', +}) + +// Discovery +const endpoint = await client.discovery.resolveServiceEndpoint(7n, 'x402r.arbiter') +``` + + +`rate()` is a convenience wrapper around `giveFeedback()` that accepts a 0-100 integer score and uses the default tags (`starred` / `x402`). Use `giveFeedback()` when you need custom tags or decimal precision. + + +#### Plugin options + +| Option | Type | Default | Description | +|--------|------|---------|-------------| +| `registryAddress` | `Address` | Auto-resolved | Identity registry address override | +| `reputationRegistryAddress` | `Address` | Auto-resolved | Reputation registry address override | +| `defaultTag1` | `string` | `'starred'` | Default `tag1` for `rate()` and `getSummary()` | +| `defaultTag2` | `string` | `'x402'` | Default `tag2` for `rate()` and `getSummary()` | + +#### Identity methods + +| Method | Parameters | Returns | Description | +|--------|-----------|---------|-------------| +| `register` | `agentURI?: string` | `Hash` | Register the connected wallet as an agent | +| `verifyAgentId` | `agentId: bigint, claimedAddress: Address` | `boolean` | Check if an agent ID belongs to the claimed address | +| `resolveAgent` | `agentId: bigint` | `ResolvedAgent` | Look up full agent record by ID | +| `isRegistered` | `address: Address` | `boolean` | Check if an address is registered | + +#### Reputation methods + +| Method | Parameters | Returns | Description | +|--------|-----------|---------|-------------| +| `rate` | `agentId: bigint, score: number` | `Hash` | Submit a 0-100 rating using default tags | +| `getSummary` | `agentId: bigint, reviewers: Address[], options?` | `ReputationSummary` | Aggregate reputation from specific reviewers | +| `giveFeedback` | `agentId: bigint, params: Erc8004GiveFeedbackParams` | `Hash` | Submit feedback with full control over tags and metadata | + +#### Discovery methods + +| Method | Parameters | Returns | Description | +|--------|-----------|---------|-------------| +| `resolveServiceEndpoint` | `agentId: bigint, serviceName: string` | `ResolvedServiceEndpoint` | Resolve an agent's service endpoint by name | + +#### Re-exported types + +The following types from `@x402r/erc8004` are re-exported by `@x402r/sdk` for convenience: + +- `ResolvedAgent` - full agent identity record +- `ReputationSummary` - aggregated reputation data +- `ResolvedServiceEndpoint` - resolved service endpoint record +- `Erc8004PluginOptions` - plugin configuration +- `Erc8004GiveFeedbackParams` - parameters for `giveFeedback()` +- `Erc8004IdentityActions` - identity namespace type +- `Erc8004ReputationActions` - reputation namespace type +- `Erc8004DiscoveryActions` - discovery namespace type + ## Next Steps diff --git a/sdk/overview.mdx b/sdk/overview.mdx index 4b43e59..ddd1dc5 100644 --- a/sdk/overview.mdx +++ b/sdk/overview.mdx @@ -32,7 +32,7 @@ bun add @x402r/sdk ``` -`@x402r/sdk` is the only package most developers need. It includes role-scoped client factories, 8 action groups (payment, escrow, refund, evidence, freeze, query, operator, watch), and an `.extend()` plugin system. +`@x402r/sdk` is the only package most developers need. It includes role-scoped client factories, 8 action groups (payment, escrow, refund, evidence, freeze, query, operator, watch), and an `.extend()` plugin system. The `erc8004Actions()` plugin adds on-chain identity, reputation, and service discovery via [ERC-8004](/sdk/create-client#erc-8004-plugin). For low-level access to contract ABIs and deploy utilities: