Mogami
  • Home
  • Roadmap & ideas
  • x402 in French
  • Java client SDK
    • Getting started
    • Example client
  • Java server SDK
    • Getting started
    • Example server
    • Configuration
  • Faciliator server
    • Getting started
    • Verifications
  • Learning X402
    • Protocol explanation
      • Get /weather without X-PAYMENT
      • Get /weather with X-PAYMENT
      • Payment verification on server
      • Payment settlement on server
    • X402 hands-on
    • Useful links
  • Contact
    • Email
    • Twitter
Powered by GitBook
On this page
  1. Learning X402
  2. Protocol explanation

Get /weather with X-PAYMENT

PreviousGet /weather without X-PAYMENTNextPayment verification on server

Last updated 25 days ago

The user can directly call the /weather with a X-PAYMENT header containing the Payment Payload encoded with base 64 (definition here: ).

To do this, the client will have to generate this kind of JSON:

{
  "x402Version": 1,
  "scheme": "exact",
  "network": "base-sepolia",
  "payload": {
    "signature": "0x2d6a7588d6acca505cbf0d9a4a227e0c52c6c34008c8e8986a1283259764173608a2ce6496642e377d6da8dbbf5836e9bd15092f9ecab05ded3d6293af148b571c",
    "authorization": {
      "from": "0x857b06519E91e3A54538791bDbb0E22373e36b66",
      "to": "0x209693Bc6afc0C5328bA36FaF03C514EF312287C",
      "value": "10000",
      "validAfter": "1740672089",
      "validBefore": "1740672154",
      "nonce": "0xf3746613c2d920b5fdabc0856f2aeb2d4f88ee6037b8cc5d04a71a4462f13480"
      }
  }
}

In this JSON, there are two things : - Payment Payload (included as the X-PAYMENT header in base64 encoded JSON). - Inside this Payment payload, there is the payload field. This field is specific and depends on the scheme you set. For example, you can find read the exact payload specification here : .

Once you have build this JSON, use the code below to encode it and then, add it to the X-PAYMENT header of your query.

String encodedPaymentHeader = Base64
.getEncoder()
.withoutPadding()
.encodeToString(paymentHeader.getBytes(UTF_8));

If the payment is accepted and all the verification succeed, the query result will be displayed (in our case, it will be the weather).

https://github.com/coinbase/x402?tab=readme-ov-file#type-specifications
https://github.com/coinbase/x402/blob/main/specs/schemes/exact/scheme_exact_evm.md#x-payment-header-payload