1

I am a startup in this domain. I see some article about Ethereum could save data as a contract. But they are too complex to me. If I already have an Ethereum account with some ETH. Is there some python code could just simply write some data to ethereum & read it back when needed with this account? This data (or contract) no need to interactive with other account or contract on Ethereum, for example like greeting function, just only record data. Thanks a lot for any reply

1

If you are using Python language, you can 1) connect to Ethereum node from your Python code 2) Read and write (send transactions) to contracts using Web3.py library.

| improve this answer | |
0

You can do several things. But before describing the possible solution, take into consideration that saving data in ethereum is expensive.

With that said:

  1. You can write a contract that receives data and saves it, using keys (IDs) to differentiate between different pieces of data set. For instance:

    contract storeData {    
        mapping(uint256 => bytes) public data;
    
        function saveData(bytes memory newData, uint256 dataID) public {
            data[dataID] = newData;
        }
    
    
        function readData(uint256 dataID) public view returns(bytes memory) {
            return data[dataID];
        }
    
    }
    
  2. Another solution is just to send normal transactions and put your data in the field data/input. You then save the hash of the transaction (txHash) locally and whenever you want the data you use web3.gettransaction(txHash) (you can use web3py for this) to recover the transaction and the data that was sent with it.

Hope this helps

| improve this answer | |

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