Skip to main content

Gas Fee (Real-time)

Receive gas price updates over WebSocket instead of polling Get Gas Fee. A server-side job quotes every network the platform supports and publishes one message per network to the broadcast:gas_fee channel; subscribers receive them automatically.

Connection​

1. Connect to the realtime server​

Open a Socket.IO connection with a valid access token:

import { io } from "socket.io-client";

const socket = io("wss://test-socket.tokenizationtr.com", {
auth: {
token: "<access_token>",
},
});

2. Subscribe to the gas fee channel​

socket.on("connect", () => {
socket.emit("subscribe", "broadcast:gas_fee");
});

3. Listen for messages​

Gas fee updates arrive as message events whose type is gas_fee. Each message describes one network; keep the latest message per network_id.

const latestByNetwork = new Map();

socket.on("message", (data) => {
if (data.type !== "gas_fee") return;
latestByNetwork.set(data.payload.network_id, data.payload);
// {
// network_id: 137,
// safe_gas_price: "0.00000003",
// propose_gas_price: "0.000000031",
// fast_gas_price: "0.000000034",
// native_currency_symbol: "POL",
// updated_at: "2026-11-09T10:15:00Z"
// }
});

4. Unsubscribe (optional)​

socket.emit("unsubscribe", "broadcast:gas_fee");

Message format​

{
"type": "gas_fee",
"payload": {
"network_id": 137,
"safe_gas_price": "0.00000003",
"propose_gas_price": "0.000000031",
"fast_gas_price": "0.000000034",
"native_currency_symbol": "POL",
"updated_at": "2026-11-09T10:15:00Z"
},
"timestamp": "2026-11-09T10:15:00Z"
}

Envelope fields​

FieldTypeDescription
typestringMessage type. Always gas_fee on this channel
payloadobjectOne network's gas price quote
timestampstringISO 8601 time the message was published

Payload fields​

FieldTypeDescription
network_idintegerThe network's numeric id (the EVM chain id, e.g. 1 Ethereum, 137 Polygon). See Networks
safe_gas_pricestringGas price for a slow, low-cost confirmation
propose_gas_pricestringGas price for a standard confirmation
fast_gas_pricestringGas price for a fast confirmation
native_currency_symbolstringNative currency the prices are expressed in (e.g. POL, ETH)
updated_atstringISO 8601 time the quote was taken

Prices are decimal strings in the network's native currency per unit of gas (not Gwei). Multiply by 1000000000 to get Gwei.

Notes​

  • Broadcast channels (prefixed broadcast:) are available to every authenticated connection.
  • A network whose quote fails in a cycle is skipped for that cycle; the others are still published.
  • An expired or invalid token fails the connection with an Authentication error.

Environments​

EnvironmentURL
Testwss://test-socket.tokenizationtr.com