Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# X402 Documentation

This folder contains the Mintlify documentation for X402 Protocol with emphasis on Sei Network integration.

## Running Locally

To run the documentation locally:

1. Install Mintlify CLI:
```bash
npm install -g mintlify
```

2. Start the dev server:
```bash
cd docs
mintlify dev
```

3. Open http://localhost:3000 to view the docs

## Deployment

This documentation is designed to be deployed with Mintlify hosting. The configuration is already set up in `mint.json`.
82 changes: 82 additions & 0 deletions docs/clients/fetch.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
title: "Fetch Client"
description: "Make paid HTTP requests with the native Fetch API and x402"
---

## Fetch Client Integration

Use x402 with the standard Fetch API to make paid HTTP requests. Perfect for both browser and Node.js environments.

## Installation

```bash
npm install @sei-js/x402-fetch viem dotenv
```

## Basic Usage

```typescript
import { config } from "dotenv";
import { Hex } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import {
wrapFetchWithPayment,
decodeXPaymentResponse,
} from "@sei-js/x402-fetch";

config();

const privateKey = process.env.PRIVATE_KEY as Hex;
const baseURL = process.env.RESOURCE_SERVER_URL as string; // e.g. http://localhost:4021
const endpointPath = process.env.ENDPOINT_PATH as string; // e.g. /weather
const url = `${baseURL}${endpointPath}`;

if (!baseURL || !privateKey || !endpointPath) {
console.error("Missing required environment variables");
process.exit(1);
}

// Create account from private key
const account = privateKeyToAccount(privateKey);

// Wrap fetch with payment handling
const fetchWithPayment = wrapFetchWithPayment(fetch, account);

// Make a paid request
fetchWithPayment(url, {
method: "GET",
})
.then(async (response) => {
const body = await response.json();
console.log("Response:", body);

// Decode the payment response
const paymentResponse = decodeXPaymentResponse(
response.headers.get("x-payment-response")!
);
console.log("Payment details:", paymentResponse);
})
.catch((error) => {
console.error("Error:", error.response?.data?.error);
});
```

## Environment Setup

Create a `.env` file with the required configuration:

```env
# Required: Your private key for making payments
PRIVATE_KEY=0xYourPrivateKeyHere

# Required: The server URL hosting the paid API
RESOURCE_SERVER_URL=http://localhost:4021

# Required: The endpoint path to access
ENDPOINT_PATH=/weather
```

<Warning>
**Security Note**: Never commit private keys to version control. Use
environment variables or secure key management services in production.
</Warning>
81 changes: 81 additions & 0 deletions docs/docs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"$schema": "https://mintlify.com/mint.json",
"name": "x402 Documentation",
"theme": "mint",
"logo": {
"dark": "https://cdn.sei.io/sei.svg",
"light": "https://cdn.sei.io/sei.svg"
},
"description": "Official documentation for x402 Protocol - HTTP micropayments for the Sei Network and beyond. Build paid APIs, premium content, and micropayment systems.",
"favicon": "/favicon.ico",
"colors": {
"primary": "#9E1F19",
"light": "#B52A2A",
"dark": "#780000"
},
"contextual": {
"options": ["copy", "chatgpt", "claude"]
},
"navigation": {
"global": {
"anchors": [
{
"anchor": "Sei Documentation",
"icon": "book-open-cover",
"href": "https://docs.sei.io"
},
{
"anchor": "GitHub",
"icon": "github",
"href": "https://github.com/sei-protocol/sei-x402"
},
{
"anchor": "Sei Network",
"icon": "globe",
"href": "https://sei.io"
}
]
},
"dropdowns": [
{
"dropdown": "Getting Started",
"icon": "rocket",
"pages": [
{
"group": "Introduction",
"pages": ["introduction", "overview", "quickstart"]
}
]
},
{
"dropdown": "Facilitators",
"description": "Verifying and settling payments",
"icon": "server",
"pages": [
{
"group": "Getting Started",
"pages": ["facilitators/introduction", "facilitators/example"]
}
]
},
{
"dropdown": "Client Integration",
"description": "Make x402 payments",
"icon": "code",
"pages": [
{
"group": "HTTP Clients",
"pages": ["clients/fetch"]
}
]
}
]
},
"footer": {
"socials": {
"github": "https://github.com/sei-protocol/sei-x402",
"discord": "https://discord.gg/sei",
"x": "https://x.com/SeiNetwork"
}
}
}
Loading