epicchain-js
Running EpicChain Blockchain Full Node with Node.js and MongoDB
epicchain-js
is a comprehensive Node.js package designed specifically for developers and blockchain enthusiasts to interact with the EpicChain blockchain effortlessly. This package acts as a bridge between your application and the EpicChain network, allowing you to synchronize and query blockchain data, manage nodes, and easily perform various blockchain operations using JavaScript.
EpicChain is built for scalability, speed, and security, and epicchain-js
fully utilizes these features. By integrating MongoDB as a storage backend, you can synchronize the blockchain state across nodes, making the entire process faster and more reliable.
This tool can be used in various scenarios such as:
- Running full nodes for the EpicChain blockchain.
- Interacting with the blockchainโs RPC methods.
- Synchronizing blockchain data with MongoDB for permanent storage.
- Querying blockchain information, such as block height, transaction details, and more.
To begin working with epicchain-js
, it's essential to ensure that your development environment meets the necessary requirements and dependencies. Follow the instructions below to set everything up properly.
Before diving into the code, ensure that you have MongoDB installed and properly configured. MongoDB 3.2 or newer is required to handle the blockchain synchronization and storage features provided by this package. MongoDB will store blockchain data locally, ensuring efficient and quick access to blockchain state across your applications.
- MongoDB Installation: You can install MongoDB via MongoDBโs official website.
- MongoDB Connection: Ensure that MongoDB is running on your local machine or a remote server, and you have the appropriate connection string to use it in your project.
Before starting, ensure you have the following installed on your system:
- Node.js v8 or above (LTS versions are recommended for stability).
- MongoDB v3.2+ (This is a critical requirement for synchronizing data with the blockchain).
If you're unfamiliar with how to install Node.js or MongoDB, here are some quick resources:
To get started with epicchain-js
, install it using npm, the Node.js package manager. This package can be installed directly from the npm registry, ensuring that you always get the latest stable version.
-
Basic Installation:
Use the following command to install the package in your project:
$ npm install --save @epicchain/epicchain-js
-
Installing the Development Version:
If you want to experiment with the latest code or contribute to the project, you can install the development version directly from the GitHub repository:
$ npm install --save git://github.com/epicchainlabs/epicchain-js.git#develop
This will install the latest development changes, but please note that this version may be less stable than the official release.
Once installed, you can start using epicchain-js
in your project. Hereโs a simple walkthrough to get you started with EpicChain interactions.
In your projectโs entry file, import the epicchain-js
module like this:
const EpicChain = require('@epicchain/epicchain-js').EpicChain;
This will give you access to all the functionality you need to interact with the EpicChain blockchain.
You can choose between connecting to the testnet or the mainnet. Both networks offer real-time blockchain data, but the testnet is safer for experimentation and testing purposes.
// Create an instance for the testnet
const testnetEpicChain = new EpicChain({ network: 'testnet' });
// Wait for the node to be ready before making API calls
testnetEpicChain.mesh.on('ready', () => {
// Fetch block count from the testnet
testnetEpicChain.api.getBlockCount().then((res) => {
console.log('Testnet Block Count:', res);
});
});
// Create an instance for the mainnet
const mainnetEpicChain = new EpicChain({ network: 'mainnet' });
// Wait for the node to be ready before making API calls
mainnetEpicChain.mesh.on('ready', () => {
// Fetch block data for block number 1000 from the mainnet
mainnetEpicChain.api.getBlock(1000).then((res) => {
console.log('Mainnet Block 1000 Hash:', res.hash);
});
});
Once your instance is set up, you can start interacting with the EpicChain node and synchronize it with MongoDB. This allows your node to track the state of the blockchain and store data in a local database for fast retrieval.
const options = {
network: 'testnet', // Specify the network (testnet or mainnet)
storageType: 'mongodb', // Use MongoDB for data synchronization
storageOptions: {
connectionString: 'mongodb://localhost/epicchain_testnet', // Connection string for MongoDB
},
};
// Create the EpicChain instance with the options
const epicchain = new EpicChain(options);
// Wait for the storage to be ready and fetch the highest block height
epicchain.storage.on('ready', () => {
epicchain.storage.getHighestBlockHeight().then((res) => {
console.log('Highest Block Height:', res);
});
});
This setup will connect your node to MongoDB and synchronize the blockchain data for efficient querying and storage.
The documentation provides more detailed information and covers advanced features of the epicchain-js
package. Be sure to check out the following links to expand your knowledge:
To bootstrap your own EpicChain instance or to run a node without downloading the entire blockchain, refer to the Bootstrap Files Documentation.
The configuration options are highly customizable to meet your needs. You can specify different networks, storage configurations, and more. For a full list of customizable options, refer to the Optional Parameters Documentation.
epicchain-js
is event-driven. Many of the methods emit events that you can listen to in order to perform specific actions when certain events occur. Learn more about the available events in the Event Emitters Documentation.
We actively encourage contributions from the community to improve and extend epicchain-js
. Whether you are fixing bugs, adding new features, or enhancing the documentation, your contributions are welcome.
Before you contribute, please read our Contributing Guidelines to ensure a smooth process. You can contribute by forking the repository, making your changes, and submitting a pull request.
By contributing, you agree to license your contributions under the MIT License.
epicchain-js
is an open-source package licensed under the MIT License.
For full licensing information, please visit the LICENSE file in the repository.
This version includes in-depth explanations of each section, offering more detailed insights for developers and users while ensuring a clean and modern design style. It focuses on guiding users through setup, configuration, and contributing to the project.