How to use the `didc` generated Rust bindings when using the ic_agent Rust crate?

I am using the didc tool to generate the consumer intended Rust types using this command ./didc bind --target rs <canister_to_call_candid_file>.

For example:

The input candid file looks like this:

And this is what the generated output bindings look like:

The issue here is with the Service struct.

It has generated calls that use ic_cdk to make the calls internally.

  • Are we supposed to be using ic_cdk to be making calls into the IC from an off chain hosted app? I assumed ic_cdk only ran inside canisters
  • If not, then how are we supposed to be using these methods from the ic_agent that’s being used in the application?
  • The agent has query and update methods that look like this:
    Agent in ic_agent - Rust
    which accept canister IDs which I assume is what specifies which canister to call into in the network? So, then the above interface generated by didc for calling the methods are meaningless?
  • On a slightly orthogonal note, if the query/update method has the canister ID specified in the method parameters, what is the with_effective_canister_ID method required for?

@lwshang @chenyan Thoughts?

With latest didc, you can generate agent bindings using:

didc bind --tartget rs-agent <CANDID_FILE>
1 Like

Got it, that worked. Thank you.

Silly me, should have noticed the other parameter :see_no_evil: