6

I have a program (using Anchor), and a I wish to return a value from an RPC call. I understand that this was not possible a few months ago but now is, though I'm having trouble finding any docs/examples.

Edit: example here: https://github.com/coral-xyz/anchor/blob/master/tests/cpi-returns/tests/cpi-return.ts#L45-L68

1 Answer 1

4

implementing this in anchor is trivial(you dont need to use set_return_data or get_return_data sys calls) , instead of returning result<()>, replace the unit "()" with the type of value you wish to return, this value can be accessed by programs cpi'ing or from the client side, check out this cpi return repo on anchor tests to get a better understanding, anchor also exposes a view function view the return value , Reference : https://github.com/coral-xyz/anchor/tree/master/tests/cpi-returns

2

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.