Loading...
Loading...
This skill should be used when the user asks to 'broadcast transaction', 'send tx', 'estimate gas', 'simulate transaction', 'check tx status', 'track my transaction', 'get gas price', 'gas limit', 'broadcast signed tx', or mentions broadcasting transactions, sending transactions on-chain, gas estimation, transaction simulation, tracking broadcast orders, or checking transaction status. Covers gas price, gas limit estimation, transaction simulation, transaction broadcasting, and order tracking across Solana, Ethereum, Base, BSC, Polygon, Arbitrum, and 20+ other chains. Do NOT use for swap quote or execution — use okx-dex-swap instead. Do NOT use for general programming questions about transaction handling.
npx skill4agent add okx/onchainos-skills okx-onchain-gatewayhttps://web3.okx.com/api/v6/dex/pre-transaction/api/v6/dex/post-transactionOK-ACCESS-KEYOK-ACCESS-SIGNOK-ACCESS-PASSPHRASEOK-ACCESS-TIMESTAMPOKX_API_KEYOKX_SECRET_KEYOKX_PASSPHRASEimport crypto from 'crypto';
const BASE = 'https://web3.okx.com';
// Signature rule:
// GET → body = "", requestPath includes query string (e.g., "/api/v6/dex/pre-transaction/gas-price?chainIndex=1")
// POST → body = JSON string of request body, requestPath is path only (e.g., "/api/v6/dex/pre-transaction/gas-limit")
// Note: Endpoints #1-2, #6 are GET; endpoints #3-5 are POST
async function okxFetch(method: 'GET' | 'POST', path: string, body?: object) {
const timestamp = new Date().toISOString();
const bodyStr = body ? JSON.stringify(body) : '';
const sign = crypto
.createHmac('sha256', process.env.OKX_SECRET_KEY!)
.update(timestamp + method + path + bodyStr)
.digest('base64');
const headers: Record<string, string> = {
'OK-ACCESS-KEY': process.env.OKX_API_KEY!,
'OK-ACCESS-SIGN': sign,
'OK-ACCESS-PASSPHRASE': process.env.OKX_PASSPHRASE!,
'OK-ACCESS-TIMESTAMP': timestamp,
'Content-Type': 'application/json',
};
const res = await fetch(`${BASE}${path}`, {
method,
headers,
...(body && { body: bodyStr }),
});
if (res.status === 429) throw { code: 'RATE_LIMITED', msg: 'Rate limited — retry with backoff', retryable: true };
if (res.status >= 500) throw { code: `HTTP_${res.status}`, msg: 'Server error', retryable: true };
const json = await res.json();
if (json.code !== '0') throw { code: json.code, msg: json.msg || 'API error', retryable: false };
return json.data;
}{ "code": "0", "data": [...], "msg": "" }code"0"// Get current gas price on Ethereum
const gasPrice = await okxFetch('GET', '/api/v6/dex/pre-transaction/gas-price?' + new URLSearchParams({
chainIndex: '1',
}));
// → gasPrice[].normal, gasPrice[].min, gasPrice[].max (legacy)
// → gasPrice[].eip1559Protocol.suggestBaseFee, .proposePriorityFee (EIP-1559)
console.log(`Gas price: ${gasPrice[0].eip1559Protocol?.suggestBaseFee ?? gasPrice[0].normal} wei`);// Broadcast a signed EVM transaction
const result = await okxFetch('POST', '/api/v6/dex/pre-transaction/broadcast-transaction', {
signedTx: '0xf86c...signed_hex',
chainIndex: '1',
address: '0xYourWallet',
});
// → result[].orderId — use with /post-transaction/orders to track
console.log(`Broadcast success, orderId: ${result[0].orderId}`);| Chain | chainIndex | Chain | chainIndex |
|---|---|---|---|
| Ethereum | | Arbitrum | |
| BSC | | Base | |
| Polygon | | Solana | |
| # | Method | Path | Docs |
|---|---|---|---|
| 1 | GET | | onchain-gateway-api-chains |
| 2 | GET | | onchain-gateway-api-gas-price |
| 3 | POST | | onchain-gateway-api-gas-limit |
| 4 | POST | | onchain-gateway-api-simulate-transaction |
| 5 | POST | | onchain-gateway-api-broadcast-transaction |
| 6 | GET | | onchain-gateway-api-orders |
User: "Swap 1 ETH for USDC and broadcast it"
1. okx-dex-swap /aggregator/swap → get tx calldata { from, to, data, value, gas }
↓ user signs the tx locally
2. okx-onchain-gateway /pre-transaction/broadcast-transaction → broadcast signed tx → orderId
3. okx-onchain-gateway /post-transaction/orders → track order status until confirmedtx.datatx.totx.valuetx.gassignedTxorderIdorderIdUser: "Simulate this transaction first, then broadcast if safe"
1. okx-onchain-gateway /pre-transaction/simulate → check if tx will succeed
↓ simulation passes (no revert)
2. okx-onchain-gateway /pre-transaction/broadcast-transaction → broadcast signed tx
3. okx-onchain-gateway /post-transaction/orders → track order statusUser: "Check if I have enough ETH, swap for USDC, then send it"
1. okx-wallet-portfolio /balance/token-balances-by-address → verify ETH balance
↓ sufficient balance confirmed
2. okx-dex-swap /aggregator/swap → get swap tx calldata
↓ user signs
3. okx-onchain-gateway /pre-transaction/broadcast-transaction → broadcast
4. okx-onchain-gateway /post-transaction/orders → trackGET /pre-transaction/gas-pricePOST /pre-transaction/gas-limitPOST /pre-transaction/simulatePOST /pre-transaction/broadcast-transactionGET /post-transaction/ordersGET /pre-transaction/supported/chainchainIndexsignedTxaddressfromAddresstoAddresstxAmountextJson.inputDataaddresschainIndexorderId/gas-price/gas-limit/simulate/broadcast-transactionorderId/orders| Just completed | Suggest |
|---|---|
| 1. Estimate gas limit for a specific tx → |
| 1. Simulate the transaction → |
| 1. Broadcast the transaction → |
| 1. Track order status → |
| 1. Check wallet balance after confirmation → |
| Field | Type | Description |
|---|---|---|
| String | Chain unique identifier (e.g., "1") |
| String | Chain name (e.g., "Ethereum") |
| String | Chain logo URL |
| String | Chain short name (e.g., "ETH") |
| Param | Type | Required | Description |
|---|---|---|---|
| String | Yes | Chain ID (e.g., |
| Field | Type | Description |
|---|---|---|
| String | Normal gas price (legacy) |
| String | Minimum gas price |
| String | Maximum gas price |
| Boolean | Whether EIP-1559 is supported |
| String | Suggested base fee |
| String | Current base fee |
| String | Proposed priority fee |
| String | Safe (slow) priority fee |
| String | Fast priority fee |
proposePriorityFeesafePriorityFeefastPriorityFeeextremePriorityFee{
"code": "0",
"data": [{
"normal": "20000000000",
"min": "15000000000",
"max": "30000000000",
"supporteip1559": true,
"eip1559Protocol": {
"suggestBaseFee": "18000000000",
"baseFee": "18000000000",
"proposePriorityFee": "2000000000",
"safePriorityFee": "1000000000",
"fastPriorityFee": "3000000000"
}
}],
"msg": ""
}| Param | Type | Required | Description |
|---|---|---|---|
| String | Yes | Chain ID |
| String | Yes | Sender address |
| String | Yes | Recipient / contract address |
| String | No | Transfer value in minimal units (default "0") |
| Object | No | Extended parameters |
| String | No | Encoded calldata (for contract interactions) |
| Field | Type | Description |
|---|---|---|
| String | Estimated gas limit |
{
"code": "0",
"data": [{ "gasLimit": "21000" }],
"msg": ""
}| Param | Type | Required | Description |
|---|---|---|---|
| String | Yes | Chain ID |
| String | Yes | Sender address |
| String | Yes | Recipient / contract address |
| String | No | Transfer value in minimal units |
| String | No | Gas price in wei (for legacy EVM txs) |
| String | No | Priority fee in micro-lamports (Solana only) |
| Object | Yes | Extended parameters |
| String | Yes | Encoded calldata |
| Field | Type | Description |
|---|---|---|
| String | Transaction intent description |
| Array | Asset changes from the simulation |
| String | Asset type |
| String | Token name |
| String | Token symbol |
| Number | Token decimals |
| String | Token contract address |
| String | Raw amount change |
| String | Gas consumed in simulation |
| String | Failure reason (empty string = success) |
| Array | Risk information (address, addressType) |
{
"code": "0",
"data": [{
"intention": "Token Swap",
"assetChange": [{"assetType": "token", "name": "USDC", "symbol": "USDC", "decimals": 6, "address": "0xa0b8...", "rawValue": "-100000000"}],
"gasUsed": "145000",
"failReason": "",
"risks": []
}],
"msg": ""
}| Param | Type | Required | Description |
|---|---|---|---|
| String | Yes | Fully signed transaction (hex for EVM, base58 for Solana) |
| String | Yes | Chain ID |
| String | Yes | Sender wallet address |
| String | No | JSON string of extra options (must |
extraData| Field | Type | Description |
|---|---|---|
| Boolean | Enable MEV protection (ETH/BSC/SOL/BASE) |
| String | Jito signed transaction (Solana) |
| Field | Type | Description |
|---|---|---|
| String | OKX order tracking ID |
| String | On-chain transaction hash |
{
"code": "0",
"data": [{ "orderId": "123456789", "txHash": "0xabc...def" }],
"msg": ""
}| Param | Type | Required | Description |
|---|---|---|---|
| String | Yes | Wallet address |
| String | Yes | Chain ID |
| String | No | Specific order ID (from broadcast response) |
| String | No | Filter by status: |
| String | No | Pagination cursor |
| String | No | Max results per page (default 20) |
| Field | Type | Description |
|---|---|---|
| String | Pagination cursor for next page |
| Array | Order list (nested under each data element) |
| String | Order ID |
| String | On-chain transaction hash |
| String | Chain ID |
| String | Sender address |
| String | Order status: |
| String | Failure reason (if failed) |
{
"code": "0",
"data": [{
"cursor": "1",
"orders": [{
"orderId": "123456789",
"txHash": "0xabc...def",
"chainIndex": "1",
"address": "0x...",
"txStatus": "2",
"failReason": ""
}]
}],
"msg": ""
}GET /api/v6/dex/pre-transaction/gas-price?chainIndex=1
-> Display:
Base fee: 18 Gwei
Max fee: 25 Gwei
Priority fee: 2 GweiPOST /api/v6/dex/pre-transaction/simulate
Body: {
"chainIndex": "1",
"fromAddress": "0xYourWallet",
"toAddress": "0xDexContract",
"txAmount": "1000000000000000000",
"extJson": { "inputData": "0x..." }
}
-> Display:
Simulation: SUCCESS (failReason is empty)
Estimated gas: 145,000
Intent: Token SwapPOST /api/v6/dex/pre-transaction/broadcast-transaction
Body: {
"signedTx": "0xf86c...signed",
"chainIndex": "1",
"address": "0xYourWallet"
}
-> Display:
Broadcast successful!
Order ID: 123456789
Tx Hash: 0xabc...defGET /api/v6/dex/post-transaction/orders?address=0xYourWallet&chainIndex=1&orderId=123456789
-> Response: data[0].orders[0] contains order details
-> Display:
Order 123456789: Success (txStatus=2)
Tx Hash: 0xabc...def
Confirmed on-chainsignedTx/pre-transaction/supported/chain50011signedTxtxHash18.5 Gwei210001450001.5 ETHeip1559Protocol.suggestBaseFeeeip1559Protocol.proposePriorityFeenormalokx-dex-swapokx-dex-marketokx-wallet-portfoliookx-dex-tokenokx-onchain-gateway