How do I send int64 with CLI?

I have this function

#[query]
fn balance_of(token_holder: Principal, timestamp: Option<i64>) -> Nat {
   ...
}

How do I invoke it with CLI?
I tried
dfx canister call canister_name balance_of '(principal "rwlgt-iiaaa-aaaaa-aaaaa-cai", null)'

but only got

An error happened during the call: 5: IC0503: Canister rrkah-fqaaa-aaaaa-aaaaq-cai trapped explicitly: Custom("No more values to deserialize")"

1 Like

If I change this function so it receives i64 instead of Option<i64> like this

#[query]
fn balance_of1(token_holder: Principal, timestamp: i64) -> Nat {
    ...
}

and then call it like this

dfx canister call canister_name balance_of1 '(principal "rwlgt-iiaaa-aaaaa-aaaaa-cai", 100)'

I get this error

An error happened during the call: 5: IC0503: Canister rrkah-fqaaa-aaaaa-aaaaq-cai trapped explicitly: Deserialize("Type mismatch. Type on the wire: Int; Expected type: Int64", "Trailing type: []\nTrailing value: [e4, 00]\nType table: []\nRemaining value types: []")"

Ooh, I see.

Looks like CLI takes it’s typetable from the .did file and if that one is out of date it fails.

I would be cool to have another candid notation for CLI, so we could dynamically specify types right after relevant values.

1 Like

I think you should just be able to provide a type annotation (but may be wrong):

dfx canister call canister_name balance_of1 '(principal "rwlgt-iiaaa-aaaaa-aaaaa-cai", 100 : int64)'
3 Likes