Skip to content

Instantly share code, notes, and snippets.

@EthereumWorks
Created November 26, 2017 13:42
Show Gist options
  • Save EthereumWorks/a00efe77b87359378c7c337467e95215 to your computer and use it in GitHub Desktop.
Save EthereumWorks/a00efe77b87359378c7c337467e95215 to your computer and use it in GitHub Desktop.
var MAINET_RPC_URL = 'https://mainnet.infura.io/metamask' ;
var ROPSTEN_RPC_URL = 'https://ropsten.infura.io/metamask' ;
var KOVAN_RPC_URL = 'https://kovan.infura.io/metamask' ;
var RINKEBY_RPC_URL = 'https://rinkeby.infura.io/metamask' ;
var CURRENT_URL = MAINET_RPC_URL ;
$( document ).ready(function() {
web3 = new Web3(new Web3.providers.HttpProvider(CURRENT_URL));
var wallet = '0x45e044ED9Bf130EafafA8095115Eda69FC3b0D20' ;
$('.check_balance').click(function(){
address = wallet ;
balance = getBalance(address) ;
console.log(balance) ;
});
function getBalance(address) {
if (address.length <= 3) {
alert("Wallet address is incorrect") ;
return 0 ;
}
web3.eth.getBalance(address, function(error, result){
console.log('yes') ;
if(!error) {
balance = result.toString(10) ;
setBalance(balance) ;
$.cookie("address", address);
} else {
alert('Some error happens. Please, try again.') ;
console.error(error);
}
});
}
function setBalance(wei) {
eth = wei / 1000000000000000000 ;
eth = web3.fromWei(wei, 'ether') ;
$('.balance_positive').html(eth) ;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment