2

How can I listen to NFT minting transactions (ERC721) using ethers.js ?

1 Answer 1

0
// 创建一个合约实例
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.