Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Update sncast script #254

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/ch02-05-01-deployment-script.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -21,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

Expand Down Expand Up @@ -70,7 +82,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
Expand Down Expand Up @@ -105,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/.*Class with hash \([^ ]*\).*/\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: //')
Expand Down
120 changes: 119 additions & 1 deletion src/ch02-06-starknet-devnet.md
Original file line number Diff line number Diff line change
@@ -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 <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.