Giter VIP home page Giter VIP logo

scc-common's Introduction

Quick Start

const { CurrencyRegistry, GatewayRegistry } = require("sota-common");
require("sota-eth");
require("sota-btc");

async function prepareEnvironment() {
  CurrencyRegistry.setCurrencyConfig(CurrencyRegistry.Ethereum, {
    restEndpoint: `https://rinkeby.infura.io/v3/${process.env.INFURA_PROJECT_ID}`
  });

  const btcRPCConfig = {
    protocol: process.env.BTC_RPC_PROTOCOL,
    host: process.env.BTC_RPC_HOST,
    port: process.env.BTC_RPC_PORT,
    user: process.env.BTC_RPC_USER,
    pass: process.env.BTC_RPC_PASS
  };

  CurrencyRegistry.setCurrencyConfig(CurrencyRegistry.Bitcoin, {
    rpcEndpoint: JSON.stringify(btcRPCConfig),
    restEndpoint: process.env.BTC_REST_ENDPOINT // http://priv-btc-explorer.sotatek.com/api
  });
}

async function main() {
  await prepareEnvironment();
  const ethGateway = GatewayRegistry.getGatewayInstance(CurrencyRegistry.Ethereum);
  const contractAddress = "0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa";
  const tokenInfo = await ethGateway.getErc20TokenInfo(contractAddress);
  console.log(tokenInfo);

  const btcGateway = GatewayRegistry.getGatewayInstance(CurrencyRegistry.Bitcoin);
  const blockCount = await btcGateway.getBlockCount();
  console.log(`Current block count: ${blockCount}`);

  const txid = "4570f2cf7dc65a0fb80920b19c727563b19e392fce3f11d399e72d326d82fe8d";
  const tx = await btcGateway.getOneTransaction(txid);
  console.log(tx);
}

main()
  .then(() => {
    console.log(`FINISHED.`);
    process.exit(0);
  })
  .catch(e => {
    console.error(e);
    process.exit(1);
  });

Notes for logging

Log level

Application log level can be configured by this environment variable:

LOG_LEVEL={debug/info/warn/error}

If the log level is not explicit defined, the info level will be used as default.

Config for CloudWatch

To enable CloudWatch logger, these environment variables must be set:

CWL_ENABLED={true/false}
CWL_LOG_GROUP_NAME=<Custom log group name here>
CWL_LOG_STREAM_PREFIX=<Custom log stream prefix here>

Some optional configurations can be set to customized CW settings:

CWL_LOG_LEVEL={debug/info/warn/error}
CWL_UPLOAD_RATE=<time in milliseconds>
CWL_AWS_ACCESS_KEY_ID=
CWL_AWS_ACCESS_KEY_SECRET=
CWL_AWS_REGION_ID=

scc-common's People

Contributors

chubby-chocobo avatar yuu-sotatek avatar sotatek-congnguyen avatar sotatek-sinhvu avatar sotatek-mainguyen avatar sotatek-ducpham avatar tuna-date avatar dependabot[bot] avatar sotatek-quanta avatar iiamtrg avatar sotatek-tunguyen avatar sotatek-hungnguyenthanh avatar johnny-vu avatar tuanhoang0203 avatar johnnyhoangit avatar

Watchers

James Cloos avatar Dong Do avatar Huy Doan Van avatar

Forkers

wlyl1999

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.