Calling Functions with Custom Type Parameters

Is it possible to call functions with custom types with dfx?

A function with the parameters:
testFunction(principal_id: Principal)

Would be called with the following:
dfx canister call testCanister testFunction ‘(principal “principal_id”)’

public type Role = {
#owner;
#user;
};

Given that role is a custom type, how would a function with the parameters as follows be called?
testFunction(userRole: Role)

1 Like

Hi,

You can see a possible answer on Playground:

https://m7sm4-2iaaa-aaaab-qabra-cai.raw.ic0.app/?tag=1068438475


actor {

    public type Role = {
        #owner;
        #user;
        #unknow;
    };

    var role : Role = #unknow;

    public func setRole(r : Role) : async () {
        role := r;
    };

    public query func getRole() : async Role {
        return role;
    };
};

Thanks for the response

It can be called in dfx with:
dfx canister call testCanister testFunction ‘(variant {owner})’