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 Answer 1

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.

2
  • 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? Commented Feb 23, 2017 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. Commented Feb 23, 2017 at 14:16

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.