Created
June 17, 2019 14:36
-
-
Save kolya-t/7504d01eb965615b81b5bbd16d86ceef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`)) | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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