Token Gating

Generate plug-and-play code snippets to restrict access based on NFT ownership.

Your Contract Address

Enter your contract address to auto-populate it in the code snippets below.

React / Next.jstsx
import { useAccount, useReadContract } from 'wagmi';

const NFT_CONTRACT = "0xYOUR_CONTRACT_ADDRESS";
const NFT_ABI = [
  {
    inputs: [{ name: "owner", type: "address" }],
    name: "balanceOf",
    outputs: [{ name: "", type: "uint256" }],
    stateMutability: "view",
    type: "function",
  },
];

function TokenGatedContent() {
  const { address } = useAccount();

  const { data: balance } = useReadContract({
    address: NFT_CONTRACT,
    abi: NFT_ABI,
    functionName: "balanceOf",
    args: [address],
  });

  const hasAccess = balance && Number(balance) > 0;

  if (!hasAccess) {
    return (
      <div className="text-center p-8">
        <h2>Access Restricted</h2>
        <p>You need to hold an NFT from this collection to view this content.</p>
      </div>
    );
  }

  return (
    <div>
      <h2>Welcome, NFT Holder!</h2>
      {/* Your gated content here */}
    </div>
  );
}

export default TokenGatedContent;

How to Integrate

1

Deploy Your Collection

Deploy an ERC-721 collection using the Deploy page and get your contract address.

2

Choose a Snippet

Select the integration type that fits your stack — React, HTML, or backend.

3

Copy & Paste

Paste the snippet into your project. It checks NFT ownership and gates content automatically.