#ethplorer-js
A promise based Nodejs library to interface with the Ethplorer API
##Usage
Import the Libary:
import { Ethplorer } from 'ethplorer-js';
let Ethplorer = require('ethplorer-js').Ethplorer
To initialize:
let api = new Ethplorer('<Your Key Here>');
let api = new Ethplorer();
Then use any of the methods, described here. e.g
api.getTokenInfo(address)
.then(data => {
})
Any optional parameters can be passed as an optional argument. e.g
api.getTokenPriceHistoryGrouped(address,{ period: 30 })
.then(data => {
})
api.getTop({limit: 10})
.then(data => {
})
Errors
The response object from the functions can be the error object from the Ethplorer API, you can either handle it manually like so:
api.getTokenInfo(address)
.then(data => {
if("error" in data){
}
else {
}
})
Alternatively
function handleEthplorerError(response){
if("error" in data){
throw data;
}
return data;
}
api.getTokenInfo(address)
.then(handleEthplorerError)
.then(data => {
})
.catch(err => {
})
Typescript
If you're using Typescript all requests and responses are fully typed according to the Ethplorer API.
Note: If you have any trouble with the typescript autocomplete from the response, you may need to check if the result is an error or not for typehinting to come back, as shown above.