[BUG?] need to specify nat when using dfx to call a canister

With dfx 0.11.2 when calling a a canister that takes a Nat as an argument, we now have to specify the type of the number passed. E.g. this doesn’t work with the REPL

❯ dfx canister --network ic call xgktx-viaaa-aaaab-qadda-cai set '(7)'
dfx.json not found, using default.
Error: Failed update call.
Caused by: Failed update call.
  The Replica returned an error: code 5, message: "Canister xgktx-viaaa-aaaab-qadda-cai trapped explicitly: IDL error: unexpected IDL type when parsing Nat"

but this does

❯ dfx canister --network ic call xgktx-viaaa-aaaab-qadda-cai set '(7 : nat)'
dfx.json not found, using default.
()

IIRC this never had to be specified previously if the method expected a plain Nat. The README of the Counter example also specifies to just call dfx canister call counter set '(7)'.

@chenyan @diegop

That should be a feature request for dfx. When calling dfx with canister id, we didn’t fetch the did file from the canister, so number defaults to Int. If you are calling by the project name as specified in dfx.json, you don’t need this type annotation.

1 Like

What would be the feature request for dfx then? To try and fetch the candid from the canister when calling by canister id or to assume Nat instead of Int?

Yep, Always fetch the did file from canister metadata. I’ve filed the ticket internally. Also as a workaround, you can use --candid to specify the did file in dfx canister call.

1 Like