Payment API

Submit Transaction#

Submit the transaction for on-chain settlement.

Request URL#

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

Request Parameters#

  • Request Body
ParameterTypeRequiredDescription
x402VersionStringYesx402 protocol version; pass integer 1 for v1
chainIndexStringYesUnique network identifier
syncSettleBooleanNoSynchronous or asynchronous settlement; defaults to synchronous (true)
paymentPayloadObjectYesx402 payment payload carried by the client with the protected request
>x402VersionStringYesx402 protocol version; pass integer 1 for v1
>schemeStringYesSettlement scheme, e.g. exact (one-time fixed-amount payment)
>payloadObjectYesPayment signature and authorization data object
>>signatureStringYesCryptographic signature
>>authorizationObjectYesAuthorization information
>>>fromStringYesPayer address
>>>toStringYesRecipient address
>>>valueStringYesAmount in the smallest on-chain unit (e.g. USDT has 6 decimals, so 1 USDT = 1000000)
>>>validAfterStringYesUnix timestamp (in seconds) when authorization becomes valid
>>>validBeforeStringYesUnix timestamp (in seconds) when authorization expires
>>>nonceStringYes32-byte hex random value to prevent replay attacks
paymentRequirementsObjectYesPayment requirements for accessing a paid resource (amount/network/asset/recipient etc.)
>schemeStringYesSettlement scheme, e.g. exact
>resourceStringNoServer URL of the resource
>descriptionStringNoAPI description of the resource
>mimeTypeStringNoMIME type of the resource response
>maxAmountRequiredStringYesMaximum payment amount in the smallest on-chain unit (e.g. USDT has 6 decimals, so 1 USDT = 1000000)
>maxTimeoutSecondsIntegerNoMaximum wait time in seconds after authorization
>payToStringYesRecipient address
>assetStringNoAsset identifier/contract address (network-dependent)
>outputSchemaObjectNoExpected JSON schema of the resource response
>extraObjectNoAdditional parameters, e.g. gasLimit

Response Parameters#

ParameterTypeDescription
chainIndexStringUnique network identifier, e.g. 196: X Layer
chainNameStringNetwork name, e.g. X Layer
successBooleanWhether settlement was successful
payerStringUser's payment address
txHashStringSettlement transaction hash (0x hash for EVM; base58 for Solana)
errorMsgStringFailure reason (e.g. insufficient_funds, invalid_payload, etc.)

Request Example#

Shell
curl --location --request POST 'https://web3.okx.com/api/v6/x402/settle' \
--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,
  "syncSettle": true,
  "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"
    }
  }
}'

Response Example#

Json
{
    "code": "0",
    "msg": "success",
    "data": [
        {
            "success": true,
            "errorReason": null,
            "payer": "<payer-wallet-address>",
            "txHash": "<transaction-hash>",
            "chainIndex": "196",
            "chainName": "X Layer"
        }
    ]
}