Created
June 5, 2018 09:52
-
-
Save thedavidmeister/3f6cfdeb856bb9e59f19712a1a0c9396 to your computer and use it in GitHub Desktop.
get eth wallet in google sheets
This file contains 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
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