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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://cdn.jsdelivr.net/npm/web3@0.20.1/dist/web3.min.js"></script> | |
</head> | |
<body> | |
<script> | |
// create a web3 object connected to our NodETH node | |
var web3 = new Web3(new Web3.providers.HttpProvider("<node rpc url>")); | |
</script> |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Ethereum Token Balance Explorer</title> | |
<script src="https://cdn.jsdelivr.net/npm/web3@0.20.1/dist/web3.min.js"></script> | |
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script> | |
</head> | |
<body> | |
<h1>Ethereum Token Balance Explorer</h1> |
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
var erc20Abi = [ | |
{ | |
"constant": true, | |
"inputs": [], | |
"name": "name", | |
"outputs": [ | |
{ | |
"name": "", | |
"type": "string" | |
} |
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
// 1. get the total supply | |
token.totalSupply.call(function (err, totalSupply) { | |
// 2. get the number of decimal places used to represent this token | |
token.decimals.call(function (err, decimals) { | |
// 3. get the name of the token |
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
var percentOwned = balance.div(totalSupply).mul(100); | |
var divisor = new web3.BigNumber(10).toPower(decimals); | |
totalSupply = totalSupply.div(divisor); | |
balance = balance.div(divisor); | |
var results = '<b>Token:</b> ' + name + '<br />'; | |
results += '<b>Total supply:</b> ' + totalSupply.round(5) + '<br /><br />'; | |
results += accountAddress + ' owns ' + balance.round(5) + ' which is ' + percentOwned.round(5) + '% of the total supply'; |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Ethereum Token Balance Explorer</title> | |
<script src="https://cdn.jsdelivr.net/npm/web3@0.20.1/dist/web3.min.js"></script> | |
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script> | |
</head> | |
<body> | |
<h1>Ethereum Token Balance Explorer</h1> |
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
async function getTokenPriceData (symbol, name) { | |
symbol = symbol.toLowerCase(); | |
name = name.toLowerCase(); | |
let tickers = await request('https://api.coinmarketcap.com/v1/ticker/', { | |
json: true | |
}); | |
return _.find(tickers, function (ticker) { | |
var tickerSymbol = ticker.symbol.toLowerCase(); |
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
try { | |
var [name, symbol, decimals, balance] = await Promise.all([ | |
token.name(), | |
token.symbol(), | |
token.decimals(), | |
token.balanceOf(argv[1]) | |
]); | |
} catch (err) { | |
throw "Could not get required data from token contract"; | |
} |