This folder contains what you need to start a Diem node locally with a custom genesis module set, along with some sample Move code and a sample application sending transactions to the local "blockchain" you just started.
.
├── genesis # CLI for building and starting a validator node
├── move/src # Move source code
│ ├── diem # Diem Framework code
│ ├── SampleModule.move # A sample Move module
├── transaction-builder # Auto-generated transaction builders in Rust
- Install Diem dependencies including Rust, Clang, etc, by running the following script in
diem
root directory:
./scripts/dev_setup.sh
- Install
df-cli
insidediem
repo. We use this tool in step 2 to compile Move code:
cargo install --git https://github.com/diem/diem df-cli --branch main
Write some Move modules you wish to include in your custom genesis and put them under ./move/src/modules
,
such as the SampleModule
we have included. This sample module contains a simple script function mint_coin
that
publishes a resource called Coin
as well as a unit test test_mint_coin
that tests this function.
Inside move
folder, run sh compile.sh
to compile the Move code. No output means everything is good.
Running cargo test
inside ./move
runs the unit test with output like this:
running 1 test
Running Move unit tests
[ PASS ] 0x1::SampleModule::test_mint_coin
Test result: OK. Total tests: 1; passed: 1; failed: 0
Inside ./genesis
, run the following command:
RUST_LOG=WARN cargo run -- --node-config-dir <directory_name_that_doesnt_exist>
Add --open-publishing
to the command above if you would like your validator to allow module publishing.
The output of this command should look like this:
Building Move code ... (took 0.545s)
Generating script ABIs ... (took 3.687s)
Generating Rust script builders ... (took 0.383s)
Creating genesis with 39 modules
Running a Diem node with custom modules ...
This code completes the following tasks in order:
- Compiles Move code in
./move/src
, auto-generates ABIs and transaction builders for script functions. - Builds a validator config that includes all the binaries of Move code from previous step in the genesis writeset,
and save this config in the directory specified on the command line (what comes after
--node-config-dir
) - Starts a Diem node with the validator config built in previous step on
http://0.0.0.0:8080
.
If you see this error:
Building Move code ... thread 'main' panicked at 'Automatically building Move code failed.
Need to manually resolve the issue using the CLI', shuffle/genesis/src/lib.rs:75:13
Go back to ./move
folder and recompile by running compile.sh
again.