0.0.1 • Published 9 months ago

eal-sdk v0.0.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
9 months ago

Coiin EAL JS SDK

Talk to your Coiin EAL chain.

Docs

Full docs for the SDK can be found here.

Installation

npm i coiin-eal-sdk --save

Initialize The Client

const sdk = require('coiin-eal-sdk');

const main = async () => {
  const client = await sdk.createClient({
    coiinEalId: 'c2dffKwiGj6AGg4zHkNswgEcyHeQaGr4Cm5SzsFVceVv'
  });
  // Do something with the client here
};

main()
  .then(console.log)
  .catch(console.error);

GetBlock

const call = await client.getBlock({ blockId: '56841' });

if (call.ok) {
  console.log('Successful call!');
  console.log(`Block: ${call.response}`);
} else {
  console.error('Something went wrong!');
  console.error(`HTTP status code from chain: ${call.status}`);
  console.error(`Error response from chain: ${call.response}`);
}

Configuration

In order to use this SDK, you need to have an Auth Key as well as an Auth Key ID for a given Coiin EAL ID. It is also strongly suggested that you supply an endpoint locally so that a remote service isn't called to automatically discover your coiin eal endpoint. These can be loaded into the sdk in various ways, and are checked in the following order of precedence:

  1. The createClient method can be initialized with an object containing the parameters coiinEalId: <ID>, authKey: <KEY>, authKeyId: <KEY_ID>, and endpoint: <URL>

  2. The environment variables COIIN_EAL_ID, AUTH_KEY, AUTH_KEY_ID, and COIIN_EAL_ENDPOINT, can be set with the appropriate values

  3. An ini-style credentials file can be provided at ~/.coiin-eal/credentials (or on Windows: %LOCALAPPDATA%\coiin-eal\credentials) where the section name is the coiin eal id, with values for auth_key, auth_key_id, and endpoint. Additionally, you can supply a value for coiin_eal_id in the default section to initialize the client for a specific chain without supplying an ID any other way

[default]
coiin_eal_id = c2dffKwiGj6AGg4zHkNswgEcyHeQaGr4Cm5SzsFVceVv

[c2dffKwiGj6AGg4zHkNswgEcyHeQaGr4Cm5SzsFVceVv]
auth_key_id = JSDMWFUJDVTC
auth_key = n3hlldsFxFdP2De0yMu6A4MFRh1HGzFvn6rJ0ICZzkE
endpoint = https://35a7371c-a20a-4830-9a59-5d654fcd0a4a.eal.coiin.io

[28VhSgtPhwkhKBgmQSW6vrsir7quEYHdCjqsW6aAYbfrw]
auth_key_id = OGNHGLYIFVUA
auth_key = aS73Si7agvX9gfxnLMh6ack9DEuidKiwQxkqBudXl81
endpoint = https://28567017-6412-44b6-80b2-12876fb3d4f5.eal.coiin.io

Logging

In order to get the logging output of the sdk, a logger must be set (by default all logging is ignored).

In order to set the logger, simply call .setLogger on the root of the require/import. For example, if you just wanted to log with console (i.e. stdout, stderr, etc), you can set the logger like the following:

const sdk = require('coiin-eal-sdk');
sdk.setLogger(console);

In that example, console can be replaced with any custom logger as long as it implements log, info, warn, debug, and error functions.

To reset the logger back to default (so it doesn't output anymore), simply called setLogger() with no params.

0.0.1

9 months ago