Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions sdk/create-client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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')
```

<Tip>
`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.
</Tip>

#### 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

<CardGroup cols={3}>
Expand Down
2 changes: 1 addition & 1 deletion sdk/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bun add @x402r/sdk
```
</CodeGroup>

`@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:

Expand Down
Loading