7

A call to a Michelson contract results in a storage update and the emission of operations. Is there a simple/standard way for the called contract to return a value to the caller?

4

No. The only way to do that is for the contract you call to explicitely send you a callback, continuation passing style.

| improve this answer | |
  • 2
    How would a contract send a callback? Can you please provide an example? (assuming it's possible currently in Michelson) – Matej maht0rz Šima Feb 6 '19 at 22:33
2

In my understanding, you can call a contract by sending a parametrised transaction, that's injected as an operation under /injection/operation.

You can trace the flow above in the source of eztz.js.

/injection/operation doesn't return much more, but a hash of the operation you've just injected. (there is a mention of a $unistring although i'm not sure what it represents right now)

My guess is also that smart contract gets executed, around the time when an operation is injected into a new block. (Don't take me for granted here, i was unable to find resources on this for Tezos, but that's how it works with ethereum)

So you can always get the contract's storage using .../contract/<contract_id>/storage - this'd represent one part of your contract's return value. But only after your operation has been processed.

And i think there should be a way to extract the operations executed by your smart contract, if you look deep enough into the RPC responses, i'd look for operations coming from your contract's address.

In fact, you can see an example smart contract on TzScan, all it seems to do is set the current storage to a value received as a parameter. You can drill down trough the transactions and operations to see how it was updated over time - this should give you an idea of where to find the required information via RPC.

| improve this answer | |

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.