Skip to content

EpicChain JS Develop is a powerful toolkit designed for developers to run a full EpicChain blockchain node using Node.js and MongoDB.

License

Notifications You must be signed in to change notification settings

epicchainlabs/epicchain-js-dev

Repository files navigation

epicchain-js

Running EpicChain blockchain full node with Node.js and MongoDB.

npm version

Overview

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.

Getting Started

Preparations

This module supports MongoDB for synchronizing the blockchain. Ensure you are connected to an instance of MongoDB 3.2+ to utilize its features.

System Recommendations

  • NodeJS 8+
  • MongoDB 3.2+

Installation

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

Quick Start

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);
  });
});

Documentation

Project documentation is available at:

Additional code examples can be found at:

Blockchain Bootstrap Files

Refer to the Bootstrap Files document.

Options

Refer to the Optional Parameters document.

Events

Refer to the Event Emitters document.

Contribution

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.

License

Releases

No releases published

Packages

No packages published