0

Sorry if I didn't fully clarify the question; it was quite challenging for me to do so.
This is a smart contract

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract GameItem {
    uint256 number = 10;

    function store(uint256 _number) public {
        number = _number;
    }

    function retrieve() public view returns (uint256 magic_number) {
        return number;
    }
}

And when we deploy this to blockchain we get a contract address address_1.

  1. If we call the retrieve then we simply read the data from the block with address address_1. (Totally understandable)
  2. we call the store function and store 20, This will create a new block that is been added to blockchain somewhere after the previous block.
  3. if we try to call the retrieve again then how we are able to get the latest value 20 comes as result even after we don't have the address of new block (we only have the address_1).

enter image description here You can see here every time we try to store, we have the same from and to addresses.

From is my wallet address
to is the contract address

I tried, but I couldn't figure out how the data was correctly fetched even though we don't have the block address.

It would be fantastic if someone could clarify my issue and explain how it functions. Thanks

1 Answer 1

0

@praval, first you need to understand that block don't have any address. accounts and smart contracts have address a unique identifier. and we've transaction hash to read transaction details unique identifier of tansaction. To read detail transaction hash and address wise, visit this https://goerli.etherscan.io/txs

1
  • So the data is read as follows: First, we obtain the transaction hashes using the contract address, after which we select the most recent one from which we can obtain the block hash, block number, and other details. I guess, these all details are sufficient to read a particular transaction from the blockchain.
    – Praval791
    Nov 8, 2022 at 3:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.