Skip to content

useGlyphTokenGate

(Available from v1.0.25)

A hook that checks token ownership, allowing you to gate specific features of your web app based on whether a user holds the required NFTs.

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 { useGlyphTokenGate } from "@use-glyph/sdk-react";

Usage

tsx
function TokenGateComponent() {
	const { checkTokenGate, isTokenGateLoading } = useGlyphTokenGate();
    const [contractAddress, setContractAddress] = useState<string>("");

	const handleTokenGate = async () => {
		const tokenOwnership = await checkTokenGate({ contractAddress });
		if (tokenOwnership.error) return alert(`Tokengate 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={isTokenGateLoading || !contractAddress}
            >
                {isTokenGateLoading ? "Checking..." : "Check token ownership"}
            </button>
        </div>
	);
}

Return Type

PropertyTypeDescription
checkTokenGate(req: GlyphOwnershipCheckRequest) => Promise<GlyphTokenGateResult>Function to check token gating requirements
isTokenGateLoadingbooleanLoading 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).

GlyphTokenGateResult

PropertyTypeDescription
resultbooleanWhether the user meets the token gating requirements.
errorstringError message if the check failed (only present when result is false).