Skip to content

Instantly share code, notes, and snippets.

@josephros
josephros / index.html
Last active August 13, 2017 17:06
web3 enabled html page
<!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>
@josephros
josephros / index.html
Last active August 13, 2017 17:59
Token Balance Explorer Form Template
<!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>
@josephros
josephros / erc20.js
Last active November 17, 2018 17:42
ERC20 ABI for NodETH Tutorial
var erc20Abi = [
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"name": "",
"type": "string"
}
@josephros
josephros / index.js
Last active August 13, 2017 17:41
Query ERC20 token
// 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
@josephros
josephros / index.js
Created August 13, 2017 17:43
Update the interface with the results
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';
@josephros
josephros / index.html
Last active December 12, 2018 09:51
Ethereum Token Balance Explorer
<!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>
@josephros
josephros / tokenvalue-coinmarketcap-get.js
Last active August 22, 2017 15:08
Get basic ticker info from a token contracts name/symbol using the coinmarketcap.com API
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();
@josephros
josephros / tokenvalue-etherest.js
Last active November 17, 2018 17:31
Query ETHEREST for tokenvalue demo script data
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";
}