3

I would like to know how many people own the erc20 tokens I created.

Is there a way to check through the api? Or please tell me another good way.

2 Answers 2

2

If your token is emitting logs correctly, Etherscan's Holders tab should show the info. See for example USDC: "Top 1,000 holders (From a total of 1,483,388 holders)".

1
  • I want to check through the api, not from Etherscan.
    – imelon2
    Aug 29, 2022 at 2:30
0

Yes you can use api to fetch the token holders data. https://docs.chainbase.com/reference/gettokenholders here is the node.js code example Using fetch in JavaScript.

network_id = '1'; // See https://docs.chainbase.com/reference/supported-chains to get the id of different chains.
token_addr = '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0'; // Take MATIC token address as an example.

fetch(`https://api.chainbase.online/v1/token/holders?chain_id=${network_id}&contract_address=${token_addr}&page=1&limit=20`, {
    method: 'GET',
    headers: {
        'x-api-key': CHAINBASE_API_KEY, // Replace the field with your API key.
        'accept': 'application/json'
    }
}).then(response => response.json())
    .then(data => console.log(data.data))
    .catch(error => console.error(error));

Using axios in JavaScript. You need to install axios using npm install axios --save in the terminal first.

network_id = '1'; // See https://docs.chainbase.com/reference/supported-chains to get the id of different chains.
token_addr = '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0'; // Take MATIC token address as an example.

const axios = require('axios');
const options = {
    url: `https://api.chainbase.online/v1/token/holders?chain_id=${network_id}&contract_address=${token_addr}&page=1&limit=20`,
    method: 'GET',
    headers: {
        'x-api-key': CHAINBASE_API_KEY, // Replace the field with your API key.
        'accept': 'application/json'
    }
};
axios(options)
    .then(response => console.log(response.data.data))
    .catch(error => console.log(error));

To better leverage the ability that Chainbase provides, you can register here for a free account and access to different APIs and data cloud.

After logging into Chainbase, visit the dashboard to get an overview. Create a new project in the console and get an API key.

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.