I'm doing a project and I want to store some basic information on Etherum, for example: Name, ID, Height, Weight. How can I store this on the blockchain and after that be availble to read it. I read this How can I store data in ethereum blockchain and it says that I would need to create a contract and deploy it on the blockchain.

How can I do this? I only find tutorials of programming smart contracts for sending/recieving coins.

  • why do you want to store data on blockchain? Oct 5 '18 at 9:24

Well, while the user Dan Garland above makes some interesting points which you should consider, a smart contract to do what you intend on doing is not very complex. Registering the data is not too expensive, and assuming you indeed want to make use of the immutability of a blockchain, there is a use-case there. I can see this in a medical records type scenario.

Here's a simple example on how you could do this:

pragma solidity^0.4.25;

contract PatientRecords {

struct Patient {
    string name;
    string ID;
    uint weight;
    uint height;

address doctor;

constructor() public {
    doctor = msg.sender;

modifier onlydoctor() {
    if (msg.sender == doctor) {

Patient[] public patients;

function registerPatient(
    string _name, 
    string _ID, 
    uint _weight, 
    uint _height) public onlydoctor {
        patients.push(Patient(_name, _ID, _weight, _height));

So the above contract will let you store the info you need and a query for that info will not cost you anything. While I did add a "onlydoctor" modifier, that's the only extra functionality there. For a proper implementation, you would have to consider things like storing certain data (e.g. ID or Name) as a hash for privacy reasons.

Test it out on Remix to see what it does. Hope this helps.

  • Thanks! I understand what Dan says, but the ID, Weight, Height it's more some example data, I'm going to use other kind of data, I just needed an example like yours to understand how to do store the data.
    – sergio8215
    Oct 10 '18 at 7:21
  • Medical records on Ethereum is a bad idea. Even private accessors are visible to anyone on the network, and as they will become part of the chain forever, it's difficult to guarantee privacy even with encyption. Oct 11 '18 at 8:51

It's not a good idea to store data such as name, height, weight on a blockchain. One of the reasons why you find a lot of tutorials that are coin-related is because transaction data is a good use case for blockchain technology. However, a blockchain is not a database.

The reason why name, height and weight aren't a good choice is that is it computationally expensive to ask every node on the Ethereum network to duplicate that data, so Ethereum transactions charge a 'gas' cost, which would mean you'd be paying in crypto to store your database edits.

Also, blockchains store the history of changes made to data, so you'd end up storing not just the height and weight now, but any subsequent edits also. In the case of weight, that might change a lot, meaning more transaction and storage costs.

Finally, it's probably not necessary that no-one tampers with this dataset. Is it valuable enough data to decentralise trust around it's access? I doubt that you'll run into censorship issues for instance which blockchain prevents.

So while it might be a useful tool for learning, some more context around how blockchains work would give you an insight into what use cases are suitable before you decide that Ethereum is the right blockchain for your requirements.

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