I have read all the other similar questions but it cant seem to get a firm grasp of the concept. There are steps in the process i understand due to the help of other posts and some i totally miss.

I will state my understanding below with an example and feel free to correct me and provide answers to the parts that are blurry for me.

Per my understanding:

  1. When creating a Smart Contract in Ethereum the Bytecode of a smart contract is published in a transaction (that is mined in a block) and i pay a gas fee for it (so far so good), and then stored in a storage of the network (what that storage is? where it is located? is it the local machine of each Node?) associated with an address.

Lets say i have implemented this simple smart contract below (i found it on stackoverflow) where i create a fundraiser and i want to raise a specific amount of money and then withdraw them if the limit is reached:

  pragma solidity ^0.8;

contract MyContract {
    uint256 constant FUNDING_GOAL = 1 ether;
    address constant TEAM_ADDRESS = address(0x123);

     * Throws if the current balance is lower than the goal
     * Otherwise sends all of the current balance to the predefined address
    function withdraw() external {
        require(address(this).balance >= FUNDING_GOAL, 'Haven\'t reached the funding goal');
     * Allows this contract to receive native currency of the network (usually ETH or BNB)
    receive() external payable {}

Now i have created this contract, its validated through the process i stated in step 1.. So far so good.

  1. Now i guess everyone in the blockchain can see the TEAM_ADDRESS and can send me their money accordingly by signing the contract on their side and depositing a specific amount on it? When that happens this signing process hes doing is included again in a block as a new transaction referencing my smart contract's address and the inner variables of the smart contract are getting updated?

  2. So the state of the contract is ensured by having the smart contract 'saved' in a storage space where all the nodes has access and then accessing each time this storage to validate any new transactions that come out of it?

I tried very hard to articulate my thought process as clear as possible in this new concept for me. I hope what i write makes sense to you and the community can guide me to find the right answer.

Thanks in advance.

1 Answer 1

  1. So yes, storage exists in the local memory of all nodes, and also anyone who was the chain data. Whenever a new block is produced all nodes add the update their storage information to match the changes from all transactions in that block.

  2. Yes, a new transaction to the contract will be included in a block and update storage accordingly, be that info on token transfers, eth transfers, or internal contract variables. All are considered part of the "state".

  3. Any node that tries to produce a block where storage is updated in a way that does not follow the rules of the protocol will not have their block accepted by the other nodes, who verify all updates to that state when a block is produced to decide if they accept it as valid. Blocks that the majority of the nodes accept will in effect be added to the blockchain, and storage updated accordingly. This stops any node from just modifying the storage in their node to mess with the internal variables of your contract. In essence, it is decentralized verification, where 51% of the nodes would need to collude in order to change the state malicously, and even then it would be considered non compliant the the protocol, and users may consider that fork completely invalid.

  • Thanks a lot for the clear and consise answer Bruce!
    – CC_Zio
    Commented Oct 1, 2022 at 21:46

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.