I went through https://infura.io/docs but not sure if Infura could allow me to read token details like owner, token Id, etc. I also googled on how to read token using Infura but to no avail.
Has anyone tried it?
I went through https://infura.io/docs but not sure if Infura could allow me to read token details like owner, token Id, etc. I also googled on how to read token using Infura but to no avail.
Has anyone tried it?
Here's a demo that lets you pull NFT data programmatically from the blockchain:
https://github.com/cryptogoth/demo-erc721
for example, a few Devcon5 tickets are sold as NFTs https://etherscan.io/token/0x22cc8b3666e926bcbf58cb726143b2b044c80a0c?a=34410171212740518240382548201030436272862311489479305301712148182074228170203
Using the demo, you can call any of the methods in the ERC721 ABI at http://erc721.org
In particular, calling ownerOf
for the token ID above gives:
NFT Owner is {"0":"0x66040374e443ae3e25afef08a781c4c2d175f43c"}
There is a manual step of creating / adding an empty Ethereum account, which you can then use to call mutator methods that cost gas. I'm working on automating this step from the command-line demo as well. Hope it helps, questions and feedback welcome.
Try this:
const Web3 = require("web3");
async function run() {
const web3 = new Web3("https://mainnet.infura.io/v3/" + YOUR_INFURA_PROJECT_ID);
const contract = new web3.eth.Contract(YOUR_CONTRACT_ABI, YOUR_CONTRACT_ADDRESS);
const retVal = await contract.methods.somePureOrViewFunction(arg1, arg2).call();
const varVal = await contract.methods.somePublicVariable().call();
}
run();