Created
November 26, 2017 13:42
-
-
Save EthereumWorks/25cf33cc932e48717dc08534213bf974 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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