6

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?

9

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.

  • 2
    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. – medvedev1088 Feb 16 '18 at 7:22
6

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.

0

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.

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.