# x402 Protocol Integration

### What is the x402 protocol?

The x402 protocol is an open framework that enables machine-to-machine payments on the web by standardizing how clients and services exchange value over HTTP. Building on the HTTP 402 "Payment Required" status code, x402 establishes a clear transaction flow where a server responds to resource requests with payment instructions (including amount and recipient), the client provides payment authorization, a payment facilitator verifies and settles the transaction, and the server delivers the requested resource along with payment confirmation.&#x20;

This protocol allows automated agents, crawlers, and digital services to conduct transactions programmatically without requiring traditional accounts, subscriptions, or API keys. By creating a common language for web-based payments, x402 enables new monetization models such as pay-per-use access, micropayments for AI agents purchasing from multiple merchants, and flexible payment schemes including immediate settlement via stablecoins or deferred settlement through traditional payment rails like credit cards and bank accounts.

{% hint style="info" %}
[The x402 Foundation](https://blog.cloudflare.com/x402/) is a collaborative initiative being established by Cloudflare and Coinbase with the mission of encouraging widespread adoption of the x402 protocol.
{% endhint %}

### x402 and xANS-104 DataItems

We are proud to be the first team that has worked on the intersection of [x402 micropayments protocol and Arweave's ANS-104 data format](https://402.load.network/). We have integrated the x402 protocol in Load's custom HyperBEAM device ([\~s3@1.0 device](https://docs.load.network/load-hyperbeam/s3-1.0-device)), resulting in the first ever expirable, paywalled, privately shareable ANS-104 DataItems.

The x402 micropayments have been integrated on the ANS-104 gateway sidecar level of the s3 device. [check out source code](https://github.com/loadnetwork/load_hb/tree/s3-node-1/native/s3_nif/src/sidecar).

### Creating x402 paywalled private dataitems

There are two ways to create an x402 paywalled private expireable ANS-104 DataItem, the first is user friendly via the LCP dashboard, and the second is programmatic yet DIY, let's explore both methods.

#### x402 on Load Cloud Platform (LCP)

x402 has been integrated on LCP, making it possible for LCP users to create x402 paywalled, expirable links for their private objects (ANS-104 DataItems) on Load S3. The process is pretty simple and straightforward: fill in the parameters of the **Create Payment Link** request (set expiry , payee EOA, and USDC amount) and the dashboard will generate a ready-to-use x402 expirable DataItem URL.

<figure><img src="https://2353286269-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVZu43bMtQ8SUIRCIsqZc%2Fuploads%2FVxhfiNeauw7cWOis3ivJ%2Fimage.png?alt=media&#x26;token=62443fd3-de9c-46d4-b721-d9ed55b6e7a4" alt=""><figcaption></figcaption></figure>

<br>

<figure><img src="https://2353286269-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVZu43bMtQ8SUIRCIsqZc%2Fuploads%2FgAPqKiizMBVAq2xIK4li%2Fimage.png?alt=media&#x26;token=f28cefad-f42b-4301-bb0a-751c9620eafc" alt=""><figcaption></figcaption></figure>

#### x402 DIY

The DIY method means doing what the LCP dashboard abstracts, first you need to create a private LS3 ANS-104 Dataitem and upload it to your LCP bucket (load-s3-agent [reference](https://github.com/loadnetwork/load-s3-agent)):

```bash
curl -X POST https://load-s3-agent.load.network/upload/private \
  -H "Authorization: Bearer $load_acc_api_key" \
  -H "signed: true" \
  -H "bucket_name: $bucket_name" \
  -H "x-dataitem-name: $dataitem_name" \
  -H "x-folder-name: $folder_name" \ 
  -F "file=@path-signed-dataitem.ans104" \
  -F "content_type=application/octet-stream"
```

After that you have to generate the x402 signed shareable receipt using the HyperBEAM LS3 sidecar:

```bash
curl -X POST https://gateway.s3-node-1.load.network/sign/402 \
  -H "Authorization: Bearer $CONTACT_US" \
  -H "x-bucket-name: $bucket_name" \
  -H "x-load-acc: $load_acc_api_key" \
  -H "x-dataitem-key: $dataitem_key.ans104" \
  -H "x-402-address: $payee_eoa" \
  -H "x-402-amount: $usdc_amount" \
  -H "x-expires-minutes: $set_expiry"
```

this curl request will return a base64 string, you use it to share the x402 paywalled ANS-104 DataItem as following: `https://402.load.network/$base64_string`

<figure><img src="https://2353286269-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVZu43bMtQ8SUIRCIsqZc%2Fuploads%2FKEPs6utmf2i3mLLmquYL%2Fimage.png?alt=media&#x26;token=76dbc014-fd16-4bae-b4cc-9ce7454c877f" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.load.network/load-cloud-platform-lcp/x402-protocol-integration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
