Skip to content

Commit 3bc259d

Browse files
Add declare-from docs (#3729)
<!-- Reference any GitHub issues resolved by this PR --> Closes #3587 **Stack**: - #3729 ⬅ - #3727 - #3726 ## Introduced changes <!-- A brief description of the changes --> - ## Checklist <!-- Make sure all of these are complete --> - [x] Linked relevant issue - [x] Updated relevant documentation - [ ] Added relevant tests - [x] Performed self-review of the code - [x] Added changes to `CHANGELOG.md`
1 parent 7778248 commit 3bc259d

File tree

5 files changed

+139
-0
lines changed

5 files changed

+139
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Possibility to use `#[available_gas]` with unnamed argument. Use named arguments instead, e.g. `#[available_gas(l2_gas: 5)]`.
1919
- The deprecated command `snforge init`. Use `snforge new` to initialize new `Forge` projects
2020

21+
### Cast
22+
23+
#### Added
24+
25+
`sncast declare-from` command to declare a contract by fetching it from a different Starknet instance
26+
2127
## [0.49.0] - 2025-09-03
2228

2329
### Forge

docs/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
* [delete](appendix/sncast/account/delete.md)
135135
* [list](appendix/sncast/account/list.md)
136136
* [declare](appendix/sncast/declare.md)
137+
* [declare-from](appendix/sncast/declare_from.md)
137138
* [deploy](appendix/sncast/deploy.md)
138139
* [invoke](appendix/sncast/invoke.md)
139140
* [call](appendix/sncast/call.md)

docs/src/appendix/sncast.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* [deploy](./sncast/account/deploy.md)
88
* [delete](./sncast/account/delete.md)
99
* [declare](./sncast/declare.md)
10+
* [declare-from](./sncast/declare_from.md)
1011
* [deploy](./sncast/deploy.md)
1112
* [invoke](./sncast/invoke.md)
1213
* [call](./sncast/call.md)
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# `declare`
2+
Declare a contract by fetching it from a different Starknet instance.
3+
4+
## Required Common Arguments — Passed By CLI or Specified in `snfoundry.toml`
5+
6+
* [`account`](./common.md#--account--a-account_name)
7+
8+
## `--class-hash, -c <CLASS_HASH>`
9+
Required.
10+
11+
Class hash of contract declared on a different network.
12+
13+
## `--url, -u <RPC_URL>`
14+
Optional.
15+
16+
Starknet RPC node url address.
17+
18+
Overrides url from `snfoundry.toml`.
19+
20+
## `--network <NETWORK>`
21+
Optional.
22+
23+
Use predefined network with public provider
24+
25+
Possible values: `mainnet`, `sepolia`.
26+
27+
## `--source-url, -u <RPC_URL>`
28+
Optional.
29+
30+
Starknet RPC node url address of the source network where the contract is already declared.
31+
32+
## `--source-network <NETWORK>`
33+
Optional.
34+
35+
Use predefined network with public provider where the contract is already declared.
36+
37+
Possible values: `mainnet`, `sepolia`.
38+
39+
## `--max-fee, -m <MAX_FEE>`
40+
Optional.
41+
42+
Maximum fee for the `declare` denoted in FRI. Must be greater than zero. If provided, it is not possible to use any of the following fee related flags: `--l1-gas`, `--l1-data-price`, `--l2-gas`, `--l2-gas-price`, `--l1-data-gas`, `--l1-data-gas-price`.
43+
44+
## `--l1-gas <L1_GAS>`
45+
Optional.
46+
47+
Maximum L1 gas for the `declare` transaction. When not used, defaults to auto-estimation.
48+
49+
## ` --l1-gas-price <l1_gas_price>`
50+
Optional.
51+
52+
Maximum L1 gas unit price for the `declare` transaction. When not used, defaults to auto-estimation.
53+
54+
## `--l2-gas <L2_GAS>`
55+
Optional.
56+
57+
Maximum L2 gas for the `declare` transaction. When not used, defaults to auto-estimation.
58+
59+
## `--l2-gas-price <L2_GAS_PRICE>`
60+
Optional.
61+
62+
Maximum L2 gas unit price for the `declare` transaction. When not used, defaults to auto-estimation.
63+
64+
## `--l1-data-gas <L1_DATA_GAS>`
65+
Optional.
66+
67+
Maximum L1 data gas for the `declare` transaction. When not used, defaults to auto-estimation.
68+
69+
## `--l1-data-gas-price <l1_data_gas_price>`
70+
Optional.
71+
72+
Maximum L1 data gas unit price for the `declare` transaction. When not used, defaults to auto-estimation.
73+
74+
## `--tip <TIP>`
75+
Optional.
76+
Conflicts with: [`--estimate-tip`](#--estimate-tip-estimate_tip)
77+
78+
Tip for the transaction. Tip for the transaction. When not provided, defaults to 0 unless [`--estimate-tip`](#--estimate-tip-estimate_tip) is used.
79+
80+
## `--estimate-tip <ESTIMATE_TIP>`
81+
Optional.
82+
Conflicts with: [`--tip`](#--tip-tip)
83+
84+
If passed, an estimated tip will be added to pay for the transaction. The tip is estimated based on the current network conditions and added to the transaction fee.
85+
86+
## `--nonce, -n <NONCE>`
87+
Optional.
88+
89+
Nonce for transaction. If not provided, nonce will be set automatically.
90+
91+
## `--block-id, -b <BLOCK_ID>`
92+
Optional.
93+
94+
Block identifier on which class of declared contract should be fetched.
95+
Possible values: `pending`, `latest`, block hash (0x prefixed string), and block number (u64).
96+
`pending` is used as a default value.

docs/src/starknet/declare.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,39 @@ transaction: https://starkscan.co/search/[..]
5353
> 💡 **Info**
5454
> Max fee will be automatically computed if `--max-fee <MAX_FEE>` is not passed.
5555
56+
# Declaring a Contract by Fetching It From a Different Starknet Instance
57+
58+
In some cases, you may need to declare a contract that was already compiled elsewhere and reuse the exact same class hash across multiple networks.
59+
This is especially important for some contracts, e.g. Universal Deployer Contract (UDC), which must preserve the same class hash across mainnet, testnets, and appchains.
60+
61+
Compiling a contract locally with a different Cairo compiler version may result in a different class hash.
62+
63+
To avoid this, you can use the `declare-from` which allows you to declare a contract by providing its class hash and the source network where it is already declared.
64+
65+
## Example
66+
67+
Let's consider a basic contract, which is already declared on Sepolia network.
68+
69+
To declare it on another network, e.g. local devnet, run:
70+
71+
```shell
72+
$ sncast --account my_account \
73+
declare-from \
74+
--class-hash 0x283a4f96ee7de15894d9205a93db7cec648562cfe90db14cb018c039e895e78 \
75+
--source-network sepolia \
76+
--url http://127.0.0.1:5055/rpc
77+
```
78+
79+
<details>
80+
<summary>Output:</summary>
81+
82+
```shell
83+
Success: Declaration completed
84+
85+
Class Hash: 0x283a4f96ee7de15894d9205a93db7cec648562cfe90db14cb018c039e895e78
86+
Transaction Hash: 0x[..]
87+
```
88+
</details>
89+
<br>
90+
5691

0 commit comments

Comments
 (0)