0

I want to get unique holder's addresses displayed in this smart contract: https://etherscan.io/token/0x7db5af2B9624e1b3B4Bb69D6DeBd9aD1016A58Ac#balances

Like, fetch these 21450 holder wallet addresses into my database. I have searched all over the internet, but couldn't find anything to do this.

enter image description here

I am using NodeJs to pull wallets from this contract. I have checked in the ABI file as well, but couldn't find such a function

Any help would be highly appreciated. Thanks in advance

I have tried collecting holders using transfer events. but the unique count that I fetched is less than 21,450

const getContract = async (contractAddress, contractAbi) => {
  w3 = new Web3(new Web3.providers.HttpProvider(config.WEB3_PROVIDER_URL));
  const filePath = path.join(__dirname, "assets", contractAbi);

  const fileContent = await readFile(filePath);
  return new w3.eth.Contract(JSON.parse(fileContent), contractAddress);
};
// since we cannot fetch all addresses at once, I am passing zero, and last block number as start and end respectively, and using below algorithm
const binaryPull = async (contract, start, end, callback) => {
  try {
    console.log("start, end", start, end);

    if (start <= end) {
      const result = await contract.getPastEvents("Transfer", {
        fromBlock: start,
        toBlock: end,
      });
      if (result.length) callback(result);
    }
  } catch (error) {
    if (error.message.includes("query returned more than 10000 results")) {
      const mid = Math.floor((start + end) / 2);
      await binaryPull(contract, start, mid, callback);
      await binaryPull(contract, mid + 1, end, callback);
    } else {
      logger.error(`error while pulling from smart contract: ${error.message}`);
    }
  }
};

const pullWallets = async (token, callback) => {
  const contract = await getContract(token.contract_address, token.abi_file);
  const latest = await w3.eth.getBlockNumber();

  await binaryPull(
    contract,
    token.last_block_number,
    latest,
    async (events) => {
      console.log("count", events.length);
      // I am collecting event.returnValues.to and event.returnValues.from to get the holder wallets
    }
  );
  return latest;
};

0 Answers0