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

Cancels a transaction that has not yet been included on-chain: it sends a zero-amount transaction to yourself using the same nonce as the original transaction with a higher fee; once this transaction is included on-chain first, the original transaction becomes invalid.

exchange.IO(k, txHash)
exchange.IO(k, txHash, options)

Examples

Cancel a transaction that has been sent.

javascript
function main() { var USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" var spender = "0x1111111254EEB25477B68fb85Ed929f73A960582" var txHash = exchange.IO("api", USDC, "approve", spender, "1000000") Log("Sent:", txHash) // First use dryRun to check the fee of the replacement transaction (without sending) Log(JSON.stringify(exchange.IO("cancelTx", txHash, { dryRun: true, multiplier: 1.5 }))) // This transaction is no longer needed: send a zero-amount transaction to yourself using the // same nonce with a higher fee; it replaces the original transaction once it is included // on-chain first var cancelHash = exchange.IO("cancelTx", txHash) Log("Cancellation transaction:", cancelHash) }

Returns

TypeDescription

string / object

Returns the hash of the cancellation transaction; when dryRun is enabled, returns the content of the cancellation transaction.

Arguments

NameTypeRequiredDescription

k

string

Yes

Function of the exchange.IO() function. When set to cancelTx, it indicates that the function is used to cancel a transaction.

txHash

string

Yes

Hash of the transaction to be replaced that has not yet been included on-chain. The transaction must have been sent from the current wallet.

options

object

No

Optional settings: multiplier is the fee multiplier, between 1.1 and 10, 1.125 by default; dryRun set to true only signs without sending and returns the replacement transaction (the same fields as exchange.IO("api", ...) with dryRun, plus replaces, the hash of the transaction being replaced).

See Also

Remarks

The replacement transaction reuses the nonce of the original transaction, and the fee is scaled up by multiplier (default value is 1.125, minimum value is 1.1; nodes require both the tip and maxFee of the replacement transaction to be increased by at least 10%), and will not be lower than the current suggested value of the network.

The cancellation is not guaranteed to succeed: if the original transaction is included in a block first, the cancellation transaction will become invalid because the nonce has already been used.

When the original transaction has already been included on-chain, the node cannot find the original transaction (for example, when it was sent through a private channel), or the original transaction was not sent from the current wallet, the function returns a null value and reports an error.

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

Fee calculation: if the original is an EIP-1559 transaction, the tip is the larger of the original tip × multiplier and the current suggested tip, and the max fee is the larger of the original max fee × multiplier and 2 × baseFee + tip; if the original is a legacy transaction, the gas price is the larger of the original gas price × multiplier and the node's eth_gasPrice. The cancelling transaction uses a gas limit of 21000.

The original transaction is looked up on the node configured on the exchange object; when exchange.IO("sendBase", ...) is set, the replacement is broadcast through that node.