0

How do i do something like

cargo contract call --contract --message get --suri //Alice

in subxt or from a rust backend the docs in subxt focus mostly on signing and submitting txs and events hence wasnt able to really find out how to call read only ink functions

1 Answer 1

0

Calling a read or write function should be the same in an ink! contract. Both are a contract message.

EDIT:

So when calling a contract the bare_call function returns the ContractExecReturn type. This is defined by the generic ContractResult type where we are interested in the result field, which is set to ExecReturnValue. Then we need to decode the data field's bytes into the return value returned by the message. You can look at these integration tests for how you can do it (it is calling the following contract message)

Note that we had to decode the bytes [1..] for some reason to get the correct value. I can't explain you how yet unfortunately (see open question)

2
  • hi - is there any example of calling a smart contract function using subxt etc - do i need to query the node storage?? the other extrinsic apis are only submitting a tx related thanks for the reply and would really appreciate a follow up on the same...
    – roguewane
    Commented Nov 14 at 21:28
  • Edited my answer, hope it helps Commented Nov 19 at 17:23

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.