onchain-pay-open-api
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBinance Onchain-Pay Open API Skill
Binance Onchain-Pay Open API技能
Call Binance Onchain-Pay Open API endpoints with automatic RSA SHA256 request signing.
通过自动RSA SHA256请求签名调用Binance Onchain-Pay Open API端点。
Quick Reference
快速参考
| Endpoint | API Path | Required Params | Optional Params |
|---|---|---|---|
| Payment Method List (v1) | | fiatCurrency, cryptoCurrency, totalAmount, amountType | network, contractAddress |
| Payment Method List (v2) | | (none) | lang |
| Trading Pairs | | (none) | (none) |
| Estimated Quote | | fiatCurrency, requestedAmount, payMethodCode, amountType | cryptoCurrency, contractAddress, address, network |
| Pre-order | | externalOrderId, merchantCode, merchantName, ts | fiatCurrency, fiatAmount, cryptoCurrency, requestedAmount, amountType, address, network, payMethodCode, payMethodSubCode, redirectUrl, failRedirectUrl, redirectDeepLink, failRedirectDeepLink, customization, destContractAddress, destContractABI, destContractParams, affiliateCode, gtrTemplateCode, contractAddress |
| Get Order | | externalOrderId | (none) |
| Crypto Network | | (none) | (none) |
| P2P Trading Pairs | | (none) | fiatCurrency |
| 端点 | API路径 | 必填参数 | 可选参数 |
|---|---|---|---|
| 支付方式列表(v1) | | fiatCurrency, cryptoCurrency, totalAmount, amountType | network, contractAddress |
| 支付方式列表(v2) | | 无 | lang |
| 交易对 | | 无 | 无 |
| 预估报价 | | fiatCurrency, requestedAmount, payMethodCode, amountType | cryptoCurrency, contractAddress, address, network |
| 预下单 | | externalOrderId, merchantCode, merchantName, ts | fiatCurrency, fiatAmount, cryptoCurrency, requestedAmount, amountType, address, network, payMethodCode, payMethodSubCode, redirectUrl, failRedirectUrl, redirectDeepLink, failRedirectDeepLink, customization, destContractAddress, destContractABI, destContractParams, affiliateCode, gtrTemplateCode, contractAddress |
| 查询订单 | | externalOrderId | 无 |
| 加密货币网络 | | 无 | 无 |
| P2P交易对 | | 无 | fiatCurrency |
How to Execute a Request
如何执行请求
Step 1: Gather credentials
步骤1:收集凭证
Use the default account (prod) unless the user specifies otherwise. You need:
- BASE_URL: API base URL
- CLIENT_ID: Client identifier
- API_KEY: The sign access token
- PEM_PATH: Absolute path to the RSA private key PEM file
Use the account marked in .
(default).local.md除非用户指定,否则使用默认账户(生产环境)。你需要:
- BASE_URL:API基础URL
- CLIENT_ID:客户端标识符
- API_KEY:签名访问令牌
- PEM_PATH:RSA私钥PEM文件的绝对路径
使用中标记为的账户。
.local.md(default)Step 2: Build the JSON body
步骤2:构建JSON请求体
Build a compact JSON body from user-specified parameters. Remove any parameters the user did not provide.
根据用户指定的参数构建紧凑的JSON请求体,移除用户未提供的任何参数。
Step 3: Sign and call using the bundled script
步骤3:使用捆绑脚本签名并调用
bash
bash <skill_path>/scripts/sign_and_call.sh \
"<BASE_URL>" \
"<API_PATH>" \
"<CLIENT_ID>" \
"<API_KEY>" \
"<PEM_PATH>" \
'<JSON_BODY>'bash
bash <skill_path>/scripts/sign_and_call.sh \
"<BASE_URL>" \
"<API_PATH>" \
"<CLIENT_ID>" \
"<API_KEY>" \
"<PEM_PATH>" \
'<JSON_BODY>'Step 4: Return results
步骤4:返回结果
Display the JSON response to the user in a readable format.
以易读格式向用户展示JSON响应。
Authentication
身份验证
See for full signing details.
references/authentication.mdSummary:
- Payload = +
JSON_BODY(milliseconds)TIMESTAMP - Sign payload with RSA SHA256 using PEM private key
- Base64 encode the signature (single line)
- Send as POST with headers: ,
X-Tesla-ClientId,X-Tesla-SignAccessToken,X-Tesla-Signature,X-Tesla-TimestampContent-Type: application/json
完整的签名细节请参阅。
references/authentication.md摘要:
- 载荷 = +
JSON_BODY(毫秒级)TIMESTAMP - 使用PEM私钥通过RSA SHA256对载荷进行签名
- 对签名进行Base64编码(单行)
- 以POST方式发送,携带请求头:,
X-Tesla-ClientId,X-Tesla-SignAccessToken,X-Tesla-Signature,X-Tesla-TimestampContent-Type: application/json
Parameters Reference
参数参考
Payment Method List v1 (buy/payment-method-list
)
buy/payment-method-list支付方式列表v1(buy/payment-method-list
)
buy/payment-method-list| Parameter | Type | Required | Description |
|---|---|---|---|
| fiatCurrency | string | Yes | Fiat currency code (e.g., |
| cryptoCurrency | string | Yes | Crypto currency code (e.g., |
| totalAmount | number | Yes | Amount value |
| amountType | number | Yes | |
| network | string | No | Blockchain network (e.g., |
| contractAddress | string | No | Token contract address (required for non-native tokens) |
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| fiatCurrency | string | 是 | 法币代码(例如: |
| cryptoCurrency | string | 是 | 加密货币代码(例如: |
| totalAmount | number | 是 | 金额数值 |
| amountType | number | 是 | |
| network | string | 否 | 区块链网络(例如: |
| contractAddress | string | 否 | 代币合约地址(非原生代币必填) |
Payment Method List v2 (v2/buy/payment-method-list
)
v2/buy/payment-method-list支付方式列表v2(v2/buy/payment-method-list
)
v2/buy/payment-method-listGet all available payment methods without specifying fiat/crypto parameters. Simplified version of v1.
| Parameter | Type | Required | Description |
|---|---|---|---|
| lang | string | No | Language code for localized payment method names (e.g., |
Differences from v1:
- Simpler: No need to specify fiatCurrency, cryptoCurrency, or amount
- Comprehensive: Returns all available payment methods for the merchant
- Use case: Useful for displaying all options before user input
Response Format: Same as v1, returns list of payment methods with their limits and properties.
无需指定法币/加密货币参数即可获取所有可用支付方式,是v1的简化版本。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| lang | string | 否 | 支付方式名称的本地化语言代码(例如: |
与v1的差异:
- 更简单:无需指定fiatCurrency、cryptoCurrency或金额
- 更全面:返回商家可用的所有支付方式
- 使用场景:适合在用户输入前展示所有选项
响应格式:与v1相同,返回包含限额和属性的支付方式列表。
Estimated Quote (buy/estimated-quote
)
buy/estimated-quote预估报价(buy/estimated-quote
)
buy/estimated-quote| Parameter | Type | Required | Description |
|---|---|---|---|
| fiatCurrency | string | Yes | Fiat currency code |
| cryptoCurrency | string | No | Crypto currency code (optional if contractAddress provided) |
| requestedAmount | number | Yes | Amount value |
| payMethodCode | string | Yes | Payment method (e.g., |
| amountType | number | Yes | |
| network | string | No | Blockchain network |
| contractAddress | string | No | Token contract address |
| address | string | No | Destination wallet address |
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| fiatCurrency | string | 是 | 法币代码 |
| cryptoCurrency | string | 否 | 加密货币代码(若提供contractAddress则可选) |
| requestedAmount | number | 是 | 金额数值 |
| payMethodCode | string | 是 | 支付方式(例如: |
| amountType | number | 是 | |
| network | string | 否 | 区块链网络 |
| contractAddress | string | 否 | 代币合约地址 |
| address | string | 否 | 接收加密货币的目标钱包地址 |
Pre-order (buy/pre-order
)
buy/pre-order预下单(buy/pre-order
)
buy/pre-orderCreate a buy pre-order and return the redirect link for payment.
| Parameter | Type | Required | Description |
|---|---|---|---|
| externalOrderId | string | Yes | Partner's unique order ID (must be unique) |
| merchantCode | string | Yes | Merchant code (e.g., |
| merchantName | string | Yes | Merchant display name (e.g., |
| ts | number | Yes | Current timestamp in milliseconds |
| fiatCurrency | string | No* | Fiat currency code (e.g., |
| fiatAmount | number | No* | Fiat amount to spend |
| cryptoCurrency | string | No* | Crypto currency to buy (e.g., |
| requestedAmount | number | No* | Amount value (fiat or crypto based on amountType) |
| amountType | number | No* | |
| address | string | No | Destination wallet address for receiving crypto |
| network | string | No | Blockchain network (e.g., |
| payMethodCode | string | No | Payment method code (e.g., |
| payMethodSubCode | string | No | Payment method sub-code (e.g., |
| redirectUrl | string | No | Success redirect URL |
| failRedirectUrl | string | No | Failure redirect URL |
| redirectDeepLink | string | No | Deep link for success (mobile apps) |
| failRedirectDeepLink | string | No | Deep link for failure (mobile apps) |
| customization | object | No | Custom configuration object (see Customization section below) |
| destContractAddress | string | No | Destination contract address (for Onchain-Pay Easy mode) |
| destContractABI | string | No | Contract ABI name (for Onchain-Pay Easy mode) |
| destContractParams | object | No | Contract parameters (for Onchain-Pay Easy mode) |
| affiliateCode | string | No | Affiliate code for commission tracking |
| gtrTemplateCode | string | No | GTR template code (e.g., |
| contractAddress | string | No | Token contract address (for non-native tokens) |
* Either or ( + ) should be provided. If is not provided, the system will auto-select available fiat currencies.
fiatAmountrequestedAmountamountTypefiatCurrencyResponse Example:
json
{
"code": "000000",
"message": "success",
"data": {
"link": "https://app.binance.com/uni-qr/ccnt?...",
"linkExpireTime": 1772852565045
},
"success": true
}创建购买预订单并返回支付跳转链接。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| externalOrderId | string | 是 | 合作伙伴的唯一订单ID(必须唯一) |
| merchantCode | string | 是 | 商家代码(例如: |
| merchantName | string | 是 | 商家显示名称(例如: |
| ts | number | 是 | 当前毫秒级时间戳 |
| fiatCurrency | string | 可选* | 法币代码(例如: |
| fiatAmount | number | 可选* | 要花费的法币金额 |
| cryptoCurrency | string | 可选* | 要购买的加密货币(例如: |
| requestedAmount | number | 可选* | 金额数值(根据amountType为法币或加密货币) |
| amountType | number | 可选* | |
| address | string | 否 | 接收加密货币的目标钱包地址 |
| network | string | 否 | 区块链网络(例如: |
| payMethodCode | string | 否 | 支付方式代码(例如: |
| payMethodSubCode | string | 否 | 支付方式子代码(例如: |
| redirectUrl | string | 否 | 成功跳转URL |
| failRedirectUrl | string | 否 | 失败跳转URL |
| redirectDeepLink | string | 否 | 成功跳转深度链接(移动端应用) |
| failRedirectDeepLink | string | 否 | 失败跳转深度链接(移动端应用) |
| customization | object | 否 | 自定义配置对象(见下方自定义选项章节) |
| destContractAddress | string | 否 | 目标合约地址(适用于Onchain-Pay简易模式) |
| destContractABI | string | 否 | 合约ABI名称(适用于Onchain-Pay简易模式) |
| destContractParams | object | 否 | 合约参数(适用于Onchain-Pay简易模式) |
| affiliateCode | string | 否 | 用于佣金追踪的联盟代码 |
| gtrTemplateCode | string | 否 | GTR模板代码(例如: |
| contractAddress | string | 否 | 代币合约地址(非原生代币) |
* 需提供 或 ( + )。若未提供,系统将自动选择可用的法币。
fiatAmountrequestedAmountamountTypefiatCurrency响应示例:
json
{
"code": "000000",
"message": "success",
"data": {
"link": "https://app.binance.com/uni-qr/ccnt?...",
"linkExpireTime": 1772852565045
},
"success": true
}Get Order (order
)
order查询订单(order
)
order| Parameter | Type | Required | Description |
|---|---|---|---|
| externalOrderId | string | Yes | The external order ID to query |
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| externalOrderId | string | 是 | 要查询的外部订单ID |
Customization Options
自定义选项
The field in pre-order API accepts various flags to customize the buy flow behavior. Each merchant must have the corresponding permission configured in table.
customizationdb.merchant_info预下单API中的字段接受各种标志,用于自定义购买流程行为。每个商家必须在表中配置相应的权限才能使用。
customizationdb.merchant_infoAvailable Customization Flags
可用自定义标志
| Flag | Code | Type | Availability | Description | Use Case |
|---|---|---|---|---|---|
| 1 | array | Open API ✓ | Lock specific order attributes so users cannot modify them. Values: | Fixed-parameter orders |
| 2 | boolean | Open API ✓ | Skip the cashier page and proceed directly to payment. Reduces user friction in the checkout flow. | Streamlined payment experience |
| 3 | boolean | Open API ✓ | Automatically redirect to | Seamless user experience |
| 6 | boolean | Open API ✓ | Hide the "Send" tab in the UI. Useful when only buy flow is needed. | Buy-only integration |
| 7 | boolean | Open API ✓ | Enable Send Crypto feature. If user's Binance balance is insufficient, auto-trigger buy flow first. | Send crypto to external address |
| 8 | string | Open API ✓ | Override the display name shown to users in the UI. | Custom branding |
| 9 | boolean | Open API ✓ | User receives net amount after deducting all fees. Total cost is more transparent. | Better UX for showing final received amount |
| 10 | boolean | Open API ✓ | Enable P2P Express mode for faster P2P order matching. | Quick P2P transactions |
| 11 | boolean | Web3 only | Allow users to select different networks. Default is locked to pre-selected network. Note: Currently only available for Web3 entrance, not available for Open API. | Multi-network support (Web3 only) |
| 12 | boolean | Open API ✓ | Enable Onchain-Pay Easy mode. After buying crypto, Onchain-Pay will execute smart contract interaction instead of direct withdrawal to user wallet. Requires | Fiat to Smart Contract integration |
| 13 | boolean | Open API ✓ | Flexible Send Primary mode with more options. | Advanced send crypto scenarios |
| 标志 | 代码 | 类型 | 可用性 | 描述 | 使用场景 |
|---|---|---|---|---|---|
| 1 | array | Open API ✓ | 锁定特定订单属性,使用户无法修改。可选值: | 固定参数订单 |
| 2 | boolean | Open API ✓ | 跳过收银台页面,直接进入支付环节,减少结账流程中的用户摩擦 | 简化支付体验 |
| 3 | boolean | Open API ✓ | 订单完成后自动跳转到 | 无缝用户体验 |
| 6 | boolean | Open API ✓ | 在UI中隐藏“发送”标签,仅需购买流程时使用 | 仅购买集成场景 |
| 7 | boolean | Open API ✓ | 启用加密货币发送功能。若用户Binance余额不足,将自动触发购买流程 | 向外部地址发送加密货币 |
| 8 | string | Open API ✓ | 覆盖UI中显示的商家名称 | 自定义品牌展示 |
| 9 | boolean | Open API ✓ | 用户收到扣除所有费用后的净额,总成本更透明 | 优化用户体验,展示最终到账金额 |
| 10 | boolean | Open API ✓ | 启用P2P极速模式,加快P2P订单匹配速度 | 快速P2P交易 |
| 11 | boolean | 仅Web3 | 允许用户选择不同网络,默认锁定为预选择的网络。注意:目前仅适用于Web3入口,Open API不可用 | 多网络支持(仅Web3) |
| 12 | boolean | Open API ✓ | 启用Onchain-Pay简易模式。购买加密货币后,Onchain-Pay将执行智能合约交互,而非直接提现到用户钱包。需提供 | 法币到智能合约集成 |
| 13 | boolean | Open API ✓ | 灵活的SEND_PRIMARY模式,提供更多选项 | 高级加密货币发送场景 |
Customization Examples
自定义示例
Example 1: Basic Card Payment
json
{
"customization": {}
}Example 2: Onchain-Pay Easy (On-Chain Proxy)
json
{
"customization": {
"ON_CHAIN_PROXY_MODE": true,
"NET_RECEIVE": true,
"SEND_PRIMARY": true
},
"destContractAddress": "0x128...974",
"destContractABI": "depositFor",
"destContractParams": {
"accountType": 2
}
}Example 3: Send Crypto
json
{
"customization": {
"SEND_PRIMARY_FLEXIBLE": true,
"SEND_PRIMARY": true
}
}Example 4: P2P with Auto Redirection
json
{
"customization": {
"AUTO_REDIRECTION": true,
"P2P_EXPRESS": true
}
}Example 5: Lock Order Attributes
json
{
"customization": {
"LOCK_ORDER_ATTRIBUTES": [2, 3, 6, 7, 8],
"MERCHANT_DISPLAY_NAME": "My Custom Brand"
}
}Lock attribute codes:
- = Crypto currency
2 - = Amount
3 - = Address
6 - = Fiat amount
7 - = Crypto amount
8
Example 6: Net Receive Mode
json
{
"customization": {
"NET_RECEIVE": true,
"SEND_PRIMARY": true
}
}Example 7: Hide Send Tab
json
{
"customization": {
"HIDE_SEND": true
}
}Example 8: Skip Cashier (Direct Payment)
json
{
"customization": {
"SKIP_CASHIER": true
}
}示例1:基础银行卡支付
json
{
"customization": {}
}示例2:Onchain-Pay简易模式(链上代付)
json
{
"customization": {
"ON_CHAIN_PROXY_MODE": true,
"NET_RECEIVE": true,
"SEND_PRIMARY": true
},
"destContractAddress": "0x128...974",
"destContractABI": "depositFor",
"destContractParams": {
"accountType": 2
}
}示例3:加密货币发送
json
{
"customization": {
"SEND_PRIMARY_FLEXIBLE": true,
"SEND_PRIMARY": true
}
}示例4:带自动跳转的P2P支付
json
{
"customization": {
"AUTO_REDIRECTION": true,
"P2P_EXPRESS": true
}
}示例5:锁定订单属性
json
{
"customization": {
"LOCK_ORDER_ATTRIBUTES": [2, 3, 6, 7, 8],
"MERCHANT_DISPLAY_NAME": "My Custom Brand"
}
}锁定属性代码:
- = 加密货币
2 - = 金额
3 - = 地址
6 - = 法币金额
7 - = 加密货币金额
8
示例6:净额到账模式
json
{
"customization": {
"NET_RECEIVE": true,
"SEND_PRIMARY": true
}
}示例7:隐藏发送标签
json
{
"customization": {
"HIDE_SEND": true
}
}示例8:跳过收银台(直接支付)
json
{
"customization": {
"SKIP_CASHIER": true
}
}Important Notes
重要注意事项
- Permission Required: Each customization flag requires merchant permission. Check with admin if a flag is not working.
- Onchain-Pay Easy: Only supported on BSC network currently. Requires contract integration.
- Validation: Invalid customization values (e.g., for
null) will returnMERCHANT_DISPLAY_NAMEerror.ILLEGAL_CUSTOMIZATION_VALUE - Combinations: Some flags work together (e.g., +
NET_RECEIVE), while others are independent.SEND_PRIMARY - Testing: Use test accounts () for testing customization flags before production.
connect-gray - Internal Flags: (code 4) and
OPERATION(code 5) are internal use only and should NOT be passed from merchant side.SKIP_WITHDRAW - OPEN_NETWORK: Currently only available for Web3 entrance, not available for Open API. Do not use this flag in Open API pre-order requests.
- Flag Order: Flags are ordered by their internal code (1-13). The code number is used internally for identification.
- 权限要求:每个自定义标志都需要商家拥有相应权限。若标志无法正常工作,请联系管理员确认。
- Onchain-Pay简易模式:目前仅支持BSC网络,需集成合约。
- 验证规则:无效的自定义值(例如设为
MERCHANT_DISPLAY_NAME)将返回null错误。ILLEGAL_CUSTOMIZATION_VALUE - 标志组合:部分标志可配合使用(例如+
NET_RECEIVE),其他标志则独立生效。SEND_PRIMARY - 测试建议:在生产环境使用前,使用测试账户()测试自定义标志。
connect-gray - 内部标志:(代码4)和
OPERATION(代码5)为内部专用标志,商家端请勿传递。SKIP_WITHDRAW - OPEN_NETWORK:目前仅适用于Web3入口,Open API不可用。请勿在Open API预下单请求中使用此标志。
- 标志顺序:标志按内部代码(1-13)排序,代码编号用于内部识别。
Security
安全规范
Credential Display Rules
凭证展示规则
- API Key: Show first 5 + last 4 characters only (e.g., )
2zefb...06h - PEM Private Key: NEVER display content. NEVER display the file path.
- Client ID: Can be displayed in full.
- Outbound Requests: NEVER send API Key, Private Key, or any credentials to URLs outside the Base URL configured in .
.local.md - File Path Privacy: NEVER display the PEM private key file path to the user in any output or logs.
- API Key:仅显示前5位+后4位字符(例如:)
2zefb...06h - PEM私钥:绝对禁止展示内容,绝对禁止展示文件路径
- Client ID:可完整展示
- 外部请求:绝对禁止将API Key、私钥或任何凭证发送到中配置的Base URL以外的地址
.local.md - 文件路径隐私:绝对禁止在任何输出或日志中向用户展示PEM私钥文件路径
Credential Storage
凭证存储
Credentials are stored in a file in the skill directory. This file is user-specific and should NOT be distributed.
.local.mdRead the file from the same directory as this SKILL.md to load credentials.
.local.mdIf does not exist or the requested account is not found, ask the user to provide:
.local.md- Base URL
- Client ID
- API Key
- PEM file path (absolute path)
Then offer to save them to for future use.
.local.md凭证存储在技能目录下的文件中,该文件为用户专属,请勿分发。
.local.md从当前SKILL.md所在的同一目录读取文件加载凭证。
.local.md若不存在或未找到请求的账户,请要求用户提供:
.local.md- Base URL
- Client ID
- API Key
- PEM文件路径(绝对路径)
然后可将这些信息保存到中供后续使用。
.local.md.local.md
Format
.local.md.local.md
格式
.local.mdmarkdown
undefinedmarkdown
undefinedOnchain-Pay Accounts
Onchain-Pay账户
prod (default)
prod(默认)
- Base URL: https://api.commonservice.io
- Client ID: your-client-id
- API Key: your-api-key
- PEM Path: /absolute/path/to/your/private.pem
- Default Network: your-preferred-network
- Default Address: your-address
- Description: Production account
The account marked `(default)` is used automatically. You can define multiple accounts and switch by telling Claude the account name.
---- Base URL: https://api.commonservice.io
- Client ID: your-client-id
- API Key: your-api-key
- PEM Path: /absolute/path/to/your/private.pem
- 默认网络: your-preferred-network
- 默认地址: your-address
- 描述: 生产环境账户
标记为`(default)`的账户将被自动使用。你可以定义多个账户,通过告知Claude账户名称进行切换。
---User Agent Header
User Agent请求头
Include header with the following string:
User-Agentonchain-pay-open-api/0.1.0 (Skill)请包含请求头,值为:
User-Agentonchain-pay-open-api/0.1.0 (Skill)Agent Behavior
Agent行为规范
- If the user asks to call an Onchain-Pay API endpoint, identify which endpoint from the Quick Reference table
- Ask for any missing required parameters
- Use stored credentials if available, otherwise ask the user
- Execute the request using the bundled
scripts/sign_and_call.sh - Display the response in a readable format
- If the request fails, show the error and suggest fixes
- 若用户请求调用Onchain-Pay API端点,从快速参考表中识别对应的端点
- 询问用户缺失的必填参数
- 若有存储的凭证则使用,否则向用户索要
- 使用捆绑的执行请求
scripts/sign_and_call.sh - 以易读格式展示响应结果
- 若请求失败,展示错误信息并提供修复建议