I have a smart contract deployed that I use to store generic data. This generic data belongs to external parties and now they want to query the data which is easy given an ID for the array index and the right permissions. Amongst this, they now want to see all related transactions of said item in the array on the smart contract. I feel the structure of this simple implementation prevents me from doing what I require.

I require a way to search the blockchain for all transactions associated or related to a user id, a transaction id etc..

Questions, To be able to provide a deep level of information based on data stored in a smart contract do I need to create multiple separate smart contracts? Or Store data in a traditional database and reference a transaction?

Basically, I want a way to say a change was made in this transaction and the data was inputted on this date and then I can display this on a UI to the customer.

1 Answer 1


For the situation you are describing, I believe your best option is to create events for each type of CRUD operation allowable for your data, and emit them within every transaction.

When creating the events on the contract, be sure to add indexed to the event parameters you wish to track/filter (e.g. userId, etc...). This will allow for easy recovery of all transactions which emit a certain event, and are associated with a certain userId.

For example:

event PhoneNumberUpdated(bytes20 indexed userId, uint newPhoneNumber)

function updatePhone(bytes20 id, uint newNumber) returns (bool) {

   //update phone number in storage ...

   emit PhoneNumberUpdated(id, newNumber);
   return true;

Then, assuming you are using web3 1.0, you would retrieve the previous event/transaction data by filtering for the indexed param of your choice (userId, in my example):

myContract.getPastEvents('PhoneNumberUpdated', {
    filter: {userId: userIdFromFrontEnd},
    fromBlock: 0,
    toBlock: 'latest'
}, function(error, events){ console.log(events); })
    console.log(events) // same results as the optional callback above
  • events are new to me so I'm going to go away and research this now and if this proves to be my solution I will accept your answer - thank you Commented Jun 5, 2018 at 16:10

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.