> ## Documentation Index
> Fetch the complete documentation index at: https://docs.x402r.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Create x402r Client

> Client factory, role presets, and configuration reference.

### Full Client

`createX402r()` returns a client with all action groups. No type restrictions.

```typescript theme={null}
import { createX402r } from '@x402r/sdk'

const client = createX402r({
  publicClient,
  walletClient,                              // optional for read-only
  operatorAddress: '0x...',                  // from deploy result
  escrowPeriodAddress: '0x...',              // from deploy result
  refundRequestAddress: '0x...',             // from deploy result
  refundRequestEvidenceAddress: '0x...',     // from deploy result
  freezeAddress: '0x...',                    // from deploy result
})

await client.payment.getAmounts(paymentInfo)
await client.refund?.request(paymentInfo, amount)
await client.escrow?.isDuringEscrow(paymentInfo)
```

### Role Presets

Role presets call `createX402r()` internally and narrow the TypeScript types so autocomplete only shows relevant methods. All three require `walletClient`.

```typescript theme={null}
import {
  createPayerClient,
  createMerchantClient,
  createArbiterClient,
} from '@x402r/sdk'

const payer = createPayerClient({ publicClient, walletClient, operatorAddress: '0x...' })
const merchant = createMerchantClient({ publicClient, walletClient, operatorAddress: '0x...' })
const arbiter = createArbiterClient({ publicClient, walletClient, operatorAddress: '0x...' })
```

Type narrowing is a DX convenience, not a security boundary. On-chain [conditions](/contracts/conditions/overview) enforce access control.

### Config Reference

| Field                             | Type           | Required | Notes                                                                         |
| --------------------------------- | -------------- | :------: | ----------------------------------------------------------------------------- |
| `publicClient`                    | `PublicClient` |    Yes   | viem public client for reads                                                  |
| `walletClient`                    | `WalletClient` |    No    | Required for writes. Role presets throw without it.                           |
| `operatorAddress`                 | `Address`      |    Yes   | Your deployed PaymentOperator                                                 |
| `chainId`                         | `number`       |    No    | Resolves from `publicClient.chain` when omitted                               |
| `network`                         | `string`       |    No    | EIP-155 network ID (for example, `'eip155:84532'`). Alternative to `chainId`. |
| `escrowPeriodAddress`             | `Address`      |    No    | Activates `escrow` group                                                      |
| `refundRequestAddress`            | `Address`      |    No    | Activates `refund` group                                                      |
| `refundRequestEvidenceAddress`    | `Address`      |    No    | Activates `evidence` group (requires `refundRequestAddress`)                  |
| `freezeAddress`                   | `Address`      |    No    | Activates `freeze` group                                                      |
| `paymentIndexRecorderHookAddress` | `Address`      |    No    | Activates `query` group                                                       |
| `paymentStore`                    | `PaymentStore` |    No    | Custom storage layer for payment lookups                                      |
| `eventFromBlock`                  | `bigint`       |    No    | Starting block for event-based payment lookups                                |

### Action Groups

| Group      | Methods | Required config                   |
| ---------- | ------- | --------------------------------- |
| `payment`  | 9       | Always available                  |
| `operator` | 8       | Always available                  |
| `watch`    | 4       | Always available                  |
| `escrow`   | 3       | `escrowPeriodAddress`             |
| `refund`   | 14      | `refundRequestAddress`            |
| `evidence` | 4       | `refundRequestEvidenceAddress`    |
| `freeze`   | 3       | `freezeAddress`                   |
| `query`    | 3       | `paymentIndexRecorderHookAddress` |

Groups without their required address are `undefined` on the client. Use optional chaining:

```typescript theme={null}
await client.escrow?.isDuringEscrow(paymentInfo) // undefined if no escrowPeriodAddress
```

### Extend

Add custom action groups with `.extend()`:

```typescript theme={null}
import { createX402r, queryActions } from '@x402r/sdk'

const client = createX402r({ publicClient, operatorAddress: '0x...' })

const extended = client.extend(
  queryActions('0xHookAddress', { eventFromBlock: 100000n })
)

// extended.query is now defined
const payments = await extended.query.getPayerPayments(payerAddress)
```

### ERC-8004 plugin

The `erc8004Actions` plugin adds `identity`, `reputation`, and `discovery` action groups for on-chain agent identity and reputation:

```typescript theme={null}
import { createX402r, erc8004Actions } from '@x402r/sdk'

const client = createX402r({ publicClient, walletClient, operatorAddress: '0x...' })

const extended = client.extend(erc8004Actions())

// Identity
await extended.identity.register('https://my-agent.example.com')
await extended.identity.verifyAgentId(42n, '0xAgentAddress...')
await extended.identity.resolveAgent(42n)
await extended.identity.isRegistered('0xAgentAddress...')

// Verify + reputation in one call
const result = await extended.identity.check(42n, '0xAgentAddress...', [
  '0xReviewer1...',
  '0xReviewer2...',
])
console.log('Verified:', result.verified)
console.log('Reputation:', result.reputation) // ReputationSummary | null

// Reputation
await extended.reputation.rate(42n, 85)
await extended.reputation.getSummary(42n, ['0xReviewer...'])

// Discovery
await extended.discovery.resolveServiceEndpoint(42n, 'arbiter')
```

#### `identity.check()`

Verifies an agent's on-chain identity and optionally fetches their reputation summary in a single call. Both the verification and reputation lookup run in parallel.

```typescript theme={null}
const { verified, reputation } = await extended.identity.check(
  agentId,
  agentAddress,
  reviewerAddresses, // optional
)
```

| Parameter   | Type                 | Description                                               |
| ----------- | -------------------- | --------------------------------------------------------- |
| `agentId`   | `bigint`             | The agent's on-chain ID                                   |
| `address`   | `Address`            | The address claiming to own the agent ID                  |
| `reviewers` | `readonly Address[]` | Optional list of reviewer addresses for reputation lookup |

Returns `CheckAgentResult`:

```typescript theme={null}
interface CheckAgentResult {
  verified: boolean
  reputation: ReputationSummary | null
}
```

If you omit `reviewers` or pass an empty array, `reputation` is `null` and only on-chain verification runs.

<Tip>
  For standalone helpers that extract identity data from x402 extension responses without a client instance, use the `extractArbiterIdentity`, `extractReputationRegistrations`, and `fetchArbiterIdentity` exports from `@x402r/sdk`.
</Tip>

## Next steps

<CardGroup cols={3}>
  <Card title="Merchant Guide" icon="store" href="/sdk/merchant/quickstart">
    Accept payments and capture funds.
  </Card>

  <Card title="Deploy Operator" icon="rocket" href="/sdk/deploy-operator">
    Get the addresses for your client config.
  </Card>
</CardGroup>
