dfinity / sdk

IC SDK: a Software Development Kit for creating and managing canister smart contracts on the ICP blockchain.
https://internetcomputer.org/developers
Apache License 2.0
174 stars 83 forks source link

Feature: Download canister .did and .most #3709

Open vporton opened 6 months ago

vporton commented 6 months ago

Please add a command to download canister's .did and .most.

Currently I do my code hacky:

%.install: %.wasm FORCE
    dfx canister create $(*F)
    dfx canister install --network=$(NETWORK) -m install --wasm=$< $(*F)

%.upgrade: %.wasm %.most FORCE
    mkdir -p $(DFXDIR)/.dfx/local/canisters/$(*F)
    cp -f $*.most $(DFXDIR)/.dfx/local/canisters/$(*F)/ # hack!
    cp -f $*.did $(DFXDIR)/.dfx/local/canisters/$(*F)/constructor.did # hack!
    dfx canister install --network=$(NETWORK) -m upgrade --wasm=$< $(*F)

I want to use moc --stable-compatible explicitly to avoid hacks, what is possible only when I get direct access to such canister data.

chenyan-dfinity commented 6 months ago

To get it from deployed canisters: dfx canister metadata <canister_id> motoko:stable-types. To get it from wasm: ic-wasm <my.wasm> metadata motoko:stable-types.

If you want to make it everything explicit and scriptable, I encourage you to try ic-repl.

vporton commented 6 months ago

OK, dfx canister metadata <canister_id> motoko:stable-types gives .did. But how to get .most? (And I don't really understand what is the distinction between .did and .most.)

Also, the following demonstrates that stresser does have main shared method, but it is missing in the actor:

$ dfx canister metadata stresser motoko:stable-types && dfx canister call stresser main '()'
// Version: 1.0.0
actor {

};
Error: Failed update call.
Caused by: Failed update call.
  The replica returned a replica error: reject code CanisterReject, reject message IC0501: Canister bkyz2-fmaaa-aaaaa-qaaaq-cai is out of cycles, error code None
$ dfx --version
dfx 0.18.0
chenyan-dfinity commented 6 months ago

motoko:stable-types gives you .most. candid:service gives you .did

lwshang commented 5 months ago

This doesn't seem to be an issue with Rust CDK but rather with general development using dfx.