epicchain-js
Running EpicChain blockchain full node with Node.js and MongoDB.
epicchain-js
is a package designed to interface with the EpicChain blockchain in various ways configured by options used to initialize a node. Below are examples of different interaction mechanics, as detailed in the quickstart and examples.
This module supports MongoDB for synchronizing the blockchain. Ensure you are connected to an instance of MongoDB 3.2+ to utilize its features.
- NodeJS 8+
- MongoDB 3.2+
Install the package using:
$ npm install --save @epicchainlabs/epicchain-js
Alternatively, to access the latest available code, reference the git repository directly:
$ npm install --save git://github.com/epicchainlabs/epicchain-js.git#develop
For comprehensive examples, visit the epicchain-js-examples
repository.
const EpicChain = require('@epicchainlabs/epicchain-js').EpicChain;
To create a new blockchain instance:
// Create a EpicChain instance to interface with RPC methods
const testnetEpicChain = new EpicChain({ network: 'testnet' });
// Wait for mesh to be ready before attempting to fetch block information
testnetEpicChain.mesh.on('ready', () => {
testnetEpicChain.api.getBlockCount().then((res) => {
console.log('Testnet getBlockCount:', res);
});
});
// To connect to the mainnet:
const mainnetEpicChain = new EpicChain({ network: 'mainnet' });
mainnetEpicChain.mesh.on('ready', () => {
mainnetEpicChain.api.getBlock(1000).then((res) => {
console.log('Mainnet getBlock(1000).hash:', res.hash);
});
});
This will create a new node instance and configure it to sync the blockchain to the defined MongoDB collections:
const options = {
network: 'testnet',
storageType: 'mongodb',
storageOptions: {
connectionString: 'mongodb://localhost/epicchain_testnet',
},
};
// Create a EpicChain instance
const epicchain = new EpicChain(options);
// Get block height
epicchain.storage.on('ready', () => {
epicchain.storage.getHighestBlockHeight().then((res) => {
console.log('Block height:', res);
});
});
Project documentation is available at:
Additional code examples can be found at:
Refer to the Bootstrap Files document.
Refer to the Optional Parameters document.
Refer to the Event Emitters document.
epicchain-js
encourages community code contributions. Before contributing, read the contributor guidelines and search the issue tracker. To contribute, fork epicchain-js
, commit your changes, and submit a pull request.
By contributing, you agree that your contributions will be licensed under the MIT license.
- Open-source MIT.
- Authors: