How to call the canister by dfx using candid file?

I want to call the Ledger Canister to transfer icps by dfx.

My command is:

$ dfx canister --network= --no-wallet call ryjl3-tyaaa-aaaaa-aaaba-cai send_dfx '(record {memo=0; amount=record {e8s=110000}; fee=record {e8s=10000}; to="05cf7b06399ebc51e81e7008407d2bf2ebe60e9886931f14e12402750df6a1de"})'
The Replica returned an error: code 5, message: "Canister ryjl3-tyaaa-aaaaa-aaaba-cai trapped explicitly: Panicked at 'Deserialization Failed: "Deserialize error: Type mismatch. Type on the wire: Int; Expected type: Nat64"', /builds/dfinity-lab/dfinity/rs/rust_canisters/dfn_core/src/"

I guess the error is caused by the dfx did not find the .did file, so the number (Int) was not converted to Nat64 correctly.

I know there are others ways to transfering icp, such as dfx ledger transfer <args>, But I want to transfer in two steps, signing first, then sending the message to ledger canister.

More importantly, I want to know the universal interaction with canister, as I know the canister id and canister interface(the .did file).

1 Like

dfx cannot fetch did files for external canisters. We are adding better support for this. For now, the work around is to put type annotations for all numbers, e.g. amount=record {e8s=110000:nat64}


This solved my problem perfectly :motoko:

1 Like