Skip to content
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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ cairo-lang-syntax = "=2.17.0"
cairo-lang-utils = "=2.17.0"

# Inner dependencies
starknet-types = { version = "0.8.0", path = "crates/starknet-devnet-types", package = "starknet-devnet-types" }
starknet-core = { version = "0.8.0", path = "crates/starknet-devnet-core", package = "starknet-devnet-core" }
server = { version = "0.8.0", path = "crates/starknet-devnet-server", package = "starknet-devnet-server" }
starknet-types = { version = "0.8.1", path = "crates/starknet-devnet-types", package = "starknet-devnet-types" }
starknet-core = { version = "0.8.1", path = "crates/starknet-devnet-core", package = "starknet-devnet-core" }
server = { version = "0.8.1", path = "crates/starknet-devnet-server", package = "starknet-devnet-server" }

# Dependabot alerts
zerocopy = "0.8.27"
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet-devnet-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-devnet-core"
version = "0.8.0"
version = "0.8.1"
edition = { workspace = true }
repository = { workspace = true }
license-file = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet-devnet-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-devnet-server"
version = "0.8.0"
version = "0.8.1"
edition = { workspace = true }
repository = { workspace = true }
license-file = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet-devnet-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-devnet-types"
version = "0.8.0"
version = "0.8.1"
edition = { workspace = true }
description = "Starknet types for the devnet"
repository.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet-devnet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-devnet"
version = "0.8.0"
version = "0.8.1"
edition = { workspace = true }
repository = { workspace = true }
license-file = { workspace = true }
Expand Down
92 changes: 92 additions & 0 deletions website/versioned_docs/version-0.8.1/account-impersonation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Account impersonation

:::info

This page is about account impersonation. To read about account class selection and deployment, click [here](./predeployed).

:::

## Introduction

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.

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.

:::warning Caveat

- Only `INVOKE` and `DECLARE` transactions are supported. `DEPLOY_ACCOUNT` transaction is not supported, but you can create an `INVOKE` transaction to UDC.
- Due to the validation step being skipped, the overall fee of transactions sent with an impersonated account will be lower than regular transactions.
- Trying to send a transaction with an account that **does not** even exist in the origin network returns an error:
- `ContractNotFound` if, during transaction preparation, you do not specify a nonce value, leading to the implicit querying of Devnet for the nonce.
- `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.

:::

## Tips

- 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).
- 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.

## API

Account impersonation follows JSON-RPC method specification. Each method returns an empty response:

### devnet_impersonateAccount

Impersonates a specific account address nonexistent in the local state.

```js
{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_impersonateAccount",
"params": {
"account_address": "0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7"
}
}
```

### devnet_stopImpersonateAccount

Stops the impersonation of an account previously marked for impersonation.

```js
{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_stopImpersonateAccount",
"params": {
"account_address": "0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7"
}
}
```

### devnet_autoImpersonate

Enables automatic account impersonation. Every account that does not exist in the local state will be impersonated.

```js
{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_autoImpersonate",
"params": {}
}
```

### devnet_stopAutoImpersonate

Stops the effect of [automatic impersonation](#devnet_autoimpersonate).

```js
{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_stopAutoImpersonate",
"params": {}
}
```

## Preventing impersonation

If you want to learn about completely preventing impersonation from being activated on your Devnet, click [here](./restrictive.md).
86 changes: 86 additions & 0 deletions website/versioned_docs/version-0.8.1/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
sidebar_position: 3
---

# API

## JSON-RPC API

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`).

### Starknet API

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).

Due to how Devnet internally works, the method `starknet_getStorageProof` is not applicable, and thus not supported.

Devnet also provides a proof-related extension method `starknet_proveTransaction`. For supported modes, behavior, and usage examples, check [Transaction proofs and proof modes](./proofs).

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).

### Devnet API

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).

#### Healthcheck

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.

### WebSocket

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:

```
$ wscat -c ws://127.0.0.1:5050/ws
Connected (press CTRL+C to quit)
> { "jsonrpc": "2.0", "id": 0, "method": "starknet_subscribeNewHeads" }
< {"id":0,"result":2935616350010920547,"jsonrpc":"2.0"}
```

#### WebSocket persistence

[Restarting](./dump-load-restart#restarting) and [loading](./dump-load-restart#loading) do not affect Devnet's WebSocket connections, but remove all subscriptions.

## Interacting with Devnet in JavaScript and TypeScript

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).

To interact with Devnet using the [Starknet API](#starknet-api), use [starknet.js](https://www.starknetjs.com/).

## Config API

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.

```json
{
"seed": 4063802897,
"total_accounts": 10,
"account_contract_class_hash": "0x61dac032f228abef9c6626f995015233097ae253a7f72d68552db02f2971b8f",
"predeployed_accounts_initial_balance": "1000000000000000000000",
"start_time": null,
"gas_price_wei": 100000000000,
"gas_price_fri": 100000000000,
"data_gas_price_wei": 100000000000,
"data_gas_price_fri": 100000000000,
"l2_gas_price_wei": 100000000000,
"l2_gas_price_fri": 100000000000,
"chain_id": "SN_SEPOLIA",
"dump_on": "exit",
"dump_path": "dump_path.json",
"state_archive": "none",
"fork_config": {
"url": "http://rpc.pathfinder.equilibrium.co/integration-sepolia/rpc/v0_7",
"block_number": 26429
},
"server_config": {
"host": "127.0.0.1",
"port": 5050,
"timeout": 120,
"restricted_methods": null
},
"block_generation": null,
"lite_mode": false,
"eth_erc20_class_hash": "0x046ded64ae2dead6448e247234bab192a9c483644395b66f2155f2614e5804b0",
"strk_erc20_class_hash": "0x046ded64ae2dead6448e247234bab192a9c483644395b66f2155f2614e5804b0"
}
```
65 changes: 65 additions & 0 deletions website/versioned_docs/version-0.8.1/balance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Account balance

Other than using prefunded predeployed accounts, you can also add funds to an account that you deployed yourself.

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:

- ETH: `0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7`
- STRK: `0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d`

## Mint token - Local faucet

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`).

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`).

```
JSON-RPC
{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_mint",
"params": {
"address": "0x6e3205f...",
"amount": 500000,
"unit": "WEI" | "FRI"
}
}
```

Result:

```
{
"new_balance": 500000,
"unit": "WEI" | "FRI",
"tx_hash": "0xa24f23..."
}
```

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:

```
{
"tx_hash": "0x123..."
"revert_reason": "Something happened"
}
```

## Check balance

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`.

```
JSON-RPC
{
"jsonrpc": "2.0",
"id": "1",
"method": "devnet_getAccountBalance",
"params": {
"address": "0x6e3205f...",
"unit": "WEI" | "FRI",
"block_id": <BLOCK_ID>
}
}
```
Loading
Loading