Skip to content

Commit 00b8adf

Browse files
[Docs] Simplify x402 documentation (#8173)
1 parent ae3dfa3 commit 00b8adf

File tree

7 files changed

+87
-37
lines changed

7 files changed

+87
-37
lines changed

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/account-abstraction/settings/SponsorshipPolicies/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ export function AccountAbstractionSettingsPage(
552552
you build your own rules.{" "}
553553
<UnderlineLink
554554
className="text-primary-500"
555-
href="https://portal.thirdweb.com/wallets/smart-wallet/sponsorship-rules#setting-up-a-server-verifier"
555+
href="https://portal.thirdweb.com/transactions/policies#server-verifier"
556556
rel="noopener noreferrer"
557557
target="_blank"
558558
>

apps/portal/src/app/payments/sidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const sidebar: SideBar = {
8282
},
8383
{
8484
href: `${paymentsSlug}/x402/facilitator`,
85-
name: "Facilitator API",
85+
name: "Facilitator",
8686
},
8787
],
8888
name: "x402",

apps/portal/src/app/payments/x402/client/page.mdx

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -68,46 +68,18 @@ The client library wraps the native `fetch` API and handles:
6868
<TabsContent value="http">
6969
## Prepare Payment
7070

71-
Create a signed payment header from the authenticated user to include in your API request:
71+
Fetch any x402-compatible API and automatically handle payment flows when APIs return a `402 Payment Required` response using the authenticated wallet.
7272

73-
### Making the Paid Request
74-
75-
After preparing the payment, include it in your API request:
73+
Only requires passing a 'url' and 'from' query parameters with the authenticated wallet address (server or user wallet) to complete the payment.
7674

7775
```bash
78-
# First, make the initial request to get payment requirements
79-
curl -X GET https://api.example.com/paid-endpoint
80-
81-
# Response will be 402 Payment Required with payment details
82-
# {
83-
# "x402Version": 1,
84-
# "accepts": [...payment requirements...],
85-
# "error": "Payment required"
86-
# }
87-
88-
# Select one of the payment methods, and sign the payment authorization using the API
89-
curl -X POST https://api.thirdweb.com/v1/payments/x402/prepare \
76+
curl -X POST https://api.thirdweb.com/v1/payments/x402/fetch?url=https://api.example.com/premium&from=0x1234... \
9077
-H "Content-Type: application/json" \
91-
-H "Authorization: Bearer <user-access-token>" \
92-
-d '{
93-
"from": "0x1234...",
94-
"paymentRequirements": { ... }
95-
}'
96-
97-
# Response will contain the signed payment header
98-
# {
99-
# "paymentPayload": { ... },
100-
# "paymentHeader": "..." // base64 encoded payment header
101-
# }
102-
103-
# Finally, make the request with the payment header
104-
curl -X GET https://api.example.com/paid-endpoint \
105-
-H "X-PAYMENT: <base64-encoded-payment>"
78+
-H "Authorization: Bearer <user-wallet-token>" \
79+
-d '{ ... }' # request body passed through to the url called.
10680
```
10781

108-
## API Reference
109-
110-
<OpenApiEndpoint path="/v1/payments/x402/prepare" method="POST" />
82+
<OpenApiEndpoint path="/v1/payments/x402/fetch" method="POST" />
11183

11284
</TabsContent>
11385
</Tabs>

apps/portal/src/app/payments/x402/facilitator/page.mdx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Tabs, TabsList, TabsTrigger, TabsContent, OpenApiEndpoint, Callout } from "@doc";
22
import { TypeScriptIcon, EngineIcon } from "@/icons";
33

4-
# Facilitator API
4+
# Facilitator
55

66
The facilitator is a service that handles verifying and submitting x402 payments. It uses your own [server wallet](/wallets/server) and leverages EIP-7702 to submit transactions gaslessly.
77

@@ -16,6 +16,13 @@ The thirdweb facilitator is compatible with any x402 backend and middleware libr
1616

1717
You can view all transactions processed by your facilitator in your project dashboard.
1818

19+
## Chain and token support
20+
21+
Our facilitator supports payments on any EVM chain, as long as the payment token supports either:
22+
23+
- ERC-2612 permit (most ERC20 tokens)
24+
- ERC-3009 sign with authorization (USDC on all chains)
25+
1926
<Tabs defaultValue="typescript">
2027
<TabsList>
2128
<TabsTrigger value="typescript" className="flex items-center [&>p]:mb-0">

apps/portal/src/app/payments/x402/page.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const fetchWithPay = wrapFetchWithPayment(fetch, client, wallet);
3333
const response = await fetchWithPay('https://api.example.com/paid-endpoint');
3434
```
3535

36+
You can also use the thirdweb API to fetch any x402 compatible endpoint and pay for it with the authenticated wallet. See the [client side docs](/payments/x402/client) for more details.
37+
3638
## Server Side
3739

3840
To make your API calls payable, use the `settlePayment` function in a middleware or endpoint:
@@ -77,6 +79,8 @@ export async function GET(request: Request) {
7779
}
7880
```
7981

82+
You can also create middlewares to handle payment for multiple endpoints, see the [server side docs](/payments/x402/server) for more details. The [facilitator](/payments/x402/facilitator) handles settling the payment onchain using your own server wallet.
83+
8084
## Going Further
8185

8286
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 mt-6">
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Gas Sponsorship Policies
2+
3+
Sponsorship policies are a way to control the execution of sponsored transactions on your account.
4+
5+
You can use them to:
6+
7+
- Set global spend limits.
8+
- Restrict sponsorship to a particular chain.
9+
- Restrict sponsorship to a particular contract.
10+
- Allow/Disallow specific wallets
11+
- Setup your own server verifier.
12+
13+
These policies can be set from your project dashboard, under project > account abstraction > settings.
14+
15+
## Server Verifier
16+
17+
The most flexible and powerful way to control the execution of sponsored transactions is to setup your own server verifier.
18+
19+
In the project dashboard, under project > account abstraction > settings, setup your backend URL and any additional headers you need to pass to the verifier.
20+
21+
On every user transaction, your backend will be called with the transaction data and the user's wallet address, your endpoint should return a boolean indicating whether the transaction should be sponsored.
22+
23+
### Backend endpoint specification:
24+
25+
Your backend will be called with the following request:
26+
27+
```http
28+
POST https://your-backend-url/verify-transaction
29+
Content-Type: application/json
30+
Referer: "https://api.thirdweb.com",
31+
# additional custom headers
32+
33+
# request body
34+
{
35+
"clientId": string;
36+
"chainId": number;
37+
"userOp": {
38+
sender: string;
39+
targets: string[];
40+
gasLimit: string;
41+
gasPrice: string;
42+
data?: {
43+
targets: string[];
44+
callDatas: string[];
45+
values: string[];
46+
};
47+
}
48+
}
49+
```
50+
51+
Your backend should process the request, apply your own policy logic based on the request data and return the following JSON response:
52+
53+
```http
54+
HTTP/1.1 200 OK
55+
Content-Type: application/json
56+
57+
{
58+
"isAllowed": boolean;
59+
"reason"?: string;
60+
}
61+
```
62+
63+
The `isAllowed` field indicates whether the transaction should be sponsored or not. `reason` is an optional field that can be used to provide a reason for the decision.

apps/portal/src/app/transactions/sidebar.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export const sidebar: SideBar = {
4242
href: `${transactionsSlug}/session-keys`,
4343
name: "Session Keys",
4444
},
45+
{
46+
href: `${transactionsSlug}/policies`,
47+
name: "Sponsorship Policies",
48+
},
4549
],
4650
},
4751
{ separator: true },

0 commit comments

Comments
 (0)