Skip to main content
Use a Swig wallet to pay for APIs and other HTTP resources that return 402 Payment Required. Pass the response to the Developer SDK to prepare a payment transaction. Your application authorizes and signs the payment, then sends the original request again with a PAYMENT-SIGNATURE header. The resource provider’s facilitator verifies and settles the payment.

How the payment flow works

The Swig API prepares the payment transaction but does not submit or settle it.

Before you begin

You need:
  • a configured SwigClient and an existing Swig wallet
  • an Ed25519 or secp256r1 authority assigned to a role permitted to invoke the token program and spend the selected mint
  • an x402 version 2 resource offering the exact payment scheme on the wallet’s Solana mainnet or devnet network
  • the wallet’s canonical associated token account, already created and funded with enough of the requested token
  • the recipient’s canonical associated token account, already created for the payTo owner and mint
  • a legacy SPL Token mint or a Token-2022 mint with no extensions; Token-2022 token accounts may have no extensions or only ImmutableOwner
  • a facilitator that supports Swig smart-wallet verification
Other Token-2022 mint and token-account extensions are not supported. For passkey payments, the facilitator must also permit Solana’s secp256r1 signature-verification program.

Pay for a resource

These examples use an Ed25519 requester and assume your application provides the Swig wallet identifiers, requester public key, resource URL, and signing callback. signTransaction / sign_transaction receives the base64 serialized transaction and prepared record, then returns the signed base64 transaction. See Signers for Ed25519 and passkey signing patterns. The examples request a resource with GET and no additional headers. In your integration, repeat the original request with the same URL, method, body, and existing headers, adding the generated PAYMENT-SIGNATURE header.
TypeScript

Choose a payment offer

Each entry in the challenge’s accepts array is a payment offer. When the index is omitted, Swig selects the first supported offer using the exact scheme on the wallet’s Solana network. The result preserves that offer’s position in the original accepts array. Pass an index when your application has already chosen an offer:
TypeScript
An explicit index must identify a supported exact offer on the wallet’s Solana network. Swig returns an error instead of falling back to another offer when the selected offer is incompatible.

Understand the prepared result

prepareFromResponse() / prepare_from_response() returns: After signing, createX402Payment() / create_x402_payment() returns:

Run the complete example

x402 Payment Example

Run a resource provider, facilitator, and Swig payer through the complete challenge, preparation, signing, settlement, and paid-resource flow.

Signers

Connect application-owned Ed25519 keys or passkeys.

Add Roles and Permissions

Assign a requester authority to an existing Swig wallet.

Transfer SOL and Tokens

Prepare ordinary wallet transfers outside the x402 flow.

Transaction API

Integrate with Swig’s transaction endpoints directly.