0.3.11 • Published 2 years ago
@sotatek/crypto-currency-common v0.3.11
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=
0.3.11
2 years ago
0.3.10
3 years ago
0.3.9
3 years ago
0.3.8
3 years ago
0.3.7
3 years ago
0.3.6
3 years ago
0.3.5
3 years ago
0.3.4
3 years ago
0.3.3
3 years ago
0.3.2
4 years ago
0.2.5
4 years ago
0.3.1
4 years ago
0.3.0
4 years ago
0.2.1
4 years ago
0.2.0
4 years ago
0.2.3
4 years ago
0.2.2
4 years ago
0.2.4
4 years ago
0.1.27
4 years ago
0.1.26
4 years ago
0.1.25
4 years ago
0.1.24
4 years ago
0.1.23
4 years ago
0.1.22
4 years ago
0.1.21
4 years ago