Generating did files in rust project , able to import types but not the method mentioned inside service section

i generate the did files in frontend like:

did file :upload-images-to-icp-asset/did/asset_proxy.did at main · Veercodeprog/upload-images-to-icp-asset · GitHub

i am able to import the type like StoreArg from the did file:
use crate::canister::asset_proxy::StoreArg;

but not able to import the method like store from the did file using:
use crate::canister::asset_proxy::store;

I don’t know enough about these functions to make any solid suggestions. But in general we now suggest using ic-cdk-bindgen like this to generate canister bindings. Not sure it’s worth migrating for you, but maybe you want to have a look into that crate’s source

1 Like

In this use case, you cannot use ic-cdk because the code needs to be generated for the frontend, not within a canister.
Therefore, you need a structure similar to the Actor in JavaScript, which contains an ic-agent::Agent instance and methods for interacting with canisters.

To achieve this, you can follow the source code of the code_generator in ic-cdk-bindgen and the @dfinity/agent library in JavaScript. However, considering the complexity, it would be better to separate this functionality into a dedicated library in the future, perhaps with a name like ic-agent-bindgen.

Alternatively, you can simply specify the method name as an argument when making calls with the Agent.

i am doing a similar thing in a different project and it works fine .

i have updated my project too where i am using Agent using ic_auth_client( a crate provided by @wiyota ) which works fine in the other project:

i have also checked the build files inside target/…/out/…
and the builds for candid files are generated correctly in my new project where i am struggling to import the methods from did file

@wiyota @Severin could you check please whats wrong in my project as it works in the other project .

@Severin @wiyota i fixed it
i have to add mod canister in the main.rs in addition to lib.rs.
Thanks for discussing it , :star2:

2 Likes