Created
September 13, 2017 21:35
-
-
Save adastreamer/cb4c9cea92d1bdb518e0cb1e56c2eca0 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
<div class="col-12 col-md-4 text-center text-bold"> | |
<h2 class="number" id="contract-balance">$135 000</h2> | |
<p class="text mt-0">Баланс смарт-контракта</p> | |
</div> | |
<div class="col-12 col-md-4 text-center text-bold"> | |
<h2 class="number" id="investors-count">10</h2> | |
<p class="text mt-0">Количество инвесторов</p> | |
</div> | |
<div class="col-12 col-md-4 text-center text-bold"> | |
<h2 class="number" id="tokens-count">10 342</h2> | |
<p class="text mt-0">Общее количество купленных токенов</p> | |
</div> | |
<script> | |
var tokenAddress = '0x241684ef15683ca57c42d8f4bb0e87d3427ddf1c'; | |
var tokenDecimals = 8; | |
var tokenPrice = 2.8; | |
var crowdsaleAddress = '0x3881c403a2ed46d171f813a0dac67dcc438d6f91'; | |
var totalTokens = 504000; | |
var apiKey = '1KPI5JUY9JBUHQMH7IQ12F2DINIVXD69VH'; | |
var updateInterval = 60000; // 60 secs | |
var tokensСountElement = document.getElementById('tokens-count'); | |
var investorsСountElement = document.getElementById('investors-count'); | |
var contractBalanceElement = document.getElementById('contract-balance'); | |
var updateTokensCount = function(){ | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', 'https://api.etherscan.io/api?module=account&action=tokenbalance&contractaddress=' + tokenAddress + '&address=' + crowdsaleAddress + '&tag=latest&apikey=' + apiKey, false); | |
xhr.send(); | |
if (xhr.status != 200) { | |
tokensСountElement.innerHTML = '?'; | |
} else { | |
var tokensCount = totalTokens - JSON.parse(xhr.responseText).result / (10**tokenDecimals); | |
tokensСountElement.innerHTML = Math.round(tokensCount * 100) / 100; | |
contractBalanceElement.innerHTML = '$' + (Math.round(tokensCount * tokenPrice * 100) / 100); | |
} | |
}; | |
updateTokensCount(); | |
setInterval(updateTokensCount, updateInterval); | |
var updateInvestorsCount = function(){ | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', 'http://api.etherscan.io/api?module=account&action=txlist&address=' + crowdsaleAddress + '&startblock=0&endblock=9999999999&apikey=' + apiKey, false); | |
xhr.send(); | |
if (xhr.status != 200) { | |
investorsСountElement.innerHTML = '?'; | |
} else { | |
investorsСountElement.innerHTML = JSON.parse(xhr.responseText).result.filter(function(tx){ | |
return tx.to == crowdsaleAddress; | |
}).length; | |
} | |
}; | |
updateInvestorsCount(); | |
setInterval(updateInvestorsCount, updateInterval); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment