Skip to main content

Make Payments with Viem

Make payments to Armory-protected APIs using Viem wallets. hooks are lifecycle callbacks. extensions are protocol fields on x402 payloads/challenges. They work together but are separate. When payment verification fails on retry (402), Armory surfaces server detail (for example insufficient_funds) in the thrown error.

Basic Payment

Prefer the Armory object (method-based API)

For multi-call flows the new createArmory object bundles the payment client with method helpers and automatic server option selection.
createArmory handles 402 responses from PAYMENT-REQUIRED and selects from accepts[]. Without hooks it uses the first compatible option. Add @armory-sh/client-hooks to apply chain/token/cheapest preference logic. The object exposes .get, .post, .put, .delete, .patch, .pay, and a .call shorthand for GET requests. Use armory.pay(url, { method: 'PATCH', body }) when you need to override the HTTP method; call .call for a simple GET.

With Custom Amount

Using Public Client

With Extension Hooks

For servers that require protocol extensions (like Sign-In-With-X):

Multiple Requests

Reuse the client for multiple requests:

Custom Extensions

Create custom hooks for your own extensions: