The semicolon was added automatically by the “Motoko Language Support” VSCode extension (v0.13.2). If that’s not valid .did syntax, the extension should probably be updated not to add it on save (if we’re supposed to be editing .did files manually as the Fortune Cookie tutorial has us doing)
I think this may be a bug in Motoko that is not allowing the trailing semi-colon, which I think is legal Candid. (I filed issue candid: motoko parser and candid spec appear to disagree on require terminal semicolon after service defn · Issue #4037 · dfinity/motoko · GitHub)
Also, I thought when the tutorial said “we remove those arguments in the public version of the dids”, that service : () -> {
would work just as well as service : {
. Are they not equivalent .did expressions?
No, they aren’t equivalent, you should strip the entire ... ->
. Motoko is expecting a candid file describing the interface of the installed service, i.e. everything after the ->
, while installing the ledger requires an explicit argument (everything to the left of the arrow). This inconvenience hacking could be avoided if we just let Motoko silently ignore the argument in the did file, which we intend to do in a release or two.
(There is an issue for that too Issues · dfinity/motoko · GitHub)
Now that that’s fixed I’m back to getting the canister alias "ckbtc_ledger" not defined
error on dfx deploy serve
or just dfx deploy
. Interestingly, dfx build serve
and dfx canister install serve --mode=reinstall
succeed (but the red squigglies remain) and dfx deploy serve
fails ("ckbtc_ledger" not defined
)
Ok, I think that’s due to a missing dependency of serve on ckbtc_ledger
in dfx.json
. See the dfx.json diffs below.
(Discovered by comparing with dfx.json in Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.)
I suspect something is going amiss when I’m trying to use the npm scripts set up in package.json with all the switching from icrc1.did to icrc1.public.did. I’m not sure which commands I was supposed to run, and in what order.
Indeed. I think you need to start with dfx.json referencing icrc1.did (with argument) to deploy the ledger, switch to the public did (without the argument) and then (build and) deploy serve
using the public did. All a bit gross. Sorry, I’ve never used the original project so am pretty fresh to this pain. For me, after this
(after fixing dfx.json and icrc1.public.did).
npm run private-dids
npm run deploy
seems to work for me.
Here are the diffs I applied to get this to work:
crusso@vm:~/videate/credits$ git diff
diff --git a/credits/dfx.json b/credits/dfx.json
index 9ef11a4..aa94add 100644
--- a/credits/dfx.json
+++ b/credits/dfx.json
@@ -2,10 +2,10 @@
"canisters": {
"ckbtc_ledger": {
"type": "custom",
- "candid": "icrc1.public.did",
+ "candid": "icrc1.did",
"wasm": "icrc1.wasm",
"remote": {
- "candid": "icrc1.public.did",
+ "candid": "icrc1.did",
"id": {
"ic": "mxzaz-hqaaa-aaaar-qaada-cai"
}
@@ -13,7 +13,10 @@
},
"serve": {
"main": "src/serve/serve.mo",
- "type": "motoko"
+ "type": "motoko",
+ "dependencies": [
+ "ckbtc_ledger"
+ ]
},
"frontend": {
"dependencies": [
diff --git a/credits/icrc1.public.did b/credits/icrc1.public.did
index 216a7aa..a77fbda 100644
--- a/credits/icrc1.public.did
+++ b/credits/icrc1.public.did
@@ -259,7 +259,7 @@ type DataCertificate = record {
hash_tree : blob;
};
-service : () -> {
+service : /* () -> */ {
icrc1_name : () -> (text) query;
icrc1_symbol : () -> (text) query;
icrc1_decimals : () -> (nat8) query;
@@ -273,4 +273,4 @@ service : () -> {
get_transactions : (GetTransactionsRequest) -> (GetTransactionsResponse) query;
get_blocks : (GetBlocksArgs) -> (GetBlocksResponse) query;
get_data_certificate : () -> (DataCertificate) query;
-};
+}//;
With those diffs, and after staring the replica, this seems to work:
crusso@vm:~/videate/credits$ npm run deploy
> credits_assets@0.1.0 deploy
> npm run deploy:ledger && npm run deploy:serve
> credits_assets@0.1.0 deploy:ledger
> PRINCIPAL=$(dfx identity get-principal) && dfx deploy ckbtc_ledger --argument "(variant {Init = record {minting_account = record { owner = principal \"$PRINCIPAL\" };transfer_fee = 10;token_symbol = \"ckBTC\";token_name = \"Token ckBTC\";metadata = vec {};initial_balances = vec {record { record {owner = principal \"$PRINCIPAL\"}; 100_000_000_000 } };archive_options = record {num_blocks_to_archive = 10_000;trigger_threshold = 20_000;cycles_for_archive_creation = opt 4_000_000_000_000;controller_id = principal \"$PRINCIPAL\";};}})" --mode=reinstall -y
Deploying: ckbtc_ledger
All canisters have already been created.
Building canisters...
Installing canisters...
Reinstalling code for canister ckbtc_ledger, with canister ID b77ix-eeaaa-aaaaa-qaada-cai
Deployed canisters.
URLs:
Frontend canister via browser
frontend: http://127.0.0.1:4943/?canisterId=by6od-j4aaa-aaaaa-qaadq-cai
Backend canister via Candid interface:
ckbtc_ledger: http://127.0.0.1:4943/?canisterId=asrmz-lmaaa-aaaaa-qaaeq-cai&id=b77ix-eeaaa-aaaaa-qaada-cai
internet_identity: http://127.0.0.1:4943/?canisterId=asrmz-lmaaa-aaaaa-qaaeq-cai&id=avqkn-guaaa-aaaaa-qaaea-cai
serve: http://127.0.0.1:4943/?canisterId=asrmz-lmaaa-aaaaa-qaaeq-cai&id=bw4dl-smaaa-aaaaa-qaacq-cai
> credits_assets@0.1.0 deploy:serve
> npm run public-dids && dfx deploy serve
> credits_assets@0.1.0 public-dids
> perl -i -pe 's|icrc1\.did|icrc1\.public\.did|g' dfx.json
Deploying: ckbtc_ledger serve
All canisters have already been created.
Building canisters...
Installing canisters...
Module hash 8ddd17ccaab8bd6adf337acb38f89b0db6db3c976f5768bb9a7ced5cef7bd481 is already installed.
Module hash a53d6ff98451b4dfaa802f6a1a48947ba39626138879873030d27dbd01823438 is already installed.
Deployed canisters.
URLs:
Frontend canister via browser
frontend: http://127.0.0.1:4943/?canisterId=by6od-j4aaa-aaaaa-qaadq-cai
Backend canister via Candid interface:
ckbtc_ledger: http://127.0.0.1:4943/?canisterId=asrmz-lmaaa-aaaaa-qaaeq-cai&id=b77ix-eeaaa-aaaaa-qaada-cai
internet_identity: http://127.0.0.1:4943/?canisterId=asrmz-lmaaa-aaaaa-qaaeq-cai&id=avqkn-guaaa-aaaaa-qaaea-cai
serve: http://127.0.0.1:4943/?canisterId=asrmz-lmaaa-aaaaa-qaaeq-cai&id=bw4dl-smaaa-aaaaa-qaacq-cai