验证交易#
验证交易合法性
请求地址#
POST https://web3.okx.com/api/v6/x402/verify
请求参数#
| 参数 | 类型 | 必传 | 描述 |
|---|---|---|---|
| x402Version | String | 是 | x402 协议版本(如 1) |
| chainIndex | String | 是 | 网络的唯一标识 |
| paymentPayload | Object | 是 | 客户端随受保护请求携带的 x402 支付载荷 |
| >x402Version | String | 是 | x402 协议版本(如 1) |
| >scheme | String | 是 | 结算方案,如 exact(按固定金额一次性支付) |
| >payload | Object | 是 | 付款签名与授权数据对象 |
| >>signature | String | 是 | 加密签名 |
| >>authorization | Object | 是 | 授权信息 |
| >>>from | String | 是 | 付款地址 |
| >>>to | String | 是 | 收款地址 |
| >>>value | String | 是 | 金额(最小单位,带精度) |
| >>>validAfter | String | 否 | 生效时间(Unix) |
| >>>validBefore | String | 否 | 失效时间(Unix) |
| >>>nonce | String | 是 | 随机数 |
| paymentRequirements | Object | 是 | 支付内容用于付费访问资源的信息(金额/网络/资产/收款方等) |
| >scheme | String | 是 | 结算方案,如 exact |
| >resource | String | 否 | 资源的服务器 URL |
| >description | String | 否 | 资源的接口描述 |
| >mimeType | String | 否 | 资源方响应的 MIME 类型 |
| >maxAmountRequired | String | 是 | 最大需支付金额(最小单位,带精度) |
| >maxTimeoutSeconds | Integer | 否 | 授权有效后最大等待秒数 |
| >payTo | String | 是 | 收款地址 |
| >asset | String | 否 | 资产标识/合约地址(视网络而定) |
| >outputSchema | Object | 否 | 期望资源返回数据的 JSON 结构 |
| >extra | Object | 否 | 额外参数,如 gasLimit |
响应参数#
| 参数 | 类型 | 描述 |
|---|---|---|
| isValid | Boolean | true 为验证有效,false 为验证无效 |
| payer | String | 用户付款地址 |
| invalidReason | String | 无效原因,如 insufficient_funds、invalid_network 等 |
请求示例#
shell
curl --request POST \
--url https://web3.okx.com/api/v6/x402/verify \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"x402Version": 1,
"paymentPayload": {
"x402Version": 1,
"scheme": "exact",
"chainIndex": "196",
"payload": {
"signature": "0xf3746613c2d920b5fdabc0856f2aeb2d4f88ee6037b8cc5d04a71a4462f13480",
"authorization": {
"from": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
"to": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
"value": "1000000000000000000",
"validAfter": "1716150000",
"validBefore": "1716150000",
"nonce": "0x1234567890abcdef1234567890abcdef12345678"
}
}
},
"paymentRequirements": {
"scheme": "exact",
"chainIndex": "196",
"maxAmountRequired": "1000000",
"resource": "https://api.example.com/premium/resource/123",
"description": "Premium API access for data analysis",
"mimeType": "application/json",
"outputSchema": {
"data": "string"
},
"payTo": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
"maxTimeoutSeconds": 10,
"asset": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
"extra": {
"gasLimit": "1000000"
}
}
}'
响应示例#
200
{
"code": "0",
"msg": "success",
"data": [
{
"isValid": true,
"invalidReason": null,
"payer": "0xcb30ed083ad246b126a3aa1f414b44346e83e67d"
}
]
}
