3

This is a noob question - apologies.

Suppose I have a smart contract that allows people to register something with an ID. For example, my public address is o4f... and I want to register the ID 012345 to my public address.

Later on I make a transaction where someone buys that ID from me, so now the ID 012345 belongs to a different public address, say 05f....

My question is: can I treat Ethereum like a database and ask the blockchain to give me all transactions that involved the ID 012345? What would that look like?

1

The normal way to do this would be to log an event for each transaction, with the key terms that you want to query indexed. You can then later query the blockchain for those terms. Look up the terms event, indexed, filter and watch for more information on this.

However, if you have large numbers of transactions this may still be slower and harder to query than you'd like; Depending how your users will be accessing the data you may prefer to keep a cache of the data in a regular database, and make a script to load the database from the Ethereum event logs.

| improve this answer | |
  • Wouldn't caching the data in a regular database defeat the purpose of decentralization, if you'll need to double check the data in the regular database for each query? – David Feb 23 '17 at 14:06
  • 1
    That depends how it's used and who owns the database. For example, if all you're doing is showing history on a website for informative purposes, it might not matter if your users have to trust you. Users may also have their own databases, filled once from the blockchain the first time they use it then topped up with subsequent transaction histories. – Edmund Edgar Feb 23 '17 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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