It generates .did. files for example_backend and example_frontend, but does not generate .did. files for these canisters that are created by example_backend from actor classes. How to generate these .did. files?
I would guess you have to make the Motoko compiler do it for you. If you put the canister that your backend is deploying in a dfx project and dfx build it, then youâll end up with the .did files. If you donât want to go that route I guess you have to build the moc invocation yourself. You can find moc in the folder that dfx cache show points to, and IIRC if you build with verbose mode (-vv) youâll get the moc invocations printed
Hereâs an example of a remote canister. The intention behind the feature is that you can say that on certain networks you donât want to deploy that canister. In this example, you only want to install the ledger if youâre running locally since there is no pre-installed ledger. On mainnet, you of course want to use the real ledger, so you donât deploy your own
You recommend to use a remote canister for .did. generation. But an example of remote canister, that you pointed, refers to an already generated .did. file rather than generates it:
Are you sure dfx does not build the .did files? For me dfx builds the .did file also for an actor class.
Not sure which commands you have tried. Maybe dfx generate? That command creates the .did file for me. With your dfx.json it would be in src/declarations/backend_example/backend_example.did. The only difference with an actor class is that there are service arguments, i.e. in the line service : (...) -> the part (...) is non-empty. I would be interested in why it doesnât do that for you.
Anyway, if dfx generate doesnât work then another way is to use dfx build. That command does not deploy the canister. But it does create a canister id (an empty canister), i.e. it still needs a replica (dfx start) running in the background. So what you are looking for is dfx build --check. With the --check option it does not even create a canister id, hence you donât need a replica running in the background. It builds .did and .wasm in .dfx/local/canisters/example_backend/. You can run dfx build --check example_backend to only build that one canister and not all that are defined in dfx.json.
I have a few actor classes that are created on demand from a canister. So they are not in my dfx config due to them being actor classes, so there could be 0 or a 1000. From what i can tell the dfx.json just takes canisters, not dynamically created actor classes.
My biggest struggle is I cant automatically create JS/TS for the services because no .did file is created, because there is no âcanisterâ that dfx deploys. Is there a way to add it to the dfx.json so it will generate .did/JS/TS?