useGlyphOwnershipCheck
(Available from v1.0.25)
Similar to useGlyphTokenGate, this hook checks token ownership, allowing you to gate specific features of your web app based on whether a user holds the required NFTs, including additional information about the NFTs owned by the user.
This hook resolves delegations (unless disabled) and NFT ownership for any user, regardless of the wallet provider being used. However, ownership resolution through linked wallets and their corresponding delegates is supported for Glyph users only.
Delegations are resolved on a per-network basis, so users must delegate their assets on the same network where the gating occurs for this feature to function as expected.
Import
tsx
import { useGlyphOwnershipCheck } from "@use-glyph/sdk-react";Usage
tsx
function TokenGateComponent() {
const { checkOwnership, isOwnershipCheckLoading } = useGlyphOwnershipCheck();
const [contractAddress, setContractAddress] = useState<string>("");
const handleOwnershipCheck = async () => {
const tokenOwnership = await checkOwnership({ contractAddress });
if (tokenOwnership.error) return alert(`Ownership check error: ${tokenOwnership.error}`);
alert(tokenOwnership.result ? "NFT owned" : "NFT not owned");
};
return (
<div className="flex flex-col items-center justify-center gap-4 mt-4 text-center">
<input
type="text"
placeholder="Contract address"
value={contractAddress}
onChange={(e) => setContractAddress(e.target.value)}
/>
<button
onClick={()=> handleTokenGate()}
disabled={isOwnershipCheckLoading || !contractAddress}
>
{isOwnershipCheckLoading ? "Checking..." : "Check token ownership"}
</button>
</div>
);
}Return Type
| Property | Type | Description |
|---|---|---|
| checkOwnership | (req: GlyphOwnershipCheckRequest) => Promise<GlyphOwnershipCheckResult> | Function to check token gating requirements |
| isOwnershipCheckLoading | boolean | Loading state for the token gate check operation |
GlyphOwnershipCheckRequest
| Property | Type | Required | Description |
|---|---|---|---|
| contractAddress | string | Yes | The contract address of the NFT (ERC721 and ERC1155) to check for ownership. |
| chainId | number | No | The network ID to check ownership on. If not provided, uses the current connected network (typically Apechain). |
| quantity | number | No | Minimum quantity of tokens required for access (default: 1). |
| tokenIdRange | string | No | Specific token ID range to check (e.g., "1-100"). |
| includeDelegates | boolean | No | Whether to include delegated tokens in the ownership check (default: true). |
GlyphOwnershipCheckResult
| Property | Type | Description |
|---|---|---|
| result | boolean | Whether the user meets the token gating requirements. |
| error | string | Error message if the check failed (only present when result is false). |
| tokens | GlyphOwnedToken[] | Array of tokens owned by the user. |
| delegationChain | GlyphDelegationChainItem[] | Array of delegation chain items. |
GlyphOwnedToken
| Property | Type | Description |
|---|---|---|
| id | number | The token ID. |
| qty | number | The quantity of tokens owned by the user. |
| owner | string | The address of the owner of the token. |
| delegated | boolean | Whether the token is delegated. |
| linked | boolean | Whether the token is linked. |
GlyphDelegationChainItem
| Property | Type | Description |
|---|---|---|
| account | string | The address of the account that delegated the token. |
| contractAddress | string | The contract address of the token. |
| tokenIds | number[] | The token IDs of the tokens owned by the user. |
| source | string | The source of the token. |
| linked | boolean | Whether the token is linked. |
