验证交易#
验证交易合法性。
请求地址#
POST https://web3.okx.com/api/v6/x402/verify
请求参数#
| 参数 | 类型 | 必传 | 描述 |
|---|---|---|---|
| x402Version | String | 是 | x402 协议版本,v1 对应传整数 1 |
| chainIndex | String | 是 | 网络的唯一标识 |
| paymentPayload | Object | 是 | 客户端随受保护请求携带的 x402 支付载荷 |
| >x402Version | String | 是 | x402 协议版本,v1 对应传整数 1 |
| >scheme | String | 是 | 结算方案,如 exact(按固定金额一次性支付) |
| >payload | Object | 是 | 付款签名与授权数据对象 |
| >>signature | String | 是 | 加密签名 |
| >>authorization | Object | 是 | 授权信息 |
| >>>from | String | 是 | 付款地址 |
| >>>to | String | 是 | 收款地址 |
| >>>value | String | 是 | 金额,以链上最小单位表示(如 USDT 精度为 6,则 1 USDT = 1000000) |
| >>>validAfter | String | 是 | 授权生效的 Unix 时间戳(秒级精度) |
| >>>validBefore | String | 是 | 授权失效的 Unix 时间戳(秒级精度) |
| >>>nonce | String | 是 | 32 字节十六进制随机数,用于防止重放攻击 |
| paymentRequirements | Object | 是 | 支付内容用于付费访问资源的信息(金额/网络/资产/收款方等) |
| >scheme | String | 是 | 结算方案,如 exact |
| >resource | String | 否 | 资源的服务器 URL |
| >description | String | 否 | 资源的接口描述 |
| >mimeType | String | 否 | 资源方响应的 MIME 类型 |
| >maxAmountRequired | String | 是 | 最大需支付金额,以链上最小单位表示(如 USDT 精度为 6,则 1 USDT = 1000000) |
| >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 'Content-Type: application/json' \
--header 'OK-ACCESS-KEY: <your-api-key>' \
--header 'OK-ACCESS-SIGN: <your-signature>' \
--header 'OK-ACCESS-PASSPHRASE: <your-passphrase>' \
--header 'OK-ACCESS-TIMESTAMP: <your-timestamp>' \
--data '{
"x402Version": 1,
"chainIndex": 196,
"paymentPayload": {
"x402Version": 1,
"scheme": "exact",
"payload": {
"signature": "<your-signature>",
"authorization": {
"from": "<payer-wallet-address>",
"to": "<payee-wallet-address>",
"value": "1000000",
"validAfter": "<unix-timestamp-seconds>",
"validBefore": "<unix-timestamp-seconds>",
"nonce": "<your-nonce>"
}
}
},
"paymentRequirements": {
"scheme": "exact",
"maxAmountRequired": "0",
"resource": "https://api.example.com/premium/resource/123",
"description": "Premium API access for data analysis",
"mimeType": "application/json",
"outputSchema": {
"data": "string"
},
"payTo": "<payee-wallet-address>",
"maxTimeoutSeconds": 10,
"asset": "<asset-contract-address>",
"extra": {
"gasLimit": "1000000"
}
}
}'
响应示例#
Json
{
"code": "0",
"msg": "success",
"data": [
{
"isValid": true,
"invalidReason": null,
"payer": "<payer-wallet-address>"
}
]
}