It’s important for developers of wallets, scripts, apps, and dApps to understand how to properly setup their API functions to get info from the EOS chain. I have information below on how to setup failover / fallback servers.

Background on EOS API

EOS has a built-in API plugin for the main node software, nodeos. There are various filters that can be applied to the transactional history that gets filtered through this process. There are extremely high costs for running an API node that has a full transactional history. Currently, the RAM usage for full history on the nodeos plugin was 800GB on Nov 2, and over 1.2 TB today on Nov 13. Servers with this capacity of RAM cost over $30k per server, but with the rate of growth in the memory usage, running nodeos is not sustainable. Therefore, the plugin is being refactored by Block.One’s development team to better integrate with more scalable database platforms — such as postgresql.

Bad Practice

There are currently too many examples of people hard-coding a single API (most commonly Greymass). This is NOT a good practice. There is no API node that will have 100% uptime. I have seen a lot of apps and scripts that are depending on Greymass and their node will go down from time to time. (It’s actually down this morning as I’m writing this.)

EOS API Proxy

The Blockmatrix team has created an excellent geo-DNS redundant proxy for EOS API nodes. The proxy will automatically route requests to the best servers that can handle those requests and he has served over 1.2 billion requests in the past 2 weeks.

Config Example: Javascript Function for EOS API Failover

Here is an example of how we recommend setting up a failover/fallback for API calls in a js function. The primary API I recommend using is https://proxy.eosnode.tools – secondarily there should be at least one fallback API node (ideally another proxy).

In this example, I have referenced the fallback proxy to shEOS high-availability bare metal servers, but you can use any nodes listed here on the EOS Nation report.

EosRequest("/v1/chain/get_info", " https://proxy.eosnode.tools ", " https://api.proxy1a.sheos.org/ "); function EosRequest(path, url, fallback, retry = false) {

let query = retry === false ? url : fallback;

fetch(query + path)

.then(function(response) {

if (!response.ok) {

if (retry === true) {

throw Error(response.statusText);

} else {

return EosRequest(path, url, fallback, true);

}

}

return response;

}).then(function(response) {

response.json().then(function(data) {

console.log(data)

});

}).catch(function(error) {

if (retry === true) {

console.log(error);

} else {

return EosRequest(path, url, fallback, true);

}

});

}

Any questions or comments? You can reach me on Twitter — @bensig.