- Introduction
- Features
- Community
- Getting Started
- Usage
- Local Development
- Configuration
- Running the Network
- Stopping the Network and Cleanup
- Testing and Metamask
- Starting the JSON-RPC Server
- Contributing
- License
- Contact
Shardeum is built to solve the scalability and performance challenges faced by existing blockchain networks. By implementing sharding, Shardeum ensures that the network can handle a large number of transactions per second without compromising security or decentralization.
- Scalability: Sharding enables horizontal scalability, allowing the network to process more transactions as the number of nodes increases.
- High Performance: Optimized consensus mechanisms and efficient transaction handling ensure low latency and high throughput.
- Security: Advanced cryptographic techniques and robust consensus protocols provide a secure environment for transactions and smart contracts.
- Decentralization: Designed to be a truly decentralized network with no single point of failure.
- Interoperability: Supports Ethereum Virtual Machine (EVM) for compatibility with existing DApps and smart contracts.
For help, discussion about code, or any other conversation that would benefit from being searchable:
For chatting with others using Shardeum:
Join the Shardeum Discord Server
Before you begin, ensure you have the following installed on your system:
- Node.js (version 18.16.1)
- npm (version 9.5.1)
- Docker (optional, for containerized deployment)
-
Clone the Repository:
git clone https://github.com/shardeum/shardeum.git cd shardeum -
Install Dependencies:
npm install
-
Setup Environment Variables: Copy the
.env_exampleto.envand customize the settings as needed.cp .env_example .env
-
Start the Node:
npm run start
-
Run in Docker (Optional):
docker build -t shardeum . docker run -d -p 8080:8080 shardeum
-
Using CLI:
npm run cli
-
Using API: The node exposes a REST API for interacting with the blockchain. Refer to the API documentation for more details.
To run a Shardeum network for local development, the instructions below will help you configure your machine to spin up local validator, archiver, and monitor servers.
Shardeum requires a specific version of Node.js version 18.16.1 and npm version 9.5.1. To manage multiple versions of Node.js, we recommend using the Node Version Manager (NVM). Follow these steps to install NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bashSet NVM directory
export NVM_DIR="$HOME/.nvm"Load NVM and its bash completion scripts by adding the following lines to your .bashrc or .bash_profile:
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completionThe networking code for the validator has been implemented in Rust as a node module to optimize the performance of Shardeum. You can install Rust using the following command:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shImport the Rust environment variables by running the following command:
source "$HOME/.cargo/env"To compile the code, ensure you have the correct Rust version installed. For compatibility reasons, use Rust version 1.74.1. You can install it by running:
rustup install 1.74.1And set it as the default Rust version:
rustup default 1.74.1For Linux:
sudo apt-get install build-essentialFor MacOS:
brew install gccBefore proceeding further, run the following commands to check the version of npm and node associated with your system.
node --version
18.16.1
npm --version
9.5.1Make sure you have node version 18.16.1 and npm version 9.5.1 installed which is what most of our tech currently requires. If you are on the wrong version of Node, you can use the Node Version Manager (aka “nvm”) to get the correct one.
nvm use 18.16.1node-gyp is a command-line tool that enables the compilation of native addon modules for Node.js. To ensure its proper functioning, it's essential to install node-gyp globally using npm. Additionally, configure the Python version. Follow these steps to install node-gyp and set the Python version:
npm i -g node-gyp // Install node-gyp globally
npm config set python `which python3` // Configure the Python version
npm config list // Verify the configurationNow that the environment is setup, let’s install the project source code and switch to dev branch:
git clone https://github.com/shardeum/shardeum.git
cd server
git switch devOnce you are on the dev branch, install the local node modules to build the project by the following command:
npm ciNow, you can initialize the project using the following command:
npm run prepareShardus is a command line tool from Shardus SDK that makes launching any Shardus protocol powered network easier:
npm install -g shardus
npm update @shardus/archiverYou have two ways to configure your local environment: easy mode or advanced mode.
You have the option to quickly configure your local environment by applying one of the patches located in the /server/ folder, such as:
git apply debug-20-nodes.patchFor instance, debug-20-nodes.patch configures a network with debug settings, requiring 20 nodes to begin processing. These patches are designed to streamline the setup process for specific network configurations, eliminating the need for manual configuration to the following settings.
The default settings included are intended to be used on the live network, so to configure the Shardeum network for local development, there are a few changes that need to be made:
- Configure Debug Mode: Enabling debug mode ensures all network addresses have a designated amount of SHM. Open the
src/config/index.tsfile and set the following configuration settings:
// src/config/index.ts
forceBogonFilteringOn: false,
mode: 'debug'Please note that setting
forceBogonFilteringOnto false is only required when you are running all the nodes locally. By default, it is
set to true for production network that prevents certain IP addresses from joining the network.
- Debug Flag Configuration: Disabling
txBalancePreCheckallows processing without balance checks for debugging purposes. For that, modify the following flags insrc/shardeum/shardeumFlags.tsas follows:
// src/shardeum/shardeumFlags.ts
txBalancePreCheck: false,
StakingEnabled: false- Local Testing: Additionally, for local testing, adjust the following settings. These changes allow nodes to get active in 30 seconds compared to 60 seconds and generate a new block every 3 seconds instead of 6 seconds, enhancing your local testing efficiency.
// src/config/index.ts
cycleDuration: 30,
// src/shardeum/shardeumFlags.ts
blockProductionRate: 3,After completing the above steps, compile again with npm run prepare.
Now we’re ready to create the network from within the Shardeum validator repo:
shardus start 20This command will start a Shardeum network of 20 nodes, 1 archiver server, and 1 monitor server exposed through port number 3000. You can inspect the nodes via the shardus pm2 list command.
For usage instructions and available options for the shardus command-line tool, run shardus --help.
shardus stop && shardus clean && rm -rf instancesThis command will stop the running network, clean up the associated resources, and remove the instances folder from the system.
Click here to install the MetaMask extension on your browser.
- Open MetaMask and click the list of networks at the top, then select "Add Network".
- Add Shardeum automatically or manually:
| Field | Details |
|---|---|
| Network Name | Shardeum Sphinx |
| New RPC URL | http://localhost:8080 |
| Chain ID | 8082 |
| Currency Symbol | SHM |
| Block Explorer URL | http://localhost:6001/ |
A Shardeum validator node does not have an integrated RPC API, instead, we provide an Ethereum compatible JSON-RPC server that can be used to interact with the network, allowing the existing Ethereum tools to use Shardeum seamlessly. To start the JSON-RPC server, clone the repository:
git clone https://github.com/shardeum/json-rpc-server.gitChange directory to json-rpc-server, switch to the dev branch, and install the required dependencies:
cd json-rpc-server
git switch dev
npm installIf you want to modify the chainId or the port number, go to the src/config.ts file:
chainId: 8082,
port: 8080The RPC URL for using Metamask with Remix IDE and for running scripts is http://localhost:port (default: http://localhost:8080).
To run the server, use the command:
npm run startYou now have a fully functioning Shardeum network on your local machine! 🎉
The Shardeum network uses a sophisticated sharding mechanism to ensure scalability and performance. Some key configuration settings include:
sharding: {
nodesPerConsensusGroup: process.env.nodesPerConsensusGroup ? parseInt(process.env.nodesPerConsensusGroup) : 10,
nodesPerEdge: process.env.nodesPerEdge ? parseInt(process.env.nodesPerEdge) : 5,
executeInOneShard: true,
},
stateManager: {
accountBucketSize: 200,
includeBeforeStatesInReceipts: true,
useNewPOQ: true,
forwardToLuckyNodes: false,
removeStuckTxsFromQueue: false,
removeStuckChallengedTXs: false,
}Shardeum provides extensive debugging options to aid developers in troubleshooting and optimizing the network:
debug: {
startInFatalsLogMode: false,
startInErrorLogMode: true,
robustQueryDebug: false,
fakeNetworkDelay: 0,
disableSnapshots: true,
countEndpointStart: -1,
hashedDevAuth: '',
devPublicKeys: {
'a45f9a87e10d6dbd88c141e4fb293f96ab30441cbb77a4b04c577ba18d393505': DevSecurityLevel.Low,
'b51124e6d01e0684ff2b86eac9433d585a17319f15b393c8e4426af19117f704': DevSecurityLevel.Medium,
'c980f4dbdd40a9d334b3815b223e83d27e227892a109413e4bc114e8220bd281': DevSecurityLevel.High,
},
checkAddressFormat: true,
enableCycleRecordDebugTool: false,
enableScopedProfiling: false,
}To maintain network stability and performance, Shardeum implements rate limiting and load detection mechanisms:
rateLimiting: {
limitRate: true,
loadLimit: {
internal: 0.6,
external: 0.6,
txTimeInQueue: 0.6,
queueLength: 0.6,
executeQueueLength: 0.6,
},
},
loadDetection: {
queueLimit: 320,
executeQueueLimit: 160,
desiredTxTime: 15,
highThreshold: 0.5,
lowThreshold: 0.2,
}Contributions are very welcome! See our contribution guide for more information. Everyone interacting in our codebases, issue trackers, and any other form of communication, including chat rooms and mailing lists, is expected to follow our code of conduct so we can all enjoy the effort we put into this project.
This project is licensed under the terms of the MIT license. See the LICENSE file for details.
For any questions or support, please reach out to us at:
- Email: support@shardeum.org
- Twitter: @Shardeum
- Discord: Join our community
