Skip to content

Commit 3335240

Browse files
committed
add gas free
1 parent 5a8e320 commit 3335240

14 files changed

Lines changed: 98 additions & 33 deletions

File tree

docs/x402/core-concepts/network-and-token-support.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,29 +100,39 @@ When configuring an `HTTP 402` payment request on the server side, you must expl
100100

101101
## Payment Scheme
102102

103-
x402 supports two payment schemes: `exact_permit` and `exact`.
103+
x402 supports three payment schemes: `exact_permit`, `exact`, and `exact_gasfree`.
104104

105105
### `exact_permit` Scheme
106106

107107
The `exact_permit` scheme transfers tokens via the `PaymentPermit` contract, suitable for:
108108

109-
- **Pay-per-use APIs** (e.g., LLM token generation, image generation services)
110-
- **Metered resources** (cloud compute time, storage usage, bandwidth consumption)
111-
- **Dynamic pricing services** based on actual usage
109+
- **Pay-per-use APIs** (e.g., LLM token generation, image generation services)
110+
- **Metered resources** (cloud compute time, storage usage, bandwidth consumption)
111+
- **Dynamic pricing services** based on actual usage
112112

113113
### `exact` Scheme
114114

115115
The `exact` scheme is for tokens that natively support `transferWithAuthorization`. It does not require the `PaymentPermit` contract.
116116

117+
### `exact_gasfree` Scheme
118+
119+
The `exact_gasfree` scheme is a TRON-specific payment mechanism that allows users to pay with USDT/USDD **without holding TRX for gas fees**. Settlement is handled via the official GasFree Proxy through the BankOfAI facilitator endpoint.
120+
121+
Key characteristics:
122+
123+
- **Zero gas cost for buyers**: Buyers do not need to hold TRX — gas is covered by the GasFree infrastructure
124+
- **No API keys required**: All GasFree API calls route through the BankOfAI proxy at `https://facilitator.bankofai.io/{mainnet,nile}`, so clients do not need to configure `GASFREE_API_KEY` or `GASFREE_API_SECRET`
125+
- **TRON only**: Available on `tron:mainnet` and `tron:nile`
126+
117127
### How Payment Schemes Work
118128

119-
1. **Authorize**
129+
1. **Authorize**
120130
The client signs a message authorizing a **maximum amount**.
121131

122-
2. **Execute**
132+
2. **Execute**
123133
The server performs the requested task and calculates the **actual cost**.
124134

125-
3. **Settle**
135+
3. **Settle**
126136
The Facilitator submits the on-chain transaction based on the actual cost.
127137

128138
---
@@ -154,7 +164,7 @@ You may deploy your own Facilitator node to gain full control over payment verif
154164
| **Networks** | `tron:mainnet`, `tron:shasta`, `tron:nile`, `eip155:56`, `eip155:97` |
155165
| **Token Standard** | TRC-20 (built-in USDT & USDD support), BEP-20 |
156166
| **Signing Mechanism** | Typed data signing |
157-
| **Payment Scheme** | `exact_permit`, `exact` |
167+
| **Payment Scheme** | `exact_permit`, `exact`, `exact_gasfree` (TRON only) |
158168

159169
---
160170

docs/x402/faq.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ Common pricing models include:
6767

6868
#### What payment schemes does x402 support?
6969

70-
x402 supports `exact_permit` and `exact` payment schemes. Both allow the client to authorize a **maximum payment amount**, and the server to settle the **actual cost incurred** (up to the authorized limit). This is ideal for **metered billing**, **LLM token usage**, and similar use cases.
70+
x402 supports three payment schemes:
71+
72+
- **`exact_permit`** and **`exact`**: Both allow the client to authorize a **maximum payment amount**, and the server to settle the **actual cost incurred** (up to the authorized limit). This is ideal for **metered billing**, **LLM token usage**, and similar use cases.
73+
- **`exact_gasfree`** (TRON only): Allows buyers to pay with USDT/USDD without holding TRX for gas. All GasFree API calls are routed through the BankOfAI proxy — no API keys required on the client side.
7174

7275
---
7376

docs/x402/getting-started/quickstart-for-agent.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ Set your agent wallet's private key as environment variables so the x402-payment
6060

6161
```bash
6262
export TRON_PRIVATE_KEY="your_agent_wallet_private_key_here"
63-
export TRON_GRID_API_KEY="your_trongrid_api_key_here" # Recommended to avoid RPC rate limits
63+
export TRON_GRID_API_KEY="your_trongrid_api_key_here" # Recommended for production workloads
6464
```
6565

66-
> 💡 **How to get a TronGrid API Key:** Register for free at [TronGrid](https://www.trongrid.io/), create an API Key, and paste it above. You can leave this blank during testnet testing, but it is required for mainnet.
66+
> 💡 **How to get a TronGrid API Key:** Register for free at [TronGrid](https://www.trongrid.io/), create an API Key, and paste it above. When `TRON_GRID_API_KEY` is not set, mainnet RPC calls are automatically routed to a BankOfAI-operated fallback endpoint. Setting this key is recommended for production workloads to ensure optimal performance.
6767
6868
</TabItem>
6969
<TabItem value="BSC" label="BSC">
@@ -194,7 +194,7 @@ Before deploying your agent to production, make sure to review the following:
194194
| Agent doesn't initiate payment, errors immediately | Skill not installed correctly | Re-run the installation command in Step 2 |
195195
| `Private key not found` or signing fails | Environment variable not set or misconfigured | Re-run Step 1, and make sure you run the agent **in the same terminal session** |
196196
| Insufficient balance error | No test tokens in the agent wallet | Go back to Prerequisites and claim test tokens from the faucet |
197-
| Request times out | Network issue or RPC rate limiting | Configure `TRON_GRID_API_KEY` to avoid rate limits |
197+
| Request times out | Network issue or RPC rate limiting | Configure `TRON_GRID_API_KEY` for better performance (a fallback endpoint is used automatically when not set) |
198198
| Agent accesses successfully but balance doesn't change | May have accessed a free endpoint | Confirm the URL path is `/protected-nile`, not another path |
199199

200200
---

docs/x402/getting-started/quickstart-for-human.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,10 @@ import httpx
212212

213213
from bankofai.x402.clients import X402Client, X402HttpClient, SufficientBalancePolicy
214214
from bankofai.x402.mechanisms.tron.exact_permit import ExactPermitTronClientMechanism
215+
from bankofai.x402.mechanisms.tron.exact_gasfree.client import ExactGasFreeClientMechanism
215216
from bankofai.x402.signers.client import TronClientSigner
217+
from bankofai.x402.utils.gasfree import GasFreeAPIClient
218+
from bankofai.x402.config import NetworkConfig
216219

217220

218221
# ========== Configuration ==========
@@ -221,14 +224,21 @@ from bankofai.x402.signers.client import TronClientSigner
221224
SERVER_URL = "https://x402-demo.bankofai.io/protected-nile"
222225
# ====================================
223226

227+
# GasFree API clients (routed through BankOfAI proxy — no API keys needed)
228+
gasfree_clients = {
229+
"tron:nile": GasFreeAPIClient(NetworkConfig.get_gasfree_api_base_url("tron:nile")),
230+
"tron:mainnet": GasFreeAPIClient(NetworkConfig.get_gasfree_api_base_url("tron:mainnet")),
231+
}
232+
224233

225234
async def main():
226235
# Initialize signer with your private key (network is resolved dynamically)
227236
signer = TronClientSigner.from_private_key(os.getenv("TRON_PRIVATE_KEY"))
228237

229-
# Create x402 client and register the payment mechanism and balance policy
238+
# Create x402 client and register payment mechanisms and balance policy
230239
x402_client = X402Client()
231240
x402_client.register("tron:*", ExactPermitTronClientMechanism(signer))
241+
x402_client.register("tron:*", ExactGasFreeClientMechanism(signer, clients=gasfree_clients))
232242
x402_client.register_policy(SufficientBalancePolicy)
233243

234244
async with httpx.AsyncClient(timeout=60.0) as http_client:
@@ -264,8 +274,9 @@ Response: {"data": "This is premium content!"}
264274
import 'dotenv/config'
265275
import {
266276
X402Client, X402FetchClient,
267-
ExactPermitTronClientMechanism, TronClientSigner,
268-
SufficientBalancePolicy,
277+
ExactPermitTronClientMechanism, ExactGasFreeClientMechanism,
278+
TronClientSigner, SufficientBalancePolicy,
279+
GasFreeAPIClient, getGasFreeApiBaseUrl,
269280
} from '@bankofai/x402'
270281

271282
const TRON_PRIVATE_KEY = process.env.TRON_PRIVATE_KEY!
@@ -280,9 +291,13 @@ async function main(): Promise<void> {
280291
// Initialize signer with your private key
281292
const signer = new TronClientSigner(TRON_PRIVATE_KEY)
282293

283-
// Create x402 client and register the payment mechanism and balance policy
294+
// Create x402 client and register payment mechanisms and balance policy
284295
const x402 = new X402Client()
285296
x402.register('tron:*', new ExactPermitTronClientMechanism(signer))
297+
x402.register('tron:*', new ExactGasFreeClientMechanism(signer, {
298+
'tron:nile': new GasFreeAPIClient(getGasFreeApiBaseUrl('tron:nile')),
299+
'tron:mainnet': new GasFreeAPIClient(getGasFreeApiBaseUrl('tron:mainnet')),
300+
}))
286301
x402.registerPolicy(SufficientBalancePolicy)
287302

288303
const client = new X402FetchClient(x402)

docs/x402/getting-started/quickstart-for-sellers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ Open the `.env` file in the `x402-demo` directory with a text editor and fill in
396396
# How to get it: TronLink → Settings → Account Management → Export Private Key
397397
TRON_PRIVATE_KEY=paste_your_facilitator_private_key_here
398398

399-
# TronGrid API Key (required for mainnet, can be left blank for testnet)
399+
# TronGrid API Key (recommended for production; when not set, a BankOfAI fallback endpoint is used automatically)
400400
# Apply at: https://www.trongrid.io/
401401
TRON_GRID_API_KEY=
402402
```
@@ -545,7 +545,7 @@ Modify the `network` parameter in the `@x402_protected` decorator in `server.py`
545545
<Tabs>
546546
<TabItem value="TRON" label="TRON">
547547

548-
1. **Apply for a TronGrid API Key**: go to [TronGrid](https://www.trongrid.io/) to register and create an API Key, then fill it into the `TRON_GRID_API_KEY` field in `.env` (required for mainnet)
548+
1. **Apply for a TronGrid API Key**: go to [TronGrid](https://www.trongrid.io/) to register and create an API Key, then fill it into the `TRON_GRID_API_KEY` field in `.env` (recommended for production; a BankOfAI fallback endpoint is used automatically when not set)
549549
2. **Replace the private key**: update the private key in `.env` to the mainnet Facilitator wallet's private key
550550
3. **Fund the fee wallet**: transfer sufficient real TRX to the Facilitator mainnet wallet (to pay Energy and Bandwidth fees)
551551
4. **Update the network config**: change the network configuration in the Facilitator code to `NetworkConfig.TRON_MAINNET`

docs/x402/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description: >-
99

1010
x402 is an open blockchain payment standard built on the HTTP `402 Payment Required` status code. It enables web services to charge for APIs or content through a “pay-before-response” mechanism — without relying on traditional account systems or session management.
1111

12-
x402 currently supports the TRON and BSC networks, with plans to expand to a broader multi-chain ecosystem in the future.
12+
x402 currently supports the **TRON** and **BSC** networks, with plans to expand to a broader multi-chain ecosystem in the future.
1313

1414
**Interested in contributing to the documentation?**
1515
Feel free to submit a PR to the [GitHub repository](https://github.com/BofAI/docs). Our only principle is to maintain neutrality — aside from essential resource links, please avoid promotional or branded content.

docs/x402/sdk-features.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ This page tracks the implementation progress and feature support status of the x
4646
| exact_permit/bsc |||
4747
| exact/tron |||
4848
| exact/bsc |||
49+
| exact_gasfree/tron |||
4950

5051
---
5152

@@ -69,6 +70,8 @@ This page tracks the implementation progress and feature support status of the x
6970
| Allowance check |||
7071
| Signing (TRON) |||
7172
| Signing (EVM) |||
73+
| SufficientBalancePolicy |||
74+
| GasFree (zero-gas TRON payments) |||
7275

7376
---
7477

@@ -101,6 +104,7 @@ This page tracks the implementation progress and feature support status of the x
101104
| Token | Python | TypeScript |
102105
|--------|--------|------------|
103106
| USDT (TRC-20) |||
107+
| USDD (TRC-20) |||
104108
| Custom TRC-20 |||
105109
| USDT (BEP-20) |||
106110
| Custom BEP-20 |||

i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/core-concepts/network-and-token-support.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ x402 专为区块链生态设计,实现了原生的链上支付验证与结算
4040
| **TRON Shasta** | **Testnet** | **备用测试网**:长期稳定的测试环境。 |
4141
| **BSC Mainnet** | **Mainnet** | **生产网络**:用于处理真实价值资产。 |
4242
| **BSC Testnet** | **Testnet** | **推荐测试网**:BSC 首选的开发与调试环境。 |
43+
4344
### 支持的代币
4445

4546
x402 协议全面支持 **TRC-20/BEP-20** 标准代币,并默认将 **USDT****USDD** 作为主要结算货币。
@@ -81,7 +82,7 @@ x402 采用类型化数据签名来处理所有支付相关的签名授权。
8182
8283
### 支付方案
8384

84-
x402 支持两种支付方案`exact_permit``exact`
85+
x402 支持三种支付方案`exact_permit``exact``exact_gasfree`
8586

8687
#### `exact_permit` 方案
8788

@@ -95,6 +96,16 @@ x402 支持两种支付方案:`exact_permit` 和 `exact`。
9596

9697
`exact` 方案适用于原生支持 `transferWithAuthorization` 的代币,无需 `PaymentPermit` 合约。
9798

99+
#### `exact_gasfree` 方案
100+
101+
`exact_gasfree` 是 TRON 专属的支付机制,允许用户使用 USDT/USDD 付款而**无需持有 TRX 来支付 gas 费用**。结算通过 BankOfAI Facilitator 端点的官方 GasFree 代理完成。
102+
103+
核心特性:
104+
105+
- **买家零 gas 成本**:买家无需持有 TRX,gas 费用由 GasFree 基础设施承担
106+
- **无需 API 密钥**:所有 GasFree API 调用通过 BankOfAI 代理路由至 `https://facilitator.bankofai.io/{mainnet,nile}`,客户端无需配置 `GASFREE_API_KEY``GASFREE_API_SECRET`
107+
- **仅限 TRON**:支持 `tron:mainnet``tron:nile`
108+
98109
#### 工作原理
99110

100111
1. **预授权 (Authorize)**:客户端签署消息,授权支付**最大金额** (Max Amount)。
@@ -123,10 +134,10 @@ Facilitator 作为协议的中间件,承担以下核心职责:
123134

124135
| 核心组件 | TRON/BSC 实现详情 |
125136
| :----------- | :----------------------------------------- |
126-
| **网络环境** | `tron:mainnet`, `tron:shasta`, `tron:nile`, `eip155:56`, `eip155:97`|
137+
| **网络环境** | `tron:mainnet`, `tron:shasta`, `tron:nile`, `eip155:56`, `eip155:97` |
127138
| **代币标准** | TRC-20 代币(默认内置 USDT 和 USDD 支持),BEP-20 代币 |
128139
| **签名机制** | 类型化数据签名 |
129-
| **支付方案** | `exact_permit`, `exact` |
140+
| **支付方案** | `exact_permit`, `exact`, `exact_gasfree`(仅限 TRON) |
130141

131142
### 添加自定义代币
132143

i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/faq.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ x402 目前提供以下 SDK:
5959

6060
#### x402 支持哪些支付方案?
6161

62-
x402 支持 `exact_permit``exact` 两种支付方案。两种方案均允许客户端授权一个**最高支付金额**,服务端结算**实际产生的费用**(不超过授权上限)。此方案非常适用于**按量计费 (Metered Billing)****LLM Token 消耗**等场景。
62+
x402 支持三种支付方案:
63+
64+
- **`exact_permit`****`exact`**:两种方案均允许客户端授权一个**最高支付金额**,服务端结算**实际产生的费用**(不超过授权上限)。此方案非常适用于**按量计费 (Metered Billing)****LLM Token 消耗**等场景。
65+
- **`exact_gasfree`**(仅限 TRON):允许买家使用 USDT/USDD 付款而无需持有 TRX 来支付 gas。所有 GasFree API 调用通过 BankOfAI 代理路由,客户端无需配置 API 密钥。
6366

6467
### 资产、网络及费用
6568

i18n/zh-Hans/docusaurus-plugin-content-docs/current/x402/getting-started/quickstart-for-agent.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ x402 专为 Agentic Web 设计。通过安装 `x402-payment` 技能,AI 代理
6060

6161
```bash
6262
export TRON_PRIVATE_KEY="在此填入代理钱包私钥"
63-
export TRON_GRID_API_KEY="在此填入TronGrid API Key" # 推荐配置,防止 RPC 限速
63+
export TRON_GRID_API_KEY="在此填入TronGrid API Key" # 生产环境推荐配置
6464
```
6565

66-
> 💡 **如何获取 TronGrid API Key:** 前往 [TronGrid 官网](https://www.trongrid.io/) 免费注册,创建 API Key 后粘贴到上方。测试网阶段可暂时留空,但主网阶段必须配置
66+
> 💡 **如何获取 TronGrid API Key:** 前往 [TronGrid 官网](https://www.trongrid.io/) 免费注册,创建 API Key 后粘贴到上方。未配置 `TRON_GRID_API_KEY` 时,主网 RPC 调用会自动路由至 BankOfAI 运营的备用 RPC 端点。生产环境建议配置此 Key 以获得最佳性能
6767
6868
</TabItem>
6969
<TabItem value="BSC" label="BSC">
@@ -194,7 +194,7 @@ https://x402-demo.bankofai.io/protected-nile
194194
| 代理未发起付款,直接报错 | 技能未正确安装 | 重新执行第二步的安装命令 |
195195
| `私钥未找到` 或签名失败 | 环境变量未配置或配置错误 | 重新执行第一步,在**同一终端**中运行代理 |
196196
| 余额不足错误 | 测试钱包中没有测试代币 | 回到前置准备,从水龙头领取测试代币 |
197-
| 请求超时 | 网络问题或 RPC 限速 | 配置 `TRON_GRID_API_KEY` 以避免限速 |
197+
| 请求超时 | 网络问题或 RPC 限速 | 配置 `TRON_GRID_API_KEY` 以获得更好的性能(未配置时会自动使用备用 RPC 端点) |
198198
| 代理访问成功但余额没有变化 | 可能访问的是免费接口 | 确认 URL 是 `/protected-nile` 而非其他路径 |
199199

200200
---

0 commit comments

Comments
 (0)