monitorchain-interface-library
NodeJS libraries for interfacing and integrating MonitorChain by subscribers.
Install
$ npm install monitorchain-interface-library
USAGE
Following modules are being exported by the library:
- AccessInterface - the interface is providing the public and restricted-to-subscribers methods
- Web3 - returns the web3 provider. The type of the provider is defined by the protocol type (web socket, http, ipc). If a 12 words mnemonic is passed - return the truffle-hdwallet-provider's instance
- ERC20Interface - can be used for accessing the ERC20 tokens' standard methods (name, symbol, totalSupply, etc.)
It supports both promises and the async-await calls with or without the callbacks.
Examples
const AccessInterface = ;const log = consolelog; const mc = 'http://main.infura.io/<API KEY>' '0xF8CE9D2....71337Bd6201a' //The MonitorChain address '12 words mnemonic is here'; // Get the list of supported tokens (resolve a promise)mc; // Get number of the supported tokens (using a callback)mc // Calculate a subscription price (async-await syntax)const calc = async { // 45-days subscription for 50 tokens const price = await mc; console;}; ; // Subscribe to given list of tokens (default period)const tokens = "0xB8c77482e45F1F44dE1745F52C74426C631bDD52" "0xf230b790E05390FC8295F4d3F60332c93BEd42e2"; mc; // 45 days subscriptionlet token = "0xE41d2489571d322189246DaFA5ebDe1F4699F498";mc; // Add a token to subscription (30 days), remit 1 eth for further purposesconst weiPerEth = "1000000000000000000";let newToken = "0xA4e8C3Ec456107eA67d3075bF9e3DF3A75823DB0";mc;
Using a built-in truffle hdwallet provider
const AccessInterface = ;const log = consolelog; const mc = 'http://localhost:8545' '0xF8CE9D27Ff65E59cc5499a44f3fd71337Bd6201a' '12 words mnemonic is here'; const subscribe = async mcwallet = 2; ; ; await mc; ; ; ;; ;
Using a custom web3 instance
const AccessInterface = ;const HDWalletProvider = ;const Web3 = ; const nodeAddress = 'http://localhost:8545';const monitorChainAddress = '0xF8CE9D27Ff65E59cc5499a44f3fd71337Bd6201a';const mnemonic = '12 words mnemonic is here'; const web3 = mnemonic nodeAddress 0 20; // A static method 'web3' allows to pass a custom web3 instanceconst mc = AccessInterface; mc;
Listening for realtime events
const AccessInterface ERC20Interface = ;const log = consolelog;const monitorChainAddress = '0xF8CE9D27Ff65E59cc5499a44f3fd71337Bd6201a'; const mc = 'http://localhost:8545' monitorChainAddress '12 words mnemonic is here'; const ws = 'ws://localhost:8543' monitorChainAddress; const callback = async { iferr throw err; const tokenAddress = await mc; if !tokenAddress return; // return if a customer is not subscribed to token ; ; const token =ERC20Interface; const tokenInfo = await token; ;}; ws;
Troubleshooting
Transactions are too slow
Increase a gas price:
const ERC20Interface = ;const token = ...;...tokengasPrice = 3; //gWei...
Error: Exceeds block gas limit
Decrease the gasLimit:
const ERC20Interface = ;const token = ...;...tokengasLimit = '3000000'...
Error: Cannot find module 'ethereumjs-wallet/hdkey'
$ npm uninstall ethereumjs-wallet$ npm install ethereumjs-wallet@0.6.0