How can I listen to NFT minting transactions (ERC721) using ethers.js ?
1 Answer
// 创建一个合约实例
const contract = new ethers.Contract(contractAddress, abi, provider);
// 监听 Transfer 事件
contract.on("Transfer", (from, to, tokenId) => {
// 获取代币的元数据 URI
const tokenURI = await contract.tokenURI(tokenId);
// 解析元数据 JSON
const metadata = await fetch(tokenURI).then(res => res.json());
// 获取代币的名称
const name = metadata.name;
});
from: new Bing