Hey I have following event

event Submitted(bytes32 indexed docHash);

The event is called by a function

function submitHash(bytes32 docHash) public onlyOwner() {

It looks like docHash gets saved in the blockchain even though only the event is called. I have another code as

bytes32 docHash;
function submitHash(bytes32  docHash) public onlyOwner() {
        docHash = docHash;

What I want is to store docHash in the blockchain so that there is a proof that docHash with the timestamp is present. Will storing with event cost more? And is it possible to search for docHash as it has indexed in it? Which would be better option?


If an event is indexed it means it can be (easily) searched for: What does the indexed keyword do? . All events are stored in the transaction (and therefore, in the blockchain) regardless if it's indexed or not.

Emitting events is the about the cheapest way to store data in the blockchain. Here are some fast-googled calculations: https://www.reddit.com/r/ethdev/comments/78ugki/do_indexed_parameters_in_events_cost_more_gas/

The only downside to events is that their data is not accessible to any contracts (not even to the contract emitting them). So once an event is emitted there is no way to retrieve that information inside the blockchain - it's only available outside the blockchain to node clients. Events do not store any information in the blockchain/contract state.

  • does this mean that bytes32 docHash wont be able to be accessed by other contracts even if its stored in the blockchain? Is events not accessible to other smart contracts because its not actually storing any variables? Or other reasons.. – Subik Jun 24 '20 at 8:14
  • 1
    edited my answer to make it more clear. Of course if you first store the same event date in a contract variable (state) then you can use that. But the emitted event data is not avaialble in contracts. – Lauri Peltonen Jun 24 '20 at 8:17
  • Ohh okay so the actual event cant be accessed through smart contract but docHash can be accessed? – Subik Jun 24 '20 at 8:26
  • Yes, docHash is a regular state variable so it can be accessed (although your code never stores to it due to a typo). – Lauri Peltonen Jun 24 '20 at 8:32
  • Thanks for the info. I changed it – Subik Jun 24 '20 at 8:39

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.