Onchain Reads
viewHat
Get a hat's properties.
const hat = await hatsClient.viewHat(hatId);
Arguments:
hatId: bigint
hatId
- The hat ID.
Response:
{
details: string;
maxSupply: number;
supply: number;
eligibility: Address;
toggle: Address;
imageUri: string;
numChildren: number;
mutable: boolean;
active: boolean;
}
details
- hat's details field.maxSupply
- maximum amount of wearers.supply
- current amount of wearers.eligibility
- hat's eligibility address.toggle
- hat's toggle address.imageUri
- hat's image URI.numChildren
- number of child hats.mutable
-true
if the hat is mutable,false
otherwise.active
-true
if the hat is active,false
otherwise.
isWearerOfHat
Check if an address is a wearer of a specific hat. An address is considered a wearer of a hat if the following conditions are met:
The address owns the hat's token ID (hat ID).
The hat is active (controlled by the hat's toggle).
The wearer is eligible for the hat (controlled by the hat's eligibility).
const isWearer = await hatsClient.isWearerOfHat({
wearer,
hatId,
});
Arguments:
{
wearer: Address;
hatId: bigint;
}
wearer
- wearer's address.hatId
- hat's ID.
Response:
boolean
true
if the given address is a wearer of the hat, false
otherwise.
isAdminOfHat
Check if an address is an admin of a specific hat. An address is an admin of a hat if it wears one of the hat's predecessor hats.
const isAdmin = await hatsClient.isAdminOfHat({
user,
hatId,
});
Arguments:
{
user: Address;
hatId: bigint;
}
user
- address to check whether an admin.hatId
- hat's ID.
Response:
boolean
true
if the given address is an admin of the hat, false
otherwise.
isActive
Check if a hat is active.
const isActive = await hatsClient.isActive(hatId);
Arguments:
hatId: bigint
hatId
- hat's ID.
Response:
boolean
true
if the given hat is active, false
otherwise.
isInGoodStanding
Check if a wearer is in good standing for a given hat.
const isGoodStanding = await hatsClient.isInGoodStanding({
wearer,
hatId,
});
Arguments:
{
wearer: Address;
hatId: bigint;
}
wearer
- address to check whether in good standing.hatId
- hat's ID.
Response:
boolean
true
if the given wearer is in good standing, false
otherwise.
isEligible
Check if an address is eligible for a specific hat.
const isEligible = await hatsClient.isEligible({
wearer,
hatId,
});
Arguments:
{
wearer: Address;
hatId: bigint;
}
wearer
- address to check whether is eligible.hatId
- hat's ID.
Response:
boolean
true
if the given address is eligible for the hat, false
otherwise.
predictHatId
Predict the ID of a yet to be created hat.
const hatId = await hatsClient.predictHatId(admin);
Arguments:
admin: bigint
admin
- parent hat of the would be created one.
Response:
bigint
Hat ID of the would be created hat.
getTreesCount
Get the number of existing trees.
const numTrees = await hatsClient.getTreesCount();
Response:
number
Current number of trees.
getLinkageRequest
Get the linkage request of a tree.
const requestedAdminHat = await hatsClient.getLinkageRequest(topHatDomain);
Arguments:
topHatDomain: number
topHatDomain
- the tree domain. The tree domain is the first four bytes of the tophat ID.
Response:
bigint
If request exists, returns the requested new admin hat ID. If not, returns zero.
getLinkedTreeAdmin
Get the admin of a linked tree (the hat which the tophat is linked to).
const adminHat = await hatsClient.getLinkedTreeAdmin(topHatDomain);
Arguments:
topHatDomain: number
topHatDomain
- the tree domain. The tree domain is the first four bytes of the tophat ID.
Response:
bigint
If tree is linked, returns the admin hat ID of the linked tree. If not, returns zero.
getHatLevel
Get a hat's level. If the tree is linked, level is calculated in the global tree (comprised of all linked trees).
const level = await hatsClient.getHatLevel(hatId);
Arguments:
hatId: bigint
hatId
- hat's ID.
Response:
number
The hat's level in the global tree.
getLocalHatLevel
Get a hat's level in its local tree (without considering linked trees).
const level = await hatsClient.getLocalHatLevel(hatId);
Arguments:
hatId: bigint
hatId
- hat's ID.
Response:
number
The hat's local level.
getTopHatDomain
Get a hat's tree domain.
const domain = await hatsClient.getTopHatDomain(hatId);
Arguments:
hatId: bigint
hatId
- hat's ID.
Response:
number
The tree domain of the hat. The tree domain is the first four bytes of the tophat ID.
getTippyTopHatDomain
Get the tree domain of the global's tree tophat (tippy top hat), which the provided tree is included in.
const domain = await hatsClient.getTippyTopHatDomain(topHatDomain);
Arguments:
topHatDomain: number
topHatDomain
- The tree domain. The tree domain is the first four bytes of its tophat ID.
Response:
number
The tree domain of the tippy top hat.
getAdmin
Get the direct admin of a hat.
const admin = await hatsClient.getAdmin(hatId);
Arguments:
hatId: bigint
hatId
- hat's ID.
Response:
bigint
The admin's hat ID. If the provided hat is an unlinked tophat, then this top hat ID is returned, as it is the admin of itself. Otherwise, the hat's parent hat ID is returned.
getChildrenHats
Get the children hats of a hat.
const children = await hatsClient.getChildrenHats(hatId);
Arguments:
hatId: bigint
hatId
- hat's ID.
Response:
bigint[]
The hat's children IDs.
Last updated