Skip to content

Instantly share code, notes, and snippets.

@fipso
Last active February 9, 2023 13:43
Show Gist options
  • Save fipso/683d682fdc41302593cc9ffb0c15eda5 to your computer and use it in GitHub Desktop.
Save fipso/683d682fdc41302593cc9ffb0c15eda5 to your computer and use it in GitHub Desktop.
fetch metadata json file from nft by contract address and token id
const { ethers } = require("ethers");
const rpc = "";
const addr = "";
async function main() {
// no providers object in ethers v6+
const provider = new ethers.JsonRpcProvider(rpc);
const abi = [
"function tokenURI(uint256 tokenId) public view returns (string)",
];
const contract = new ethers.Contract(addr, abi, provider);
const tokenURI = await contract.tokenURI(1);
console.log(tokenURI);
}
main().then(() => console.log("done"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment