Type/to search
Built-in Functions
Structures
Built-in Variables and Constants
Conventions
Exchanges
Capability Matrix
Centralized Exchanges
Decentralized Exchanges (DEX)
Prediction Markets
Securities and Futures
On-chain & Custom

Queries, synchronizes or sets the nonce counter used when sending transactions.

exchange.IO(k)
exchange.IO(k, "sync")
exchange.IO(k, nonce)

Examples

Query the nonce status and resynchronize.

javascript
function main() { // latest: number of transactions confirmed on-chain; pending: count seen by the node, including // pending transactions; local: the next nonce to be used locally var st = exchange.IO("nonce") Log("Address:", st.address, "latest:", st.latest, "pending:", st.pending, "local:", st.local) if (Number(st.pending) > Number(st.latest)) { Log("There are", Number(st.pending) - Number(st.latest), "transactions not yet confirmed on-chain") } // After sending transactions from the same address elsewhere (wallet, other programs), you can // manually resynchronize with the chain st = exchange.IO("nonce", "sync") Log("After sync, local:", st.local) }

Returns

TypeDescription

object

Returns a {address, latest, pending, local} object: latest is the number of transactions already confirmed on-chain; pending is the count returned by the node, including pending transactions; local is the next nonce in the local record (null if no transaction has been sent yet). All values are returned as strings.

Arguments

NameTypeRequiredDescription

k

string

Yes

Functionality of the exchange.IO() function. When set to nonce, the function is used to manage the nonce.

nonce

string / number

No

When this parameter is omitted, only the nonce status is queried. When sync is passed, the local record is resynchronized based on the pending count returned by the node. When a numeric value is passed, the next nonce in the local record is set to that value.

See Also

Remarks

The nonce is assigned automatically when sending a transaction: the larger of the pending count returned by the node and the next nonce in the local record is used. If the node count is larger, it means the address has sent transactions elsewhere, so the node's value is used. If the local record is larger, it means transactions sent by yourself have not yet been detected by the node (for example, those sent through the private channel of exchange.IO("sendBase", ...)), so the local value continues to be used; therefore, the nonce will not be reused when sending transactions consecutively. When the node returns a nonce-too-low error or a pending transaction already exists for that nonce, the system automatically resynchronizes and resends once. When the local record is ahead of the node and no new transaction has been confirmed on-chain for a long time (5 minutes), it is determined that an intermediate transaction has been dropped, and the nonce automatically falls back to the node's count.

The local record is only valid within the same exchange object (the same bot). When multiple bots share one wallet, they cannot access each other's records, so nonce conflicts may still occur. It is recommended that each bot use a separate wallet.

When sending a transaction, you can also set nonce in the last parameter of exchange.IO("api", ...) to specify the nonce manually.

Currently only Ethereum (EVM) chains are supported; TRON is not supported yet.