0

I started with smart contracts and now having tons of doubts and expecting answers from experts. I read in one of the tutorials with insurance as an example - if 'date = '01-01-2019' then 'send money to all clients aged > 60'. Now this is the smart contract. Now i have the following questions

1) This is now getting pushed to the nodes in the block chain and why everyone is expected to execute this ?

2) If everyone is executing then will not the "then" condition executed that many times? i.e. wont the clients > 60 get the money == no of nodes / miners executing ?

3) If i try to relate this with Bit Coin, the miner does the proof of work and whoever finds the nonce with the HASH will be the winner - In this case - who gets the Ether ? - If everyone is executing who decides who is the winner and should get the 5 Ether?

4) Who pays the ether -i assume in this example the insurance company does that - please advise if i am not correct .

5) The smart contract code says - send money to all clients > age 60. Are all the clients expected to be in the Block Chain network with their address ? - Are they expected to have a wallet or account or client so that they get registered in the ledger .

Apologies if these are basic questions and i request the team to help for me to proceed to next stage ....thanks a bunch in advance.

1

1) This is now getting pushed to the nodes in the block chain and why everyone is expected to execute this ?

Everyone is not executing this. The code is only executed once. By the miner who mines the transaction first. After that its functions are called from other users or by you to interact with the smart contract.

2) If everyone is executing then will not the "then" condition executed that many times? i.e. wont the clients > 60 get the money == no of nodes / miners executing ?

No it is not getting executed by every miner. Every miner is just trying to put it on the blockchain.

3) If i try to relate this with Bit Coin, the miner does the proof of work and whoever finds the nonce with the HASH will be the winner - In this case - who gets the Ether ? - If everyone is executing who decides who is the winner and should get the 5 Ether?

The one do does this first, gets the reward. Then the new block is propagated which compels the miners to stop working on that block and get back to mining other blocks.

4) Who pays the ether -i assume in this example the insurance company does that - please advise if i am not correct

After you create the contract(insurance in the case) you have to pass some ether to it. This ether is stored within the contract which can be used by the owner of the contract to send it to its users. Yes contracts can store ether.

5) The smart contract code says - send money to all clients > age 60. Are all the clients expected to be in the Block Chain network with their address ? - Are they expected to have a wallet or account or client so that they get registered in the ledger .

Yes the are supposed to have an address on the blockchain and a wallet to use the smart contract. It takes some fees to interact with the contract. The user pays for it.

  • Thanks Kashish , so the mining concept is the same as what we see in bitcoin - that is nonce to be derived & hash computation etc etc ., ? For the first Q - you answered it is executed only once & for the second - you are saying every miner is trying to put the code in to block chain - so please help to eloborate 1 & 2 . Many thanks in advance – Harish Narayanan Jan 3 '18 at 13:01
  • The code is a part of the transaction, which is sent along with it. Like additional data. The transaction is added to a block, then the block is added to the blockchain.(mining). Then the code is executed. Your question is how many times does the same code runs, then that depends totally on your code and who is using the smart contract. But it is definitely executed once after the transaction is successfully added in the blockchain. – Kashish Khullar Jan 3 '18 at 13:26
  • Each node executes every transaction. POW is done after a selection of the transactions, probably the ones with the highest gas prices that will fit within the gas limit for the next block, are processed. If the POW game is won by a node, it broadcasts a block, which includes transaction ID's, and other nodes run those transactions on the previous state to ensure they get the same output as the winner of the POW. It is necessary for each node to execute every transaction so they can verify/ensure the other nodes aren't making fraudulent transactions or changing the state in their favour. – willjgriff Jan 17 '18 at 0:29

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.