Skip to main content

Pending transactions

onMempoolTransaction() calls you for every pending transaction seen on a network, the moment it appears — the whole mempool, not just one address. To follow the pending transactions of a single address, use onPendingTransaction().

const btc = cg.explore(cg.networks.bitcoin)

btc.onMempoolTransaction(({ txid, vsize, feeRate }) => {
console.log(`${txid} — ${vsize} vB at ${feeRate ?? '?'} sat/vB`)
})
High volume

Busy networks produce several pending transactions per second. Keep the callback light, and prefer the address-scoped events whenever you only care about a few addresses.

Pending events may be unavailable on some networks

Pending tracking is an optional capability of each network. Subscribing where it is not available succeeds, but no events arrive.

UTXO networks​

FieldTypeDescription
txidstringTransaction id
seenAtnumberUnix seconds when the transaction was first seen
vsizenumberVirtual size, in vbytes
feeAmount | nullFee paid; null when an input could not be resolved
feeRatenumber | nullFee rate in satoshis per vbyte; null when the fee is unknown
inputs[]{ prevTxid, prevN, prevAmount? }The outputs being spent; prevAmount is present when it could be resolved
outputs[]{ n, amount }The outputs created

EVM networks​

Pending events cover the native coin only — gas is not included, and token transfers are not visible until the transaction is mined.

FieldTypeDescription
hashstringTransaction hash
fromstringSender
tostring | nullRecipient; null for a contract creation
valueAmountNative value moved
noncenumberSender nonce
inputstringCalldata — "0x" for a plain transfer
gasbigintGas limit
gasPricebigint | nullLegacy gas price in wei, when present
maxFeePerGasbigint | nullEIP-1559 max fee per gas in wei, when present
maxPriorityFeePerGasbigint | nullEIP-1559 priority fee per gas in wei, when present
typenumber | nullTransaction type (0 legacy, 1 EIP-2930, 2 EIP-1559), when reported
chainIdnumber | nullChain id, when reported
seenAtnumberUnix seconds when the transaction was first seen
const eth = cg.explore(cg.networks.ethereum)

eth.onMempoolTransaction(({ hash, value, maxFeePerGas }) => {
if (value.min() >= 100n * 10n ** 18n) {
console.log('Whale alert:', hash, value.base(), 'ETH', 'max fee', maxFeePerGas, 'wei')
}
})