10

When a transaction that executes a smart contract fails (maybe for an exception or require rule), is the transaction propagated to the network and included in the blockchain? If yes, what would be the reason for that?

4 Answers 4

12

It is included in the blockchain. The user still has to pay for the gas used to process the transaction, even if the transaction reverted. The exception to this, of course, is if the account sending the transaction doesn't have enough ETH to cover the tx fee and the ETH sent. In this case, the transaction can't be included in the blockchain at all because it can't cover the fee.

1
  • 5
    A few other conditions that make a transaction invalid and not be included in the blockchain: (1) transaction nonce is not equal to the sender account's current nonce, (2) transaction gas limit is smaller than the intrinsic gas 21000. Full list of conditions is section 6 of yellowpaper. Commented Feb 16, 2018 at 7:22
8

Just to add to @flygoing's answer...

If yes, what would be the reason for that?

By including it in the blockchain, you force the user to pay for the gas associated with the contract call. This acts as a financial disincentive to attackers who could otherwise spam the network with transactions they have deliberately engineered to fail.

1

Eth will charge gas for every step, gas will cost you. Any thing related to cost will be recorded in the ledger. Ledger will be maintained in blockchain.

There are most 2 common ways transaction's may fail, now lets see what will happen in eth ledger:

  1. P2P transfer's: When A want to transfer X Eth's B, I this case lets assume A doesn't have sufficient funds, then eth will verify A has funds (X+trans fee). A does n't have so it will fail. Because it will not even record in block chain

  2. Contract: Assume when user A executing contract function, to complete computation for that function it may required 200 gas units. But user passed 100 gas units while calling function. Then at this movement Eth will execute 100 equivalent gas step's. Trans cost = 100*gasPrice will be charge from user and Eth client will throw out of gas exception. And Eth will credit 100*gasPrice Eth's to miner account. And this will record in block chain. Because ledger changed. Any state changes will be recorded in Eth network.

Any exception while executing function Eth will revert back to function storage.

1

To summarize the answers in this thread, failed transactions can be either included or not included.

Those can be included are mostly smart contract interactions. This means, the transactions satisfy all the conditions to be included on the ledger except the environmental or internal conditions that are not possible to be checked when seleted from the memory pool.

Those cannot be included are transactions that can be filtered out in the process of collecting valid transactions into the next block, due to conditions that can be checked in this process, like not enough Ethers, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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