1

When one deploy a smart contract in the Ethereum network, the creator adds on it a gas limit and a gas price for transaction. Then, a miner executes the contract to verify the transaction and he gets the gas by the creator. My questions are:

1) Does all the hosts in the network execute the smart contract, after the miner puts it in a block?

2) If it is so, does they take some ether/gas by doing this by the creator of the contract? If not, does this mechanism do not entail any economic losses to hosts?

1

When a contract is deployed, it is not executed by the miner. The miner just mines the transaction and makes the byte code of the contract available in the block chain. As a consequence, the creator pays just the cost for contact creation, but not for execution of the contract, and he pays it only to the miner of the block.

A contract is executed if a function of the contract is called. This is again done using a transaction, which is this time directed to the address of the contract address. Now, the contract code is executed, but again only by the miner of the block. The results of the function that was called is put on the blockchain, where it can be read by everyone.

Note that if you are just reading data from the blockchain, but not changing the state of the blockchain, you do not need to send a transaction, and therefore you do not need to spend Ether. In this case, you invoke a function of the contract locally at the node you are connected to, the function is then carried out of the EVM of the node you are connected to.

  • Thank you for your answer. I have only another question (maybe a silly one). When a miner put the transaction of an executed function in the block, and the other hosts verify it, does they have to execute the function to verify the correctness of the miner's job? If it is so, doesn't they spend gas to verify it? – Bruce Wayne Nov 18 '17 at 13:51
  • You are right in the sense that every miner spends effort trying to mine the next block. And since the transactions and functions executed by the contracts change the state of the block, the miners run the contract code while they are mining. However, only the miner that actually mines the block is rewarded the gas. So I think the key to resolving your question is looking at the whole topic such that gas is not spent by the miners, but by the creator of the contract. The miners spend effort (energy, hardware, time) and are rewarded with gas. – gisdev_p Nov 18 '17 at 16:07
  • So the creator of the contract pays gas only to the miner that mines the block containing the transaction of the executed function, and not everyone who try to mine the block containing it? – Bruce Wayne Nov 18 '17 at 17:32
  • Yes, that's correct. – gisdev_p Nov 18 '17 at 17:35

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.