Currently I am writing smart contract code in anchor. When i declare a pub struct in smart contract I can access it in type script easily using IdlType example:
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy)]
#[repr(C)]
/// Stores meta information about the `Account` on chain
pub struct UserData {
// user pk
pub user_pk : Pubkey,
// user balance in lamports for the game / user
pub user_balance : u64,
}
can be accessed in typescript code as follows
type UD = anchor.IdlTypes<Program>["UserData"];
let userData : UD = account.userData;
let userBalance = data.userBalance;
But i am not able to do same things with enums instead of structs.
// rust code
enum UserType {
client,
employee
}
// ts code
type UT = anchor.IdlTypes<Program>["UserType"];
let userType : UT = account.userType;
assert(userType == UT.client);
Could you help me to find out how to use enums.
UT
and what value do you get asuserType
?data
andaccount
variables intentional?type UT = {}
but in case of UD I havetype UD = { userPk: anchor.web3.PublicKey; userBalance: anchor.BN; }
value of user type is :const userType: TypeDef<{ name: "UserType"; type: { kind: "enum"; variants: [{ name: "client"; }, { name: "employee"; }]; }; } & { name: "UserType"; }, Record<string, never>>
anchor.IdlAccount<Program>
and data is member of that account.