4

I have a asynchronous task running in service.spawn_essential_task(task).

Which does some stuff and wants to write data in storage. How can i achieve this?

Changing state by making runtime_apis to pallet functions which are not extrinsics and changing state through them does not really change state and this seems to have a local state which changes data there and not in on-chain.

And can we call these task as off chain worker or are these just seperate tasks?

1 Answer 1

1

To do any kind of state change on chain, you will need to send an extrinsic. You can write to the storage in a runtime api, but the changes are thrown away. The runtime is a state transition function and every node needs to do the same transition to come to the same result. However, this would not work if the nodes would use the runtime api to do some changes to the state.

And can we call these task as off chain worker or are these just seperate tasks?

You could introduce some custom host functions that would allow you to access your custom task.

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.