Hello everyone,
I am playing around with canisters and I have hit a roadblock when it comes to passing an argument from a javascript front-end to a motoko canister.
In the front-end the failling call is as follow:
api.mintNFT( {“to”: {“address” : “123456789123456789” } } ).then( response => {…
The problem is the formatting of the argument {“to”: {“address” : “123456789123456789” }}. For some reason, this format is rejected. I have tried a large number of variations such as without quotation, without brackets, different brackets, adding the word “record”, adding the word “variant”, removing “address”,etc. It is probably a silly mistake and I wonder if anyone could help. The biggest problem is that the rejection does not send an error back which makes it tedious to guess the problem…
The motoko target function is as follow:
public shared({ caller }) func mintNFT (request : MintRequest) : async () {
let recipient = ExtCore.User.toAID(request.to);
let token = nextTokenId;
ledger.put(token, recipient);
nextTokenId := nextTokenId + 1;
};
The type MintRequest is as follow:
public type MintRequest = {
to : ExtCore.User;
metadata : ?Blob;
};
The type user is as follow:
public type User = {
#address : AccountIdentifier; //No notification
#principal : Principal; //defaults to sub account 0
};
I can call it successfully from terminal in this format:
dfx canister call betadeck mintNFT “(record { to = variant { address = “123456789123456789” }; })”
I have successfully created and called other functions in the same canister, but never succeeded at passing any argument…
How do I pass arguments properly from javascript to motoko canister?
Many thanks in advance!!!