Read contracts
Read factory, token, router, collection, and marketplace state.
Contract reads expose current launch settings, token identity, pool details, listings, fees, and proceeds. These calls do not require a connected wallet.
Read launch factory state
import { Contract, formatEther } from "ethers";
import { addresses, provider } from "./spawn";
const factory = new Contract(addresses.launchFactory, [
"function createTokenEnabled() view returns (bool)",
"function initialBuyAmount() view returns (uint256)",
"function tokenCount() view returns (uint256)",
"function feeRecipientForToken(address token) view returns (address)",
"function referrerForToken(address token) view returns (address)",
"function referralFeesGenerated(address referrer,address asset) view returns (uint256)",
"function tokenToNFTId(address token) view returns (uint256)",
"function tokenFeesGenerated(address token) view returns (uint256)",
], provider);
const [enabled, initialBuy, tokenCount] = await Promise.all([
factory.createTokenEnabled(),
factory.initialBuyAmount(),
factory.tokenCount(),
]);
console.log({
enabled,
initialBuyEth: formatEther(initialBuy),
tokenCount: tokenCount.toString(),
});
Read a launched token
const token = new Contract(tokenAddress, [
"function name() view returns (string)",
"function symbol() view returns (string)",
"function totalSupply() view returns (uint256)",
"function getTokenInfo() view returns (address deployer,string logo,string description,(string website,string x,string telegram,string discord,string other) socials)",
"function getTokenPair() view returns (address pool,address pairedToken,address factory)",
], provider);
const [name, symbol, info, pair] = await Promise.all([
token.name(),
token.symbol(),
token.getTokenInfo(),
token.getTokenPair(),
]);
console.log({ name, symbol, info, pair });
Treat returned URLs and descriptions as untrusted launcher content when rendering them.
Read a listing
const marketplace = new Contract(addresses.nftMarketplace, [
"function listings(address collection,uint256 tokenId) view returns (address seller,uint256 price,uint64 expiresAt,uint256 platformFee,address royaltyReceiver,uint256 royaltyAmount)",
"function isListingValid(address collection,uint256 tokenId) view returns (bool)",
"function pendingProceeds(address account) view returns (uint256)",
"function platformFeeBps() view returns (uint96)",
"function paused() view returns (bool)",
], provider);
const [listing, valid] = await Promise.all([
marketplace.listings(collectionAddress, tokenId),
marketplace.isListingValid(collectionAddress, tokenId),
]);
console.log({
seller: listing.seller,
priceWei: listing.price.toString(),
expiresAt: Number(listing.expiresAt),
platformFeeWei: listing.platformFee.toString(),
royaltyReceiver: listing.royaltyReceiver,
royaltyWei: listing.royaltyAmount.toString(),
valid,
});
Read an NFT and its royalty
const collection = new Contract(collectionAddress, [
"function ownerOf(uint256 tokenId) view returns (address)",
"function tokenURI(uint256 tokenId) view returns (string)",
"function supportsInterface(bytes4 interfaceId) view returns (bool)",
"function royaltyInfo(uint256 tokenId,uint256 salePrice) view returns (address receiver,uint256 royaltyAmount)",
], provider);
const ERC2981_INTERFACE_ID = "0x2a55205a";
const [owner, tokenUri, hasRoyalties] = await Promise.all([
collection.ownerOf(tokenId),
collection.tokenURI(tokenId),
collection.supportsInterface(ERC2981_INTERFACE_ID),
]);
Call royaltyInfo only after confirming support or handle a revert from a non-ERC-2981 collection.