Skip to content

Commit b761ede

Browse files
author
3alpha
authored
Release v0.7.0 (#891)
1 parent 9ecc7f7 commit b761ede

28 files changed

Lines changed: 1496 additions & 12 deletions

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ members = [
1212
panic = "unwind"
1313

1414
[workspace.package]
15-
authors = ["Mario"]
15+
authors = ["0xSpaceShard"]
1616
edition = "2021"
1717
repository = "https://github.com/0xSpaceShard/starknet-devnet"
1818
license-file = "LICENSE"
@@ -106,9 +106,9 @@ cairo-lang-syntax = "=2.12.3"
106106
cairo-lang-utils = "=2.12.3"
107107

108108
# Inner dependencies
109-
starknet-types = { version = "0.6.1", path = "crates/starknet-devnet-types", package = "starknet-devnet-types" }
110-
starknet-core = { version = "0.6.1", path = "crates/starknet-devnet-core", package = "starknet-devnet-core" }
111-
server = { version = "0.6.1", path = "crates/starknet-devnet-server", package = "starknet-devnet-server" }
109+
starknet-types = { version = "0.7.0", path = "crates/starknet-devnet-types", package = "starknet-devnet-types" }
110+
starknet-core = { version = "0.7.0", path = "crates/starknet-devnet-core", package = "starknet-devnet-core" }
111+
server = { version = "0.7.0", path = "crates/starknet-devnet-server", package = "starknet-devnet-server" }
112112

113113
# Dependabot alerts
114114
zerocopy = "0.8.27"

crates/starknet-devnet-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "starknet-devnet-core"
3-
version = "0.6.1"
3+
version = "0.7.0"
44
edition.workspace = true
55
repository.workspace = true
66
license-file.workspace = true

crates/starknet-devnet-server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "starknet-devnet-server"
3-
version = "0.6.1"
3+
version = "0.7.0"
44
edition = "2021"
55
repository.workspace = true
66
license-file.workspace = true

crates/starknet-devnet-types/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "starknet-devnet-types"
3-
version = "0.6.1"
3+
version = "0.7.0"
44
edition = "2021"
55
description = "Starknet types for the devnet"
66
repository.workspace = true

crates/starknet-devnet/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "starknet-devnet"
3-
version = "0.6.1"
3+
version = "0.7.0"
44
edition = "2021"
55
repository.workspace = true
66
license-file.workspace = true
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Account impersonation
2+
3+
:::info
4+
5+
This page is about account impersonation. To read about account class selection and deployment, click [here](./predeployed).
6+
7+
:::
8+
9+
## Introduction
10+
11+
Devnet allows you to impersonate an account that exists on the Starknet mainnet or testnet. This is achieved by skipping the validation step of transactions for all or some accounts, on a running Devnet via JSON-RPC.
12+
13+
A transaction sent from an impersonated account will not fail with an invalid signature error, which is what happens in the general case of locally absent accounts. For impersonation to work, Devnet needs to [fork](./forking.md) the network that has the desired account.
14+
15+
:::warning Caveat
16+
17+
- Only `INVOKE` and `DECLARE` transactions are supported. `DEPLOY_ACCOUNT` transaction is not supported, but you can create an `INVOKE` transaction to UDC.
18+
- Due to the validation step being skipped, the overall fee of transactions sent with an impersonated account will be lower than regular transactions.
19+
- Trying to send a transaction with an account that **does not** even exist in the origin network returns an error:
20+
- `ContractNotFound` if, during transaction preparation, you do not specify a nonce value, leading to the implicit querying of Devnet for the nonce.
21+
- `InsufficientAccountBalance` or similar if the nonce is supplied in the transaction; this happens because the token balance of a non-existent contract is 0 indeed insufficient.
22+
23+
:::
24+
25+
## Tips
26+
27+
- The impersonated account may have had all or a part of its funds used up on the origin network. You may need to give it more funds via [minting](./balance.md).
28+
- If you're defining a new account in your Starknet client application (starknet.js, starknet.rs, starkli...), you may need to specify a private key for it. Since the signature validation is skipped, you may provide a dummy key.
29+
30+
## API
31+
32+
Account impersonation follows JSON-RPC method specification. Each method returns an empty response:
33+
34+
### devnet_impersonateAccount
35+
36+
Impersonates a specific account address nonexistent in the local state.
37+
38+
```js
39+
{
40+
"jsonrpc": "2.0",
41+
"id": "1",
42+
"method": "devnet_impersonateAccount",
43+
"params": {
44+
"account_address": "0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7"
45+
}
46+
}
47+
```
48+
49+
### devnet_stopImpersonateAccount
50+
51+
Stops the impersonation of an account previously marked for impersonation.
52+
53+
```js
54+
{
55+
"jsonrpc": "2.0",
56+
"id": "1",
57+
"method": "devnet_stopImpersonateAccount",
58+
"params": {
59+
"account_address": "0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7"
60+
}
61+
}
62+
```
63+
64+
### devnet_autoImpersonate
65+
66+
Enables automatic account impersonation. Every account that does not exist in the local state will be impersonated.
67+
68+
```js
69+
{
70+
"jsonrpc": "2.0",
71+
"id": "1",
72+
"method": "devnet_autoImpersonate",
73+
"params": {}
74+
}
75+
```
76+
77+
### devnet_stopAutoImpersonate
78+
79+
Stops the effect of [automatic impersonation](#devnet_autoimpersonate).
80+
81+
```js
82+
{
83+
"jsonrpc": "2.0",
84+
"id": "1",
85+
"method": "devnet_stopAutoImpersonate",
86+
"params": {}
87+
}
88+
```
89+
90+
## Preventing impersonation
91+
92+
If you want to learn about completely preventing impersonation from being activated on your Devnet, click [here](./restrictive.md).
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
sidebar_position: 3
3+
---
4+
5+
# API
6+
7+
## JSON-RPC API
8+
9+
Both Starknet's and Devnet's JSON-RPC API are reachable at `/rpc` and `/`. E.g. if spawning Devnet with default settings, these URLs are functionally equivalent: `http://127.0.0.1:5050/rpc` and `http://127.0.0.1:5050/`. The difference between these two groups of methods is their prefix: `starknet_` (e.g. `starknet_getNonce`) and `devnet_` (e.g. `devnet_mint`).
10+
11+
### Starknet API
12+
13+
Unlike Pythonic Devnet, which also supported Starknet's gateway and feeder gateway API, Devnet in Rust supports [Starknet's JSON-RPC API](https://github.com/starkware-libs/starknet-specs/tree/master/api), including [WebSocket support](#websocket).
14+
15+
Due to how Devnet internally works, the method `starknet_getStorageProof` is not applicable, and thus not supported.
16+
17+
Since JSON-RPC v0.6.0, to find out which JSON-RPC version is supported by which Devnet version, check out the [releases page](https://github.com/0xspaceshard/starknet-devnet/releases).
18+
19+
### Devnet API
20+
21+
Devnet has many additional features available via JSON-RPC. The RPC methods are documented throughout the documentation in their corresponding pages, but are also aggregated [here](https://github.com/0xSpaceShard/starknet-devnet/blob/main/website/static/devnet_api.json).
22+
23+
#### Healthcheck
24+
25+
To check if a Devnet instance is alive, send an HTTP request `GET /is_alive`. If alive, Devnet will reply with a `200 OK` and an appropriate message. This is the only special functionality not provided as part of the JSON-RPC API.
26+
27+
### WebSocket
28+
29+
The whole [Starknet](#starknet-api) and [Devnet](#devnet-api) JSON-RPC API, including [WebSocket subscription methods](https://github.com/starkware-libs/starknet-specs/blob/v0.9.0/api/starknet_ws_api.json) can be accessed via the WebSocket protocol, using text or binary messages. Devnet listens for new WebSocket connections at `ws://<HOST>:<PORT>/ws` (notice the protocol scheme). E.g. using [`wscat`](https://www.npmjs.com/package/wscat) on the same computer where Devnet is spawned at default host and port:
30+
31+
```
32+
$ wscat -c ws://127.0.0.1:5050/ws
33+
Connected (press CTRL+C to quit)
34+
> { "jsonrpc": "2.0", "id": 0, "method": "starknet_subscribeNewHeads" }
35+
< {"id":0,"result":2935616350010920547,"jsonrpc":"2.0"}
36+
```
37+
38+
#### WebSocket persistence
39+
40+
[Restarting](./dump-load-restart#restarting) and [loading](./dump-load-restart#loading) do not affect Devnet's WebSocket connections, but remove all subscriptions.
41+
42+
## Interacting with Devnet in JavaScript and TypeScript
43+
44+
To spawn Devnet and interact with it using the [Devnet API](#devnet-api), you can use [`starknet-devnet-js`](https://github.com/0xSpaceShard/starknet-devnet-js/). This can be especially useful in achieving [L1-L2 communication](./postman.md).
45+
46+
To interact with Devnet using the [Starknet API](#starknet-api), use [starknet.js](https://www.starknetjs.com/).
47+
48+
## Config API
49+
50+
To retrieve the current configuration of Devnet, as specified via [CLI](running/cli.md) and later requests, send a `JSON-RPC` request with method name `devnet_getConfig`. Example response is attached below. It can be interpreted as a JSON mapping of CLI input parameters, both specified and default ones, with some irrelevant parameters omitted. So use `starknet-devnet --help` to better understand the meaning of each value, though keep in mind that some of the parameters have slightly modified names. The exact values may have changed and should not be referenced.
51+
52+
```json
53+
{
54+
"seed": 4063802897,
55+
"total_accounts": 10,
56+
"account_contract_class_hash": "0x61dac032f228abef9c6626f995015233097ae253a7f72d68552db02f2971b8f",
57+
"predeployed_accounts_initial_balance": "1000000000000000000000",
58+
"start_time": null,
59+
"gas_price_wei": 100000000000,
60+
"gas_price_fri": 100000000000,
61+
"data_gas_price_wei": 100000000000,
62+
"data_gas_price_fri": 100000000000,
63+
"l2_gas_price_wei": 100000000000,
64+
"l2_gas_price_fri": 100000000000,
65+
"chain_id": "SN_SEPOLIA",
66+
"dump_on": "exit",
67+
"dump_path": "dump_path.json",
68+
"state_archive": "none",
69+
"fork_config": {
70+
"url": "http://rpc.pathfinder.equilibrium.co/integration-sepolia/rpc/v0_7",
71+
"block_number": 26429
72+
},
73+
"server_config": {
74+
"host": "127.0.0.1",
75+
"port": 5050,
76+
"timeout": 120,
77+
"restricted_methods": null
78+
},
79+
"block_generation": null,
80+
"lite_mode": false,
81+
"eth_erc20_class_hash": "0x046ded64ae2dead6448e247234bab192a9c483644395b66f2155f2614e5804b0",
82+
"strk_erc20_class_hash": "0x046ded64ae2dead6448e247234bab192a9c483644395b66f2155f2614e5804b0"
83+
}
84+
```
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Account balance
2+
3+
Other than using prefunded predeployed accounts, you can also add funds to an account that you deployed yourself.
4+
5+
Separate tokens use separate ERC20 contracts for minting and charging fees. These are the token contracts predeployed by Devnet and the addresses where they are located:
6+
7+
- ETH: `0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7`
8+
- STRK: `0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d`
9+
10+
## Mint token - Local faucet
11+
12+
By sending a `JSON-RPC` request with method name `devnet_mint` for a token, you initiate a transaction on that token's ERC20 contract. The response contains the hash of this transaction, as well as the new balance after minting. The token is specified by providing the unit, and defaults to `FRI` (the unit of `STRK`).
13+
14+
The value of `amount` is in WEI or FRI. The precision is preserved if specifying an integer or a float whose fractional part is zero (e.g. `1000.0`, `1e21`). If the fractional part is non-zero, the amount is truncated to the nearest integer (e.g. `3.9` becomes `3` and `1.23e1` becomes `12`).
15+
16+
```
17+
JSON-RPC
18+
{
19+
"jsonrpc": "2.0",
20+
"id": "1",
21+
"method": "devnet_mint",
22+
"params": {
23+
"address": "0x6e3205f...",
24+
"amount": 500000,
25+
"unit": "WEI" | "FRI"
26+
}
27+
}
28+
```
29+
30+
Result:
31+
32+
```
33+
{
34+
"new_balance": 500000,
35+
"unit": "WEI" | "FRI",
36+
"tx_hash": "0xa24f23..."
37+
}
38+
```
39+
40+
In case of a reverted minting request, an error is returned containing the stringified revert reason and the hex string of the hash of the reverted transaction for further inspection:
41+
42+
```
43+
{
44+
"tx_hash": "0x123..."
45+
"revert_reason": "Something happened"
46+
}
47+
```
48+
49+
## Check balance
50+
51+
Check the balance of an address by sending a `JSON-RPC` request. The address should be a 0x-prefixed hex string; `unit` defaults to `FRI` (the unit of `STRK`) and `block_id` to `latest`.
52+
53+
```
54+
JSON-RPC
55+
{
56+
"jsonrpc": "2.0",
57+
"id": "1",
58+
"method": "devnet_getAccountBalance",
59+
"params": {
60+
"address": "0x6e3205f...",
61+
"unit": "WEI" | "FRI",
62+
"block_id": <BLOCK_ID>
63+
}
64+
}
65+
```

0 commit comments

Comments
 (0)