Skip to main content

Method Signature

align.blockchain.nfts.isOwner(
  contractAddress: string,
  owner: string,
  tokenId: string,
  network: Network
): Promise<boolean>

Parameters

contractAddress
string
required
ERC-1155 contract address
owner
string
required
Address to check
tokenId
string
required
Token ID to check
network
string
required
Network

Returns

Returns true if the address owns at least 1 of the token, false otherwise.

Examples

import Align from "@tolbel/align";

const align = new Align({
  apiKey: process.env.ALIGN_API_KEY!,
  environment: "sandbox",
});

const owns = await align.blockchain.nfts.isOwner(
  "0xERC1155Contract...",
  "0xWalletAddress...",
  "42", // Token ID
  "polygon"
);

if (owns) {
  console.log("User owns token #42!");
} else {
  console.log("User does not own token #42");
}

Gate Access Based on NFT Ownership

async function checkAccess(userAddress: string): Promise<boolean> {
  // Check if user owns the "premium" token (ID 1)
  return align.blockchain.nfts.isOwner(
    MEMBERSHIP_CONTRACT,
    userAddress,
    "1", // Premium membership token ID
    "polygon"
  );
}

const hasAccess = await checkAccess(userWallet);
if (!hasAccess) {
  throw new Error("Premium membership required");
}