JSFiddle - React, Tailwind, and code Playground
by shrpne
HTML
<progress id="progress" max="" value=""></progress>
<label for="progress"></label>
<div id="log"></div>
<pre id="result"></pre>
JavaScript
const networks = {
1: {
rpc: 'https://rpc.ankr.com/eth',
etherscan: 'https://api.etherscan.io',
ankrChain: 'eth',
},
56: {
rpc: 'https://rpc.ankr.com/bsc',
etherscan: 'https://api.bscscan.com',
ankrChain: 'bsc',
},
};
const labelEl = document.querySelector('label');
const progressEl = document.querySelector('#progress');
const logEl = document.querySelector('#log');
function showError(error) {
console.error(error);
logEl.innerText = logEl.innerText + error.message + '\n';
}
function setProgress(current, total) {
labelEl.innerText = current + '/' + total;
progressEl.setAttribute('max', total);
progressEl.value = current;
}
getSmartContractsByCreator(56, '0x84B748b6a51548f3C1a59DAF4f36dF47Ca7fB4B5', '0x324718b3ce9906fcf5ce140342146eb16970d889')
.then((res) => console.log(res));
async function getSmartContractsByCreator(chainId, tokenContractAddress, swCreatorAddress, ankrApiKey, etherscanApiKey) {
try {
const factoryTxResponse = await fetch(`${networks[chainId].etherscan}/api?module=account&action=txlistinternal&address=${swCreatorAddress}&startblock=0&page=1&offset=10000&sort=asc&apikey=${etherscanApiKey}`);
const factoryTxData = await factoryTxResponse.json();
const swList = factoryTxData.result
.filter((tx) => {
return tx.isError === '0' && tx.type.indexOf('create') === 0;
})
.map((tx) => tx.contractAddress.toLowerCase());
// Fetch the token holders from the Ankr API
const ankrResponse = await fetch("https://rpc.ankr.com/multichain/?ankr_getTokenHolders=", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
},
body: JSON.stringify({
id: 1,
jsonrpc: "2.0",
method: "ankr_getTokenHolders",
...