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
.
- If we call the retrieve then we simply read the data from the block with address
address_1
. (Totally understandable) - 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. - 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 theaddress_1
).
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