Skip to content

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

PropertyTypeDescription
checkOwnership(req: GlyphOwnershipCheckRequest) => Promise<GlyphOwnershipCheckResult>Function to check token gating requirements
isOwnershipCheckLoadingbooleanLoading state for the token gate check operation

GlyphOwnershipCheckRequest

PropertyTypeRequiredDescription
contractAddressstringYesThe contract address of the NFT (ERC721 and ERC1155) to check for ownership.
chainIdnumberNoThe network ID to check ownership on. If not provided, uses the current connected network (typically Apechain).
quantitynumberNoMinimum quantity of tokens required for access (default: 1).
tokenIdRangestringNoSpecific token ID range to check (e.g., "1-100").
includeDelegatesbooleanNoWhether to include delegated tokens in the ownership check (default: true).

GlyphOwnershipCheckResult

PropertyTypeDescription
resultbooleanWhether the user meets the token gating requirements.
errorstringError message if the check failed (only present when result is false).
tokensGlyphOwnedToken[]Array of tokens owned by the user.
delegationChainGlyphDelegationChainItem[]Array of delegation chain items.

GlyphOwnedToken

PropertyTypeDescription
idnumberThe token ID.
qtynumberThe quantity of tokens owned by the user.
ownerstringThe address of the owner of the token.
delegatedbooleanWhether the token is delegated.
linkedbooleanWhether the token is linked.

GlyphDelegationChainItem

PropertyTypeDescription
accountstringThe address of the account that delegated the token.
contractAddressstringThe contract address of the token.
tokenIdsnumber[]The token IDs of the tokens owned by the user.
sourcestringThe source of the token.
linkedbooleanWhether the token is linked.