New to blockchain and smart contracts. Been doing research and I realize I can't update my transaction smart contract. Is it possible to store database data as an entry to the ledger or in another smart contract that only I update that the transaction smart contract can access to pull the data?

For example

User wants to make a donation payment to an organization. His wallet needs to pull in all possible organizations for him to choose from a database which I would like to be decentralized.

Where can I store the organizations and their wallet address as well as update them or remove them? Also I want to add subsections of an organization and its address.

For example

User wallet pulls in:

  • Hospital, address
  • Hospital, lab, address,
  • Hospital, ER, address
  • Fire department, address
  • Fire department, equipment fund, address
  • Fire department, supplies fund, address
  • Etc.

I would read the only one adding organizations and removing them . Is there a way to do this all decentralized inside the blockchain?


1 Answer 1


Smart contracts can have Arrays and Maps as data structures that store state permanently on the blockchain, and functions of the smart contract can modify them.

For your example, you could use something like this:

pragma solidity ^0.4.16;

contract MyOrgDatabase {
  struct Organization {
    address _where;
    string _name;
  Organization[] public availableOrgs;
  address public owner = msg.sender;

  function addOrg(address _where, string _name) {
    require(msg.sender == owner);
    availableOrgs.push(Organization(_where, _name));

That contract has a public availableOrgs property that anyone can read from the blockchain. But only the address that created the contract (the owner) can add organizations to that list (you'd probably also want to add functions for removing organizations from the list, or changing the ownership of the contract for a fully-featured contract, but that should give you the idea).

  • You are using the address in the struct organization in wrong way. It suppose to be a string on _where Oct 30, 2017 at 9:04
  • 2
    @EduardoPereira: If the intent was to store a street address (mailing address), then a string would be appropriate. But the intent of this one is to store their Ethereum address (as the original question cites the use case of sending funds to them). The address type field is a type specifically sized for holding Ethereum addresses (typically long hex-encoded numbers). Oct 31, 2017 at 11:38
  • @MidnightLightning I think this wont be a persistent storing solution. Like for example sake if we are closing our connection with the ethereum or closing the ganache-cli , the next we will open it we wont get the data. Right?..please correct me if I am wrong Nov 30, 2018 at 20:26
  • @AnikethSaha I believe you're incorrect; the way I've laid out the contract here (having a "public" list of "Organization" structs) is a standard way to permanently store data on the Ethereum blockchain. Ethereum exists as a network of computers running the Ethereum client application ("nodes") that all execute all transactions. Therefore, the moment I submit a transaction to trigger the "addOrg" function, all the nodes record that as a change. If I disconnect from one of the nodes, that doesn't delete the data; it's still there on all the nodes that saw the transaction. Dec 3, 2018 at 4:17
  • @AnikethSaha Ganache is a separate situation; Ganache is a testing space for developers to work on their applications without risking real money on the real Ethereum blockchain. Your Ganache network only has one computer in it (yours), so if your computer loses its data, it would really be gone. But just stopping and starting Ganache doesn't delete everything on it (that's just like stopping and restarting a database server). However there are specific commands to tell Ganache to throw out all the blockchain data and start again, which then your past actions would be lost. Dec 3, 2018 at 4:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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