Skip to main content

Full Client

createX402r() returns a client with all action groups. No type restrictions.
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.
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 enforce access control.

Config Reference

FieldTypeRequiredNotes
publicClientPublicClientYesviem public client for reads
walletClientWalletClientNoRequired for writes. Role presets throw without it.
operatorAddressAddressYesYour deployed PaymentOperator
chainIdnumberNoResolves from publicClient.chain when omitted
networkstringNoEIP-155 network ID (for example, 'eip155:84532'). Alternative to chainId.
escrowPeriodAddressAddressNoActivates escrow group
refundRequestAddressAddressNoActivates refund group
refundRequestEvidenceAddressAddressNoActivates evidence group (requires refundRequestAddress)
freezeAddressAddressNoActivates freeze group
paymentIndexRecorderHookAddressAddressNoActivates query group
paymentStorePaymentStoreNoCustom storage layer for payment lookups
eventFromBlockbigintNoStarting block for event-based payment lookups

Action Groups

GroupMethodsRequired config
payment9Always available
operator8Always available
watch4Always available
escrow3escrowPeriodAddress
refund14refundRequestAddress
evidence4refundRequestEvidenceAddress
freeze3freezeAddress
query3paymentIndexRecorderHookAddress
Groups without their required address are undefined on the client. Use optional chaining:
await client.escrow?.isDuringEscrow(paymentInfo) // undefined if no escrowPeriodAddress

Extend

Add custom action groups with .extend():
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:
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.
const { verified, reputation } = await extended.identity.check(
  agentId,
  agentAddress,
  reviewerAddresses, // optional
)
ParameterTypeDescription
agentIdbigintThe agent’s on-chain ID
addressAddressThe address claiming to own the agent ID
reviewersreadonly Address[]Optional list of reviewer addresses for reputation lookup
Returns CheckAgentResult:
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.
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.

Next steps

Merchant Guide

Accept payments and capture funds.

Deploy Operator

Get the addresses for your client config.