2

I've just started learning about Smart Contracts and Ethereum, and I've come accross the classical example of FoundRaising. ( e.g. https://developer.ibm.com/clouddataservices/2016/05/19/block-chain-technology-smart-contracts-and-ethereum/)

Since the good practice of a Smart Contract implies that the outcome of the contract needs to be the same accross all the nodes, I have an issue understanding the drawdown() functionality of the smart contract presented at the provided URL.

Concretely, when calling :

benefactor.send(this.balance);

  1. How does the actual sending process occur? Is the balance of the benefactor changed locally in each node that executes the smart contract? And if so...

  2. How is the consensus achieved?

1

All nodes have a copy of the same append-only ledger (called the blockchain) which stores the state at the time the block is mined. Miners and mining are explained super well in the Ethereum whitepaper.

The balance is changed locally in each node, yes, but nodes don't reach consensus on each individual contract execution/state change in real time as they occur, it is simply the miner who successfully mines the block that gets to choose which state changes and function calls are included. This question discusses further when each node actually executes each transaction's/contract call's code.

This newly mined block is appended to the blockchain, and the blockchain with the most work behind it is accepted as the 'correct' chain, so all nodes agree that all states in that block are the correct states for now.

As an example, imagine you called benefactor.send(this.balance); with the balance value 294820984, and I called it with the balance value 7429847298. If we sent these contract calls to the network at the same time, some miners might include your call, and update their state log accordingly, but some might include mine. They would only reach consensus on the one that gets mined into a block, however. This answer explores in more detail what nodes are agreeing on when consensus is reached.

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.