2

I have created an Open Zeppelin subgraph so I can track many different ERC20, ERC721 and ERC1155 smart contracts.

My config.json looks like this:

{
    "output": "generated/sample.",
    "chain": "mainnet",
    "datasources": [
        { 
            "address": "0x8B0D1a282f132f67fc2018CeB797890D9C513710", 
            "startBlock": 31900771, 
            "module": [
                "erc20", 
                "ownable", 
                "accesscontrol"
            ] 
        },
        { 
            "address": "0x63dbcD091fBE539B70fB855bB941055e7EE80324", 
            "startBlock": 31895100, 
            "module": [
                "erc721", 
                "ownable", 
                "accesscontrol"
            ] 
        },
        { 
            "address": "0xDE7195E8865576A1c9Faae5f7c7d543967bF704E", 
            "startBlock": 32356993, 
            "module": [
                "erc1155", 
                "ownable", 
                "accesscontrol"
            ] 
        }
    ]
}

I am trying to query my wallet to see how many ERC721 tokens I have, like this:

{
  account(id: "0xfe02781cc0fe76Bfd2D211430bfa97D2889fd853") {
    ERC721tokens {
      id
    }
  }
}

Problem is I am getting this as a result:

{
  "data": {
    "account": {
      "ERC721tokens": []
    }
  }
}

I actually hold 2 tokens of 0x63dbcD091fBE539B70fB855bB941055e7EE80324 (you can check it here).

How can I get the right balance of ERC721? My subgraph is 100% synced and has no issues.

2 Answers 2

4

As an alternative to the graph, you can also use API providers to query the ERC721 balance from EVM blockchains. For example, you can use Moralis getWalletNFTs API to do the same thing in a few lines of code.

Simply install the moralis package

npm install moralis

and use the following code with your API Key

import Moralis  from 'moralis';
import { EvmChain } from '@moralisweb3/evm-utils';

try {
    const address = '0xfe02781cc0fe76Bfd2D211430bfa97D2889fd853';

    const chain = EvmChain.MUMBAI;

    await Moralis.start({
        apiKey: "YOUR_API_KEY",
        // ...and any other configuration
    });

    const response = await Moralis.EvmApi.nft.getWalletNFTs({
        address,
        chain,
    });

    console.log(response?.result);
} catch (e) {
    console.error(e);
}

And you will the ERC721 balance easily just like that. Hope this helps 😃

P.S. I work for Moralis

0

The problem was I wasn't updating my subgraph correctly.

Every time you make a modification to your config.json, you need to re-compile, re-create and re-deploy it with these commands:

npx graph-compiler --config configs/config.json --include node_modules/@openzeppelin/subgraphs/src/datasources --export-schema --export-subgraph


graph create generated/sample --node http://127.0.0.1:8020


graph deploy --ipfs http://localhost:5001 --node http://localhost:8020 generated/sample ./generated/sample.subgraph.yaml

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.