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

<p>Testnet does not enforce standardness rules.</p>

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

CC BY-SA 4.0
2019-03-10T07:51:39.683Z
I just made transaction, please see the link. Does it mean testnet works differently than mainnet?
lebed2045
CC BY-SA 4.0
2019-03-10T08:01:16.030Z
made  another tx 10 outputs with 1 satoshi each https://live.blockcypher.com/btc-testnet/tx/e729f400518ee3cdf65d98123712436564aaf161583dc429737ed4a4a1eab907/
lebed2045
CC BY-SA 4.0
2022-05-09T12:45:55.897Z
this means that dust doesn't exist in testnet? Can have valid transaction with less than 546 satoshi?
Giacomo Brunetta
CC BY-SA 4.0
2019-03-10T07:27:26.647Z
2019-03-10T09:51:21.593Z
2019-03-10T09:51:21.593Z
MCCCS
<blockquote>
  <p>it's definitely possible to make at such output at least on testnet </p>
</blockquote>

<p>It is possible to make such output on mainnet, but such transaction is <strong>non-standard on mainnet</strong> 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.</p>

<blockquote>
  <p>What would be the correct way to prevent that?</p>
</blockquote>

<p>Just do not spend dust inputs if any. E.g. I have two dust inputs on my address <a href="https://www.blockchain.com/btc/tx/b8e9acf88c65c55b1f91094684cf513445202fda0601738bcda66153ded4f6b4" rel="nofollow noreferrer">{first}</a> <a href="https://www.blockchain.com/btc/tx/c344a1279827f736004c420e8966493209126961844207b88d5e2f9d28577aec" rel="nofollow noreferrer">{second}</a> which I do not want to spend.</p>

CC BY-SA 4.0
2019-03-10T09:39:04.967Z
2019-03-10T09:44:22.793Z
2019-03-10T09:44:22.793Z
amaclin
<p>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. </p>

<p>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. </p>

<p>(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) </p>

CC BY-SA 4.0
2019-03-10T09:23:37.563Z
2019-03-10T09:23:37.563Z
Rene Pickhardt
<p>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. </p>

CC BY-SA 4.0
2019-03-10T07:55:17.557Z
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
CC BY-SA 4.0
2022-05-09T12:46:01.030Z
this means that dust doesn't exist in testnet? Can have valid transaction with less than 546 satoshi?
Giacomo Brunetta
CC BY-SA 4.0
2019-03-10T07:51:08.910Z
2019-03-10T07:51:08.910Z
Claris
<p>I've read on <a href="https://bitcoin.stackexchange.com/questions/71604/what-is-the-dust-limit-on-bitcoin-cash-transactions">What is the dust limit on Bitcoin Cash transactions?</a> that small transaction with less than 546 Satoshi get rejected by miners, but I'm confused. </p>

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

<p>I'm trying to implement bitcoin testnet wallet on JavaScript, </p>

<pre><code>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 &lt; 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 &lt; utxo.length; i++) {
        tx.sign(i, fromECPair);
    }
}
</code></pre>

<p>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 <a href="https://chain.so/tx/BTCTEST/021c782fbb75dab2ca843d83a3709e0e846f0d3e99c14a5826f7e18cccfeab25" rel="nofollow noreferrer">https://chain.so/tx/BTCTEST/021c782fbb75dab2ca843d83a3709e0e846f0d3e99c14a5826f7e18cccfeab25</a>
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? </p>

<dust>
Does Bitcoin dust limit include miner fee as well?
lebed2045
# Does Bitcoin dust limit include miner fee as well?

(Asked by: username_0 on 2019-03-10)

I've read on [What is the dust limit on Bitcoin Cash transactions?](https://bitcoin.stackexchange.com/questions/71604/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?

**Tags:** dust


---

## 4 answers

### Answer by username_1 on 2019-03-10. Score: 1

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.

> **Comments:**
> **username_0**: I just made transaction, please see the link. Does it mean testnet works differently than mainnet?  
> **username_0**: made  another tx 10 outputs with 1 satoshi each https://live.blockcypher.com/btc-testnet/tx/e729f400518ee3cdf65d98123712436564aaf161583dc429737ed4a4a1eab907/  
> **username_2**: this means that dust doesn't exist in testnet? Can have valid transaction with less than 546 satoshi?  

---

### Answer by username_3 on 2019-03-10. Score: 0

> 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}](https://www.blockchain.com/btc/tx/b8e9acf88c65c55b1f91094684cf513445202fda0601738bcda66153ded4f6b4) [{second}](https://www.blockchain.com/btc/tx/c344a1279827f736004c420e8966493209126961844207b88d5e2f9d28577aec) which I do not want to spend.


---

### Answer by username_4 on 2019-03-10. Score: 0

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)


---

### Answer by username_5 on 2019-03-10. Score: 0

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.

> **Comments:**
> **username_0**: 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?  
> **username_2**: this means that dust doesn't exist in testnet? Can have valid transaction with less than 546 satoshi?  

---

