From 4c3537059973e77d613d90978983ff1e3840ca83 Mon Sep 17 00:00:00 2001 From: Dalmas Ogembo Date: Tue, 7 Nov 2023 16:59:10 +0300 Subject: [PATCH 1/4] Add starknet devnet rs docs --- src/ch02-06-starknet-devnet.md | 120 ++++++++++++++++++++++++++++++++- 1 file changed, 119 insertions(+), 1 deletion(-) diff --git a/src/ch02-06-starknet-devnet.md b/src/ch02-06-starknet-devnet.md index 569835792..54ffbddcf 100644 --- a/src/ch02-06-starknet-devnet.md +++ b/src/ch02-06-starknet-devnet.md @@ -1 +1,119 @@ -# Starknet Devnet 🚧 +# Starknet Devnet Rust + +Starknet Devnet Rust is devnet in rust similar to the [`pythonic devnet`](https://0xspaceshard.github.io/starknet-devnet/docs/intro). + +## Installation + +There are two ways to install `starknet devnet rs`. You can either use `docker` or clone the repository and `cargo run`. + +### Using docker + +To use docker, use the procedures highlighted [here](https://github.com/0xSpaceShard/starknet-devnet-rs#readme) + +### Using manual procedure (Cloning the repo) + +Prerequisites: + +- [Rust](https://www.rust-lang.org/tools/install) + +Procedure + +1. Create a folder where you want to place it. + +2. Then run this command + +```shell +git clone git@github.com:0xSpaceShard/starknet-devnet-rs.git +``` + +## Running + +To run starknet devnet rs after installation run + +```rust +cargo run +``` + +Successfull Result + +```shell +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 + +1. Using a seed + +When you run starknet devnet it gives you a `Seed to replicate this account sequence` meaning you can use the given seed to get the accounts you have used previously making your work easier when using other tools like [`sncast`](https://book.starknet.io/ch02-12-foundry-cast.html) or `starkli` to interact with your contract because you are not going to change the accounts. + +To load the old accounts based on a given `seed` run + +```shell +cargo run -- --seed +``` + +Example + +```shell +cargo run -- --seed 912753742 +``` + +2. Dumping and loading data + +Dumping and loading data will help you to continue working from where you left off. + +- To `dump` use the following command + +Dumping can be done on `exit` or `transaction`. For our case we have done it on exit. + +I have done the dumping into a given `directory` remember to have the directory but not the file. + +```shell +cargo run -- --dump-on exit --dump-path ./dumps/contract_1 +``` + +- To `load` use the following command and pass in the seed otherwise you will get an error `low account balance`. + +On loading, have both the directory and the file existing, the file was automatically created by the `dump` command. + +```shell +cargo run -- --dump-path ./dumps/contract_1 --seed 912753742 +``` + +> > For more options check [here](https://0xspaceshard.github.io/starknet-devnet/docs/guide/run) though this is the `pythonic devnet`. Only difference is before the first flag have two extra dashes ie `cargo run -- --port 5006` or `cargo run -- -- dump-on exit ...`. The rest of the flags can be passed in normally. + +#### Cross-version disclaimer + +Dumping and loading is not guaranteed to work cross-version. I.e. if you dumped one version of Devnet, do not expect it to be loadable with a different version. + +### Minting + +You can mint tokens to an address or a new address using the command below + +```shell +curl -d '{"amount":8646000000000, "address":"0x6e...eadf"}' -H "Content-Type: application/json" -X POST http://localhost:5050/mint +``` + +> All commands that work in the [`sncast section`](https://book.starknet.io/ch02-12-foundry-cast.html) and `starkli` work here as well. + +## Conclusion + +Rust Devnet is faster starting from powering on to handling transactions as compared to pythonic devnet making testing locally much smoother. From 89c02dbef2ebd4771d3b62f411d1a0fd6921de1c Mon Sep 17 00:00:00 2001 From: Dalmas Ogembo Date: Mon, 13 Nov 2023 02:46:20 +0300 Subject: [PATCH 2/4] Update sncast script: update the regex on declaration output to read class hash --- src/ch02-05-01-deployment-script.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ch02-05-01-deployment-script.md b/src/ch02-05-01-deployment-script.md index e97f1fabe..32a54c3d8 100644 --- a/src/ch02-05-01-deployment-script.md +++ b/src/ch02-05-01-deployment-script.md @@ -6,6 +6,16 @@ Disclaimer: This is an example. Use it as a foundation for your own work, adjust ## Setup +#### This script supports the following versions or above + +```txt +scarb 2.3.0 (f306f9a91 2023-10-23) +cairo: 2.3.0 (https://crates.io/crates/cairo-lang-compiler/2.3.0) +sierra: 1.3.0 +snforge 0.10.1 +sncast 0.10.1 +``` + ### 1. Prepare the Script File - In your project's root folder, create a file named **`script.sh`**. This will house the script. @@ -105,7 +115,7 @@ if [ "$FAILED_TESTS" != "true" ]; then if echo "$declaration_output" | grep -q "error: Class with hash"; then echo "Class hash already declared." - CLASS_HASH=$(echo "$declaration_output" | sed -n 's/.*Class with hash \([^ ]*\).*/\1/p') + CLASS_HASH=$(echo "$declaration_output" | sed -n 's/.*StarkFelt("\(.*\)").*/\1/p') else echo "New class hash declaration." CLASS_HASH=$(echo "$declaration_output" | grep -o 'class_hash: 0x[^ ]*' | sed 's/class_hash: //') From ba3729eebcfe619e4b7974c2ef8894ffa572c4cc Mon Sep 17 00:00:00 2001 From: Dalmas Ogembo Date: Mon, 13 Nov 2023 18:26:23 +0300 Subject: [PATCH 3/4] Update snforge command to snforge test for proper testing --- src/ch02-05-01-deployment-script.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch02-05-01-deployment-script.md b/src/ch02-05-01-deployment-script.md index 32a54c3d8..5e7f5e30b 100644 --- a/src/ch02-05-01-deployment-script.md +++ b/src/ch02-05-01-deployment-script.md @@ -80,7 +80,7 @@ EOF # Step 3: Run contract tests echo -e "\nTesting the contract..." -testing_result=$(snforge 2>&1) +testing_result=$(snforge test 2>&1) if echo "$testing_result" | grep -q "Failure"; then echo -e "Tests failed!\n" snforge From 1ac3c86baa2b8f657fc44556f20f95db93aa2854 Mon Sep 17 00:00:00 2001 From: Dalmas Ogembo Date: Wed, 15 Nov 2023 19:16:30 +0300 Subject: [PATCH 4/4] Update the script to include different lines for reading an already declared classhash for devnet rs and devnet python --- src/ch02-05-01-deployment-script.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ch02-05-01-deployment-script.md b/src/ch02-05-01-deployment-script.md index 5e7f5e30b..280726620 100644 --- a/src/ch02-05-01-deployment-script.md +++ b/src/ch02-05-01-deployment-script.md @@ -31,6 +31,8 @@ Below is the content for `script.sh`. It adheres to best practices for clarity, **Security Note**: Using environment variables is safer than hardcoding private keys in your scripts, but they're still accessible to any process on your machine and could potentially be leaked in logs or error messages. +On step 5 _declaring_, Uncomment according to local devnet you are using either the rust node or python node for declaration to work as expected. + ```sh #!/usr/bin/env bash @@ -115,7 +117,8 @@ if [ "$FAILED_TESTS" != "true" ]; then if echo "$declaration_output" | grep -q "error: Class with hash"; then echo "Class hash already declared." - CLASS_HASH=$(echo "$declaration_output" | sed -n 's/.*StarkFelt("\(.*\)").*/\1/p') + CLASS_HASH=$(echo "$declaration_output" | sed -n 's/.*Class with hash \([^ ]*\).*/\1/p') ## Uncomment this for devnet python + # CLASS_HASH=$(echo "$declaration_output" | sed -n 's/.*StarkFelt("\(.*\)").*/\1/p') ## Uncomment this for devnet rust else echo "New class hash declaration." CLASS_HASH=$(echo "$declaration_output" | grep -o 'class_hash: 0x[^ ]*' | sed 's/class_hash: //')