4

Is it possible to create a transaction that calls an offchain worker to write data to the offchain worker?

2 Answers 2

5

If you take a look at this diagram:

The dotted red lines indicate that the Off-Chain Worker (OCW), although existing in the Substrate Node in tandem with the Substrate Runtime, actually lives in its own separate WASM execution environment - denoted by the dotted red line. One of the main reasons the OCW lives in the Node with the Substrate Runtime is so that it can have access to on-chain state and also so that, if opted-in, the runtime can have access to Off-Chain Storage via Off-Chain Indexing.

An OCW can be thought of as a second application that runs alongside the blockchain. That being said, your OCW can listen to events from the runtime and react in some manner to those events. Your Substrate Runtime should not have any idea that your OCW exists nor should it assume so.

More info: https://docs.substrate.io/reference/how-to-guides/offchain-workers

Also read:

This video has legacy code but is helpful in how one should think of OCWs.

1

OCW cannot be triggered manually, but you can write Storage and Off-Chain Sotrage (via Off-Chain Indexing) in transactions, then read Storages in Hooks::offchain_worker.

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.