To run: npm install && node index.js
Note: You must have Geth running. Geth (hehe) it here. After installing, run geth --rpc
To run: npm install && node index.js
Note: You must have Geth running. Geth (hehe) it here. After installing, run geth --rpc
| /* | |
| This checker assumes you have geth installed and running. | |
| */ | |
| const fs = require('fs'); | |
| const Web3 = require('web3'); | |
| const fetch = require('node-fetch'); | |
| let web3 = new Web3(); | |
| web3.setProvider(new web3.providers.HttpProvider("http://127.0.0.1:8545")); | |
| async function run() { | |
| const response = await fetch('https://raw.githubusercontent.com/kvhnuke/etherwallet/mercury/app/scripts/tokens/ethTokens.json'); | |
| const tokens = await response.json(); | |
| parseTokens(tokens); | |
| } | |
| async function checkToken(token) { | |
| let newToken = await web3.eth.getCode(token).then((err, res) => { | |
| if(err) throw err; | |
| return res; | |
| }).catch(err => { | |
| return err; | |
| }); | |
| return newToken; | |
| } | |
| function parseTokens(arr) { | |
| var newArr = []; | |
| var nonErc20 = []; | |
| var counter = 0; | |
| arr.forEach(item => { | |
| counter++; | |
| checkToken(item.address).then(res => { | |
| if(res !== '0x') { | |
| newArr.push(item); | |
| } else { | |
| nonErc20.push(item); | |
| } | |
| if(counter === arr.length) { | |
| if(newArr.length > 0) { | |
| createNewFile('ethToken.json', newArr); | |
| } | |
| if(nonErc20.length > 0) { | |
| createNewFile('nonErc20.json', nonErc20); | |
| } | |
| } | |
| }); | |
| }); | |
| } | |
| function createNewFile(name, arr) { | |
| fs.writeFileSync(name, JSON.stringify(arr)); | |
| } | |
| run(); |
| { | |
| "name": "token-tester", | |
| "version": "1.0.0", | |
| "description": "", | |
| "main": "index.js", | |
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| }, | |
| "author": "", | |
| "license": "ISC", | |
| "devDependencies": { | |
| "node-fetch": "^2.1.2", | |
| "web3": "^1.0.0-beta.33" | |
| } | |
| } |