Motoko Help on calling Type Structure

This is my Motoko function and structure (type) how i can call the canister from the console to use the function ?

type MarsLand = {
name: Text;
imageurl: Text;
tokenid:Text;
};

// adds new MarsLand to 
public func addMarsLand (newMarsLand: MarsLand) : async Id {
    let id = next;
    next +%= 1;
    MarsLands := Trie.replace(
        MarsLands,
        key(id),
        eq,
        ?newMarsLand,
    ).0;

    return id;
};  

My canister is marspoolxyx and can i call with below code in console.

dfx canister call marspoolxyz addMarsLand ‘{“tokenid:1001”,“name:Paris”,“imageurl:Rome”}’

Thanks for your reply

You’ll want to format it like this:

dfx canister call marspoolxyz addMarsLand '( record {name="Paris"; imageurl="Rome"; tokenid="1001"} )'

dfx uses the candid textual format, you can find a bit more info on this here:
https://sdk.dfinity.org/docs/candid-guide/candid-concepts.html#textual-values
And here:
https://sdk.dfinity.org/docs/candid-guide/candid-concepts.html#_candid_types_and_values

3 Likes

Thank you Ori !
:heart:ing already !

Now, I am able to call from the candid from console.

But, how to do reference that in Javascript in front-end
This link is broken/404

https://sdk.dfinity.org/docs/candid-types.html

The _assets directory in your project should get you started, and then this: https://sdk.dfinity.org/docs/candid-guide/candid-types.html

Thanks for spotting the broken link!
@lsgunn

1 Like