x402 API

交易结算#

将客户端提交的支付 Payload 进行链上交易结算

请求地址#

POST https://web3.okx.com/api/v6/x402/settle

请求参数#

  • 请求体
参数类型必传描述
x402VersionStringx402 协议版本(如 1)
chainIndexString网络的唯一标识
paymentPayloadObject客户端随受保护请求携带的 x402 支付载荷
>x402VersionStringx402 协议版本(如 1)
>schemeString结算方案,如 exact(按固定金额一次性支付)
>payloadObject付款签名与授权数据对象
>>signatureString加密签名
>>authorizationObject授权信息
>>>fromString付款地址
>>>toString收款地址
>>>valueString金额(最小单位,带精度)
>>>validAfterString生效时间(Unix)
>>>validBeforeString失效时间(Unix)
>>>nonceString随机数,防重放
paymentRequirementsObject支付内容用于付费访问资源的信息(金额/网络/资产/收款方等)
>schemeString结算方案,如 exact
>resourceString资源的服务器 URL
>descriptionString资源的接口描述
>mimeTypeString资源方响应的 MIME 类型
>maxAmountRequiredString最大需支付金额(最小单位,带精度)
>maxTimeoutSecondsInteger授权有效后最大等待秒数
>payToString收款地址
>assetString资产标识/合约地址(视网络而定)
>outputSchemaObject期望资源返回数据的 JSON 结构
>extraObject额外参数,如 gasLimit

响应参数#

参数类型描述
chainIndexString网络的唯一标识,如 196:X Layer
chainNameString网络名称,如 X Layer
successBoolean是否结算成功
payerString用户付款地址
txHashString结算交易哈希(EVM 为 0x hash;Solana 为 base58)
errorMsgString失败原因(如 insufficient_funds、invalid_payload 等)

请求示例#

curl --location --request POST 'https://web3.okx.com/api/v6/wallet/settle' \
--header 'Content-Type: application/json' \
--header 'OK-ACCESS-KEY: 37c541a1-****-****-****-10fe7a038418' \
--header 'OK-ACCESS-SIGN: leaV********3uw=' \
--header 'OK-ACCESS-PASSPHRASE: 1****6' \
--header 'OK-ACCESS-TIMESTAMP: 2023-10-18T12:21:41.274Z' \
  --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": [
        {
            "success": true,
            "errorReason": null,
            "payer": "0xcb30ed083ad246b126a3aa1f414b44346e83e67d",
            "txHash": "0x4f46ed8eac92ddbccfb56a88ff827db3616c7beb191adabbeeded901340bd7d5",
            "chainIndex": "196",
            "chainName": "X Layer"
        }
    ]
}