Skip to content

Instantly share code, notes, and snippets.

@kolya-t
Created June 17, 2019 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kolya-t/7504d01eb965615b81b5bbd16d86ceef to your computer and use it in GitHub Desktop.
Save kolya-t/7504d01eb965615b81b5bbd16d86ceef to your computer and use it in GitHub Desktop.
const fs = require('fs');
const Web3 = require('web3');
const web3 = new Web3('https://mainnet.infura.io/v3/1198c5abaa8c4d3e8e170694ca1e3d59');
const abi = [{
"constant": true,
"inputs": [{"name": "", "type": "address"}],
"name": "registers",
"outputs": [{"name": "", "type": "string"}],
"payable": false,
"stateMutability": "view",
"type": "function"
}];
const linkerAddress = '0x8b748672f7ff9c46647106c7c735e33bfbaca47b';
(async () => {
const addresses = fs.readFileSync('export-0x8b748672f7ff9c46647106c7c735e33bfbaca47b.csv', {encoding: 'UTF-8'})
.split('\n')
.filter((_, index) => index !== 0 && index !== 1)
.map(e => e.split(",")[4])
.map(e => e.match(/\w+/)[0])
.map(e => e.toLowerCase())
.filter((value, index, self) => self.indexOf(value) === index);
const linker = new web3.eth.Contract(abi, linkerAddress);
const ethBnbLinks = [];
fs.writeFileSync('addresses.csv', '');
for (const ethAddress of addresses) {
const bnbAddress = await linker.methods.registers(ethAddress).call();
if (bnbAddress !== '') {
ethBnbLinks.push({ ethAddress, bnbAddress });
}
}
ethBnbLinks.forEach(({ ethAddress, bnbAddress }) => fs.appendFileSync('addresses.csv', `${ethAddress},${bnbAddress}\n`))
})();
{
"name": "linkFetcher",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"web3": "^1.0.0-beta.55"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment