TransWikia.com

How do we get latest value of a key from blockchain?

Ethereum Asked by Madan on December 17, 2020

I want to understand the basic working of storing a value of a key that can periodically update its value in blockchain. For example, if the value of ‘a’ is 4 today and is stored in blockchain, then tomorrow i may update it to someother value and it may be recorded in some other block. Now, if i want to get the latest value of the key, how does it work?

3 Answers

Ethereum uses merkle tree to store data of multiple blocks. This property is used for re-organizing block

However, the number of block stored depends on sync mode. Archive nodes store the state of all historical blocks while full nodes stores only state of 128 blocks.

Answered by nguyen Quang on December 17, 2020

In addition to the existing answer, mappings are persistent, so when you're mapping a value to a key it works in the same way as when you're updating the content of state variables, state modifying functions effect storage in the same way for the two scenarios.

Answered by 6egic on December 17, 2020

You mean

contract Keys{
    mapping (string => uint256) dict;


    function get(string key) public view  returns(uint256){
        return dict[key];
    }

    function set(string key, uint256 val) public{
        dict[key] = val;
    }
}

You can get the current value of any key anytime with get("a") and set new values with a new transaction on set("a",newvalue);

Answered by Davide C on December 17, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP