dev111
December 3, 2021, 5:58pm
1
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
rbolog
December 3, 2021, 10:04pm
2
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;
};
};
dev111
December 4, 2021, 8:02pm
3
Thanks for the response
It can be called in dfx with:
dfx canister call testCanister testFunction ‘(variant {owner})’