How can I store data in ethereum blockchain

  • I want to store pdf hash in blockchain I already read this post What are some proposed ways of storing data in Ethereum? But I'm beginner in this domain and I don't understand... Is it possible to store data (hash in my case) in Ethereum?

    How many cost to store data in Ethereum? And how can I do this with python or an other language?

  • manidos

    manidos Correct answer

    5 years ago

    You can store data in the blockchain:

    1. In a special place on the blockchain reserved for contract data
    2. In a special place on the blockchain reserved for transaction input data

    To store your data in a special place 1 you'll need to create a contract and deploy it on the blockchain.

    To store your data in a special place 2 you'll need to send someone a transaction and include your data in it.

    Before you you can interact with the blockchain you will need to get access to the web3 object. There are multiple ways of doing so. I'd suggest you installing MetaMask plugin for Chrome browser. After you install it, you will have access to web3 object. The ways of interacting with web3 object can be found here (web3 api documentation)

    Now that you've installed MetaMask plugin. Choose Morden testnet in the configs. Now you can use solidity browser compiler. Try to compile and deploy a simple contract there:

    contract A {
        uint x = 255;
    }
    

    You will need some ether in your account(MetaMask provided account) to deploy contracts. Go to https://morden.ether.camp/ and get 5 testnet ether for free.

    And after I install web3, could I store data in a special place 1?

    @wxcvbn, I updated my response, check it out, feel free to ask

    Thank a lot for your answer! Can I insert several hash in one contract? Or is it possible to open an existing contract and add a hash? I need some ether for each contract created or for each data insert in contract?

    @wxcvbn,You can insert as many hashes into a contract storage as you want. The more data your contract is supposed to hold, the more you will pay for its creation. If you want to open a contract and invoke a function in it you may pay or may not pay ether. If this function modifies anything on the blockchain, for example, stores some value provided by you, then you pay ether. So, yeah, you pay for each data insert. To open an existing contract you will need to know its address and **abi**(it's like a description of the code inside a contract).

    So juste I need to create MetaMask account and add ether? I'm a little lost, what do I do first? download Ethereum? Or MetaMask?

    @wxcvbn, the beauty of MetaMask chrome browser plugin is that you don't need to download the whole Ethereum blockchain in order to interact with the network. Oh, silly me, I should have given you another point to start from. Do you have Mist wallet installed? If you do, you can compile/deploy contracts and send transactions from there, but you will need to download the whole blockchain, it may take a while.

    do you know an other way to do this with python or php (or an other language ...) ?

    @wxcvbn, I don't know, sorry.

    Don't worry, it's okay =)

    web3 library available in several languages, for Python use this: https://github.com/ethereum/web3.py

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM