Starknet Devnet

Starknet Devnet is a development network (devnet) implemented in Rust, similar to the Python-based starknet-devnet.

Installation

starknet devnet rs can be installed in two ways: using Docker or manually by cloning the repository and running it with Cargo.

Using Docker

To install using Docker, follow the instructions provided here.

Manual Installation (Cloning the Repo)

Prerequisites:

Procedure:

  1. Create a new folder for the project.
  2. Clone the repository:
git clone git@github.com:0xSpaceShard/starknet-devnet-rs.git

Running

After installation, run Starknet Devnet with the following command:

cargo run

On successful execution, you'll see outputs like predeployed contract addresses, account information, and seed details.

Predeployed FeeToken
Address: 0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7
Class Hash: 0x6A22BF63C7BC07EFFA39A25DFBD21523D211DB0100A0AFD054D172B81840EAF

Predeployed UDC
Address: 0x41A78E741E5AF2FEC34B695679BC6891742439F7AFB8484ECD7766661AD02BF
Class Hash: 0x7B3E05F48F0C69E4A65CE5E076A66271A527AFF2C34CE1083EC6E1526997A69

| Account address |  0x1d11***221c
| Private key     |  0xb7***8ee25
| Public key      |  0x5d46***76bf10

.
.
.

Predeployed accounts using class with hash: 0x4d07e40e93398ed3c76981e72dd1fd22557a78ce36c0515f679e27f0bb5bc5f
Initial balance of each account: 1000000000000000000000 WEI
Seed to replicate this account sequence: 912753742

Running Options

Using a Seed

The Starknet devnet provides a Seed to replicate this account sequence feature. This allows you to use a specific seed to access previously used accounts. This functionality is particularly useful when employing tools like sncast or starkli for contract interactions, as it eliminates the need to change account information.

To load old accounts using a specific seed, execute the following command:

cargo run -- --seed <SEED>

Example (add any number you prefer):

cargo run -- --seed 912753742

Dumping and Loading Data

The process of dumping and loading data facilitates resuming work from where you left off.

  • Dumping Data:
  • Data can be dumped either on exit or after a transaction.
  • In this example, dumping is done on exit into a specified directory. Ensure the directory exists, but not the file.
cargo run -- --dump-on exit --dump-path ./dumps/contract_1
  • Loading Data:
  • To load data, use the command below. Note that both the directory and the file created by the dump command must exist. Also, pass in the seed to avoid issues like 'low account balance'.
cargo run -- --dump-path ./dumps/contract_1 --seed 912753742

For additional options and configurations, refer to the Starknet Devnet documentation. This guide primarily covers the Python-based devnet. However, the main difference for the Rust version is the syntax for flags. For example, use cargo run -- --port 5006 or cargo run -- --dump-on exit ... for the Rust Devnet. Other flags can be used in the standard format.

Cross-Version Disclaimer

Be aware that the dumping and loading functionality might not be compatible across different versions of the Devnet. In other words, data dumped from one version of Devnet may not be loadable with another version.

Minting Tokens

To mint tokens, either to an existing address or a new one, use the following command:

curl -d '{"amount":8646000000000, "address":"0x6e...eadf"}' -H "Content-Type: application/json" -X POST http://localhost:5050/mint

Commands compatible with the sncast and starkli subchapters are also applicable in the Rust Devnet.

Next

In the next subchapter we will use the sncast tool to interact with the Starknet Devnet in a real world example.