Hey,
in my use case I try to get some candid information from a remote canister and later I’m going to call a function from the remote canister.
To do so I use the following solution I have found:
# fetch the candid
const candid_source = await fetchCandid(canisterId, agent);
to fetch the candid as text from the remote canister, then I convert this text to javascript with the following function:
async candidToJS (candid_source: string){
// call didjs canister
const didjs_interface: IDL.InterfaceFactory = ({ IDL }) =>
IDL.Service({
did_to_js: IDL.Func([IDL.Text], [IDL.Opt(IDL.Text)], ["query"]),
});
const candidCanister = 'a4gq6-oaaaa-aaaab-qaa4q-cai';
const agent2 = HttpAgent.createSync({ host:"https://icp-api.io" });
const didjs = Actor.createActor(didjs_interface, {
agent: agent2,
canisterId: candidCanister,
});
const js: any = await didjs['did_to_js'](candid_source);
if (Array.isArray(js) && js.length === 0) {
return undefined;
}
return js[0];
};
At the end this is working.
My question is, is there another way to convert the Candid text to JavaScript besides using this remote solution? Or, what is the recommended way to do that?