3

Looking at the docs, it seems I can only return custom weights in dispatchables

I want to be able to create data in storage then return the ID, because we will be calling the chain from a UI/Dapp

I am assuming this wont be possible because just because an extrinsic was called successfully doesn't mean the data is stored on-chain, we have to wait for consensus to be reached

So is there a way to return the value stored on-chain on the call itself? or is the best way to have a separate process check the chain state for the stored value?

2 Answers 2

1

I am assuming this wont be possible because just because an extrinsic was called successfully doesn't mean the data is stored on-chain, we have to wait for consensus to be reached

The question would be here, return a result to where? What would be the purpose of returning a value that would not be consumed by anyone?

It is also questionable what kind of data you want to return there, because you hopefully not do any kind of "calculations" in your runtime. However, you can use events to notify the outside of something has happened on your chain.

In your case, if you send a particular extrinsic, I don't see any purpose to send any event at all. If you send an extrinsic and you see that it was successfully included in a block, it means that you can check the state for the value you are interested. There is no real need to use an event for your use case IMO.

2
  • To clarify, what we want to return is an ID/Key. This key is required to be the joining key between onchain/offchain storage with the chain being the source of truth We wanted to build a UI to create data on-chain then also store a link to that data offchain. Was wondering if there was a simpler/cleaner way to find out when something was stored rather than just wait for block finalisation Seems to me the best approach is to call the extrinsic and have a separate process check for the inclusion of said extrinsic Is that what you are proposing?
    – Sam Elamin
    Feb 26 at 19:34
  • This is exactly what events are good for; broadcasting a state change to the outside world. In the case that you only wait for storage change, you can subscribe to storage events itself. They are emitted when a storage item changes. Feb 28 at 10:36
8

Your best bet here are to use Events.
Events can wrap data and it is possible to query historical Events from a node.
This is useful in case you want to query all successful Events from the past.

Have a look at the template pallet and how it emits an Event with an ID attached.

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.