Skip to content

Instantly share code, notes, and snippets.

@raypulver
Created December 20, 2017 19:53
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 raypulver/4e998059ba9cb779ead83340fb726bf4 to your computer and use it in GitHub Desktop.
Save raypulver/4e998059ba9cb779ead83340fb726bf4 to your computer and use it in GitHub Desktop.
Simple script to get the DVIP balance in the sale contract
// using web3@1.0.0-beta.26, bluebird, bignumber.js, and lodash
'use strict';
const BN = require('bignumber.js');
const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io/aR7WPNCrZhhnYRnn8yRT'));
const { bindKey } = require('lodash');
const { promisify } = require('bluebird');
const encodeFunctionCall = bindKey(web3.eth.abi, 'encodeFunctionCall');
const payload = encodeFunctionCall({
name: 'balanceOf',
inputs: [{
name: 'owner',
type: 'address'
}]
}, [ '0x0d845706ddc11f181303a80828219c714ceb3687' ])
// payload is always 0x70a082310000000000000000000000000d845706ddc11f181303a80828219c714ceb3687
const call = promisify(bindKey(web3.eth, 'call'));
call({
to: '0xadc46ff5434910bd17b24ffb429e585223287d7f',
data: payload
}).then((v) => new BN(v).div(new BN(10).pow(8)).toPrecision())
.then((v) => console.log(v + ' DVIP remaining in sale'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment