Quentin@gfusee33
Just released a new #MultiversX dev tool: mx-chain-simulator-interface-rs ⚒️
This tool is a Rust crate that allows you to create a local blockchain in the simulation mode in seconds. It is a no-brainer tool that does all the work for you 🔥
Plan of the thread:
1️⃣ The chain simulator: what is it?
2️⃣ Features of the Rust tool
3️⃣ How to use
This tool is fully open-sourced, here is where you can see the code: github.com/gfusee/mx-chai…
1️⃣ The chain simulator: what is it?
MultiversX nodes are programs that can be run in several modes. A staking provider runs its nodes in the validator mode, while developers, who only want to interact with the blockchain, can run a node in an observer mode
There is another mode we rarely heard about, the simulator mode. When a node is run as a simulator, it will act as a validator for a local blockchain which runs inside a single computer. However, this local blockchain is pretty different from a classic local blockchain create through mxpy or xNetwork, which runs isolated nodes in the validator mode. The simulator mode gives the blockchain some superpowers:
- Blocks can be generated at will, you can choose to generate 1 block per second while maintaining the block’s duration of 6 seconds; you can literally speed up the time
- Signatures could be bypassed, it means you can do transactions in the behalf of any wallet
- You can set EGLD & ESDT balances + any storage value for any wallet
In other terms, on a simulator blockchain you can do anything you want! For developers this is the perfect environment to perform some tests
The MultiversX team created a CLI to create easily such a local blockchain. My tool is a Rust wrapper around this CLI to allow developers to create them directly from their Rust programs, in a completely typed and safe manner!
2️⃣ Features of the Rust tool
mx-chain-simulator-interface-rs is a Rust crate bringing the following features:
- All binaries are embedded. No need to install or compile anything, the crate is smart and while act accordingly to your CPU’s architecture. Currently, Linux AMD64, macOS AMD64 and macOS ARM64 are compatible. Linux ARM64 compatibility will come with the 1.7 version of the protocol
- Everything is typed. No need to worry about anything, just enjoy the wonderful Rust type system
No configuration. You don’t have to handle any TOML or JSON config, neither parsing CLI flags, the crate does this for you
- Fully customizable. No configuration but you can change with a single line any parameter you want; it could the number of shards, the server port for the gateway or anything else
- Async compatible. The crate has been thought to be used with tokio
- Easy interactions. Once the blockchain is running you can make use of the new superpowers you have directly from your Rust code
- Errors are fully typed. Each possible error can be caught by the developer, moreover all the errors are compatible with the crate anyhow, making error handling even more easier
- Smart processes. The crate automatically kills the network when the simulator variable goes out of its scope. You can listen to the process stdout in a parallel thread without causing any memory leak
3️⃣ How to use
Let me show you the magic 🪄
First you need to import the crate in your Cargo.toml like any other crate:
mx-chain-simulator-interface-rs = “0.0.1”
Then here’s the minimal code to run a localnet in the simulator mode:
Voilà! This code is sufficient to launch a local blockchain in simulator mode, with a fully working gateway 🔥
What did you say? You want to have 2 shards? Right:
You want to generate 17 blocks immediately following the blockchain genesis? Let’s do it:
Finally, you don’t need to generate the blocks. Instead, you need to set the EGLD balance to 10 EGLD for erd1n7ed3f6rkqvwkpfevulvhyl4hskx2vqyleed5lqfq9jp2csfw8esg88f5g? Easy:
Conclusion
I hope my thread was clear! I want to thank the MultiversX team for the super intuitive CLI upon which my tool is based: github.com/multiversx/mx-…
If you liked this thread, feel free to share it & give a follow, it supports me a lot 🫶
PS: Imagine this wrapper integrated into NovaX and xNetwork? 👀