I've read on What is the dust limit on Bitcoin Cash transactions? that small transaction with less than 546 Satoshi get rejected by miners, but I'm confused.

Is that limited applied to sum of inputs or outputs (excluding miner fee)?

I'm trying to implement bitcoin testnet wallet on JavaScript,

async function signTransaction(fromECPair, to, amountToSend) {
    const address = getP2pkhAddress(fromECPair);
    const balance = await getBalance(address);
    const utxo = await getUtxo(address);

    const tx = new Bitcoin.TransactionBuilder(BitcoinNetwork);
    for (let i = 0; i < utxo.length; i++) {
        tx.addInput(utxo[i].txid, utxo[i].vout);

    let transactionFee = (148*utxo.length + 34*2 + 10) * price_per_byte; 
    let amountToKeep = balance - amountToSend - transactionFee;
    tx.addOutput(to, amountToSend);
    tx.addOutput(address, amountToKeep);

    for (let i = 0; i < utxo.length; i++) {
        tx.sign(i, fromECPair);

I've just made transaction with one of output less than 546 satoshi so it's definitely possible to make at such output at least on testnet https://chain.so/tx/BTCTEST/021c782fbb75dab2ca843d83a3709e0e846f0d3e99c14a5826f7e18cccfeab25 So attacker can potentially spam my address with lots of tiny outputs and this naive wallet implementation won't work (it would be more costly to sign these UTXOs than value they have). What would be the correct way to prevent that?


For a transaction to be standard, Each of the outputs has to be at least 546 satoshis. (except an OP_RETURN output, which has some extra rules).

Testnet does not enforce standardness rules.

You can still include a nonstandard transaction in your block in mainnet, but still, those transactions are not relayed.


The "dust limit" is a standardness rule, not a consensus rule. Miners can always violate these as they only effect transaction relay through the network, rather than making a transaction if these rules are violated.

  • aren't miner care only about transaction fees? What prevent sender to do transaction with lots of outputs with 1 satoshi but acceptable price_per_byte?
    – lebed2045
    Mar 10 '19 at 7:55

The mining fee is calculated as the sum of all inputs minus the sum of all outputs. As long as it is positive and less than the sum of all inputs it is valid.

As the fee is not an extra output it takes no space in transactions. Not even the coinbase so there are no dust rules applied to fees and the fees can be as low as one Satoshi (if miners accept those) certainly you could self mine but then the fee would go to you anyway.

(I am not sure what would happen in the hypothetical case thatin the future the block reward is zero and miners mine a block with only one transaction of a fee below the dust limit producing a coinbase with an output below the dust limit)


it's definitely possible to make at such output at least on testnet

It is possible to make such output on mainnet, but such transaction is non-standard on mainnet and most of miners will ignore it under default client settings. The probability that such tx would be delivered to a miner and confirmed is very small.

What would be the correct way to prevent that?

Just do not spend dust inputs if any. E.g. I have two dust inputs on my address {first} {second} which I do not want to spend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.