Method Signature
align.blockchain.nfts.isOwner(
contractAddress: string,
owner: string,
tokenId: string,
network: Network
): Promise<boolean>
Parameters
ERC-1155 contract address
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");
}
const owns = await align.blockchain.nfts.isOwner(
contract,
walletAddress,
tokenId,
"polygon"
);
console.log("Owns token:", owns);
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");
}