Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thedavidmeister/3f6cfdeb856bb9e59f19712a1a0c9396 to your computer and use it in GitHub Desktop.
Save thedavidmeister/3f6cfdeb856bb9e59f19712a1a0c9396 to your computer and use it in GitHub Desktop.
get eth wallet in google sheets
function fetchJSON(url) {
var response = UrlFetchApp.fetch(url);
return JSON.parse(response.getContentText());
}
function ETHWALLET(address, token) {
if (address && token) {
var token = token + '';
var url = 'https://api.ethplorer.io/getAddressInfo/' + address + '?apiKey=freekey';
var val = fetchJSON(url);
// ETH is special case in API response
if (token === 'ETH') {
return val['ETH']['balance'];
}
else {
// look for our token
var ts = val['tokens'];
for (var i = 0; i < ts.length; i++) {
if (ts[i]['tokenInfo']['symbol'] === token) {
return ts[i].balance * Math.pow(10, -ts[i]['tokenInfo']['decimals']);
}
}
// token not found
return 0;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment