I have a scenario where I want to execute a scheduled call via the scheduler pallet at block number n. This call will change certain storage items of pallet.

So before this storage changes, I want to use offchain_worker() to dump storage to some HTTP server.

Now I feel that scheduled call will be executed before offchain_worker() gets triggered for block number n. Is this true? If yes, then what can be done to achieve my goal?

2 Answers 2


OCW's run asynchronously at the end of every block import.

You could use a combination of off-chain storage and off-chain indexing.

Off-chain Storage to orchestrate when to run the OCW (it does not need to run at the end of every block import).

And you could have your pallet write its storage to the off-chain indexing storage before it changes its storage so it is accessible by the OCW when it runs later.

Note that even with the above solution, the OCW will still run at the end of block import.

Take a look at these two guides. The code is a bit legacy but still relevant:



Except your question about ocw, for your target "So before this storage changes I want to use offchain_worker() to dump storage to some http server", I think it's not a great scenario to use OCW/OCS.

What you really want is ability to indexing you on-chain data (cover before or after change), it's good to use indexing service like subquery.

As CQRS pattern goes, block-chain act as the Command part, if you want to build the query part, indexing service/infrastructure is there to serve.

In detail, for your requirement, you can listen to every block's modification on your specific storage item, and then write those value into db(like postgres).

  • 1
    I agree. This post has some good points on using substrate-archive. I think it could be a better solution for you.
    – Bruno
    Commented Apr 25, 2022 at 14:23
  • Yes, sure, give indexers a try. Commented Apr 26, 2022 at 2:12

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.