0

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?

0

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();
  • I'll try this and will let you know the outcome. – vocotipex Sep 30 at 10:19
0

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.

  • I dont mind, but the API doesn't allow me to view NFT token details. – vocotipex Sep 30 at 10:17
  • @vocotipex you're correct, Etherscan is just ERC20. I changed my answer to include a demo for ERC721 using the Democracy framework. Let me know if you have problems using it. – Paul Pham Sep 30 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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