create-stylus 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/package.json +1 -1
  2. package/templates/base/.gitignore.template.mjs +2 -2
  3. package/templates/base/dist/cli.js +683 -0
  4. package/templates/base/dist/cli.js.map +1 -0
  5. package/templates/base/package.json +1 -0
  6. package/templates/base/packages/nextjs/.gitignore.template.mjs +3 -3
  7. package/templates/base/packages/nextjs/scaffold.config.ts +2 -2
  8. package/templates/base/packages/stylus/.env.example +5 -2
  9. package/templates/base/packages/stylus/.gitignore.template.mjs +3 -3
  10. package/templates/base/packages/stylus/package.json +0 -1
  11. package/templates/base/packages/stylus/scripts/deploy.ts +29 -12
  12. package/templates/base/packages/stylus/scripts/deploy_contract.ts +34 -43
  13. package/templates/base/packages/stylus/scripts/deploy_wrapper.ts +4 -44
  14. package/templates/base/packages/stylus/scripts/export_abi.ts +13 -13
  15. package/templates/base/packages/stylus/scripts/utils/command.ts +18 -31
  16. package/templates/base/packages/stylus/scripts/utils/contract.ts +23 -14
  17. package/templates/base/packages/stylus/scripts/utils/deployment.ts +169 -45
  18. package/templates/base/packages/stylus/scripts/utils/network.ts +27 -7
  19. package/templates/base/packages/stylus/scripts/utils/type.ts +13 -10
  20. package/templates/base/packages/stylus/your-contract/Cargo.lock +35 -18
  21. package/templates/base/packages/stylus/your-contract/Cargo.toml +3 -1
  22. package/templates/base/packages/stylus/your-contract/src/lib.rs +51 -21
  23. package/templates/base/readme.md +208 -43
  24. package/templates/base/yarn.lock +1 -2
  25. package/templates/base/packages/stylus/README.md +0 -263
  26. package/templates/base/packages/stylus/header.png +0 -0
  27. package/templates/base/packages/stylus/scripts/deploy_all_contracts.ts +0 -59
@@ -1,4 +1,4 @@
1
- # 🏗 scaffold-stylus
1
+ # 🏗 scaffold-stylus
2
2
 
3
3
  <h4 align="center">
4
4
  <a href="https://arb-stylus.github.io/scaffold-stylus-docs/">Documentation</a> |
@@ -10,8 +10,8 @@
10
10
  ⚙️ Built using Rust, NextJS, RainbowKit, Stylus, Wagmi, Viem, and TypeScript.
11
11
 
12
12
  - ✅ **Contract Hot Reload**: Your frontend auto-adapts to your smart contract as you edit it.
13
- - 🪝 **[Custom hooks]()**: Collection of React hooks wrapped around [wagmi](https://wagmi.sh/) to simplify interactions with smart contracts with TypeScript autocompletion.
14
- - 🧱 [**Components**](): Collection of common web3 components to quickly build your frontend.
13
+ - 🪝 **[Custom hooks](https://arb-stylus.github.io/scaffold-stylus-docs/components)**: Collection of React hooks wrapped around [wagmi](https://wagmi.sh/) to simplify interactions with smart contracts with TypeScript autocompletion.
14
+ - 🧱 [**Components**](https://arb-stylus.github.io/scaffold-stylus-docs/hooks): Collection of common web3 components to quickly build your frontend.
15
15
  - 🔥 **Burner Wallet & Local Faucet**: Quickly test your application with a burner wallet and local faucet.
16
16
  - 🔐 **Integration with Wallet Providers**: Connect to different wallet providers and interact with the Arbitrum network.
17
17
 
@@ -30,13 +30,11 @@ Before you begin, you need to install the following tools:
30
30
 
31
31
  ## Quickstart
32
32
 
33
- [Video Demo](https://app.screencastify.com/watch/9GYnnO0Fqq9QOjYRjQg0)
34
-
35
33
  To get started with Scaffold-Stylus, follow the steps below:
36
34
 
37
- 1. Clone this repo & install dependencies
35
+ ### 1. Clone this repo & install dependencies
38
36
 
39
- ```
37
+ ```bash
40
38
  git clone https://github.com/Arb-Stylus/scaffold-stylus.git
41
39
  cd scaffold-stylus
42
40
  yarn install
@@ -44,34 +42,72 @@ yarn install
44
42
  git submodule update --init --recursive
45
43
  ```
46
44
 
47
- 2. Run a local network in the first terminal:
45
+ ### 2. Install Stylus tools
48
46
 
47
+ Install [Rust](https://www.rust-lang.org/tools/install), and then install the Stylus CLI tool with Cargo:
48
+
49
+ ```bash
50
+ cargo install --force cargo-stylus cargo-stylus-check
49
51
  ```
52
+
53
+ **Prerequisite:**
54
+
55
+ - `cargo-stylus` version `^0.6.1`
56
+ - `rustc` version match with `packages/stylus/your-contract/rust-toolchain.toml`
57
+
58
+ Set default `toolchain` match `rust-toolchain.toml` and add the `wasm32-unknown-unknown` build target to your Rust compiler:
59
+
60
+ ```bash
61
+ rustup default 1.87
62
+ rustup target add wasm32-unknown-unknown --toolchain 1.87
63
+ ```
64
+
65
+ You should now have it available as a Cargo subcommand:
66
+
67
+ ```bash
68
+ cargo stylus --help
69
+ ```
70
+
71
+ ### 3. Run a local network
72
+
73
+ In your first terminal:
74
+
75
+ ```bash
50
76
  yarn chain
51
77
  ```
52
78
 
53
79
  This command starts a local Stylus-compatible network using the Nitro dev node script (`./nitro-devnode/run-dev-node.sh`). The network runs on your local machine and can be used for testing and development. You can customize the Nitro dev node configuration in the `nitro-devnode` submodule.
54
80
 
55
- 3. On a second terminal, deploy the test contract:
81
+ ### 4. Deploy the test contract
56
82
 
57
- ```
83
+ In your second terminal:
84
+
85
+ ```bash
58
86
  yarn deploy
59
87
  ```
60
88
 
61
- This command deploys a test smart contract to the local network. The contract is located in `packages/stylus/your-contract/src` and can be modified to suit your needs. The `yarn deploy` command uses the deploy script located in `packages/stylus/scripts` to deploy the contract to the network. You can also customize the deploy script.
89
+ This command deploys a test smart contract to the local network. The contract is located in `packages/stylus/your-contract/src` and can be modified to suit your needs. The `yarn deploy` command uses the deploy script located in `packages/stylus/scripts` to deploy the contract to the network. You can also customize the deploy script .
62
90
 
63
- 4. On a third terminal, start your NextJS app:
91
+ ### 5. Start your NextJS app
64
92
 
65
- ```
93
+ In your third terminal:
94
+
95
+ ```bash
66
96
  yarn start
67
97
  ```
68
98
 
69
- Visit your app at: `http://localhost:3000`. You can interact with your smart contract using the `Debug Contracts` page. You can tweak the app config in `packages/nextjs/scaffold.config.ts`.
99
+ Visit your app at: `http://localhost:3000`. You can interact with your smart contract using the **Debug Contracts** page, which provides a user-friendly interface for testing your contract's functions and viewing its state.
100
+
101
+ ### 6. Test your smart contract
70
102
 
71
- Run smart contract tests with `yarn stylus:test`
103
+ ```bash
104
+ yarn stylus:test
105
+ ```
106
+
107
+ ## Development Workflow
72
108
 
73
109
  - Edit your smart contract `lib.rs` in `packages/stylus/your-contract/src`
74
- - Edit your frontend in `packages/nextjs/pages`
110
+ - Edit your frontend in `packages/nextjs/app`
75
111
  - Edit your deployment scripts in `packages/stylus/scripts`
76
112
 
77
113
  ## Create Your Own Contract
@@ -82,7 +118,7 @@ Scaffold-Stylus enables you to create and deploy multiple contracts within a sin
82
118
 
83
119
  Use the following command to create a new contract and customize it as needed:
84
120
 
85
- ```
121
+ ```bash
86
122
  yarn new-module <contract-name>
87
123
  ```
88
124
 
@@ -90,39 +126,18 @@ The generated contract will be located in `packages/stylus/<contract-name>`.
90
126
 
91
127
  ### Step 2: Deploy Your Contract
92
128
 
93
- Deploy your contract using one of the following methods:
94
-
95
- #### Method A: Deploy with Script (Recommended)
96
-
97
- ```
98
- yarn deploy
129
+ ```bash
130
+ yarn deploy [...options]
99
131
  ```
100
132
 
101
133
  This command runs the `deploy.ts` script located in `packages/stylus/scripts`. You can customize this script with your deployment logic.
102
134
 
103
- #### Method B: Deploy Single Contract Directly
104
-
105
- If you prefer not to write a deployment script, you can deploy a single contract directly:
106
-
107
- ```
108
- yarn deploy --contract <contractFolder> [...options]
109
- ```
110
-
111
135
  **Available Options:**
112
136
 
113
- - `--name <contractName>`: Deploy your contract with a custom name (default is the contract folder name)
114
137
  - `--network <network>`: Specify which network to deploy to
115
138
  - `--estimate-gas`: Only perform gas estimation without deploying
116
139
  - `--max-fee=<maxFee>`: Set maximum fee per gas in gwei
117
140
 
118
- #### Method C: Deploy All Contracts
119
-
120
- Deploy all contracts in your project with a single command:
121
-
122
- ```
123
- yarn deploy --all [...options]
124
- ```
125
-
126
141
  **Note:** Deployment information is automatically saved in `packages/stylus/deployments` by default.
127
142
 
128
143
  ## Deploying to Other Networks
@@ -139,6 +154,8 @@ To deploy your contracts to other networks (other than the default local Nitro d
139
154
  RPC_URL_SEPOLIA=https://your-network-rpc-url
140
155
  ```
141
156
 
157
+ **Note:** If RPC URL is not provided, system will use default public RPC URL from that network
158
+
142
159
  2. **Set the Private Key**
143
160
 
144
161
  For real deployments, you must provide your own wallet's private key. Set the `PRIVATE_KEY_<network>` environment variable:
@@ -149,7 +166,15 @@ To deploy your contracts to other networks (other than the default local Nitro d
149
166
 
150
167
  **Security Note:** A development key is used by default when running the Nitro dev node locally, but for external deployments, you must provide your own private key.
151
168
 
152
- 3. **Update Frontend Configuration**
169
+ 3. **Set the Account Address**
170
+
171
+ Set the `ACCOUNT_ADDRESS_<network>`
172
+
173
+ ```env
174
+ ACCOUNT_ADDRESS_SEPOLIA=your_account_address_here
175
+ ```
176
+
177
+ 4. **Update Frontend Configuration**
153
178
 
154
179
  Open `packages/nextjs/scaffold.config.ts` and update the `targetNetworks` array to include your target chain. This ensures your frontend connects to the correct network and generates the proper ABI in `deployedContracts.ts`:
155
180
 
@@ -159,21 +184,161 @@ To deploy your contracts to other networks (other than the default local Nitro d
159
184
  targetNetworks: [chains.arbitrumSepolia],
160
185
  ```
161
186
 
187
+ ### Available Networks
188
+
189
+ This template supports Arbitrum networks only. You can test which networks are available and their RPC URLs:
190
+
191
+ ```bash
192
+ yarn test:networks
193
+ ```
194
+
195
+ This will show you all supported networks and their corresponding RPC endpoints.
196
+
162
197
  ### Deploy to Other Network
163
198
 
164
199
  Once configured, deploy to your target network:
165
200
 
166
- ```
201
+ ```bash
167
202
  yarn deploy --network <network>
168
203
  ```
169
204
 
170
205
  **Important Security Notes:**
171
206
 
172
207
  - The values in `.env.example` provide a template for required environment variables
173
-
174
208
  - **Always keep your private key secure and never commit it to version control**
175
209
  - Consider using environment variable management tools for production deployments
176
210
 
211
+ ## Verify your contract
212
+
213
+ #### Prerequisites
214
+
215
+ Your contract must meet Arbiscan's verification requirements:
216
+
217
+ - No external libraries
218
+ - No constructor arguments
219
+ - No custom optimization settings
220
+ - No specific compiler version requirements
221
+
222
+ ### Local Verification
223
+
224
+ Make sure your constructor does not contain any args
225
+
226
+ ```rs
227
+ pub fn constructor(&mut self)
228
+ ```
229
+
230
+ The scaffold includes built-in local verification to ensure your Stylus contract deployments are reproducible. To enable verification during deployment, set `verify: true` in your deployment script:
231
+
232
+ ```ts
233
+ await deployStylusContract({
234
+ contract: "your-contract",
235
+ verify: true,
236
+ ...deployOptions,
237
+ });
238
+ ```
239
+
240
+ This runs `cargo stylus verify` locally after deployment, which:
241
+
242
+ - Verifies that the deployed bytecode matches your source code
243
+ - Ensures reproducibility across different environments
244
+ - Validates the deployment transaction
245
+
246
+ ### Arbiscan Verification
247
+
248
+ For public verification on Arbiscan, follow these steps:
249
+
250
+ #### Steps
251
+
252
+ 1. **Create a dedicated repository** containing only your contract source code
253
+ 2. **Navigate to Arbiscan**:
254
+ - Go to [Arbiscan Verify Contract](https://arbiscan.io/verifyContract)
255
+ - Enter your deployed contract address
256
+ 3. **Follow the verification process**:
257
+ - Select "Solidity (Standard-Json-Input)" as the compiler type
258
+ - Enter your contract source code (github link)
259
+ - Provide any constructor arguments if applicable
260
+ - Submit for verification
261
+
262
+ Check official document for detail instructions: https://docs.arbitrum.io/stylus/how-tos/verifying-contracts-arbiscan
263
+
264
+ > **Note**: Arbiscan verification for Stylus contracts is still evolving. If you encounter issues, consider using the local verification method or check Arbiscan's latest documentation for Stylus-specific instructions.
265
+
266
+ ### 🛠️ Troubleshooting Common Issues
267
+
268
+ #### 1. `stylus` Not Recognized
269
+
270
+ If you encounter an error stating that `stylus` is not recognized as an external or internal command, run the following command in your terminal:
271
+
272
+ ```bash
273
+ sudo apt-get update && sudo apt-get install -y pkg-config libssl-dev
274
+ ```
275
+
276
+ After that, check if `stylus` is installed by running:
277
+
278
+ ```bash
279
+ cargo stylus --version
280
+ ```
281
+
282
+ If the version is displayed, `stylus` has been successfully installed and the path is correctly set.
283
+
284
+ #### 2. ABI Not Generated
285
+
286
+ If you face issues with the ABI not being generated, you can try one of the following solutions:
287
+
288
+ - **Restart Docker Node**: Pause and restart the Docker node and the local setup of the project. You can do this by deleting all ongoing running containers and then restarting the local terminal using:
289
+ ```bash
290
+ yarn run dev
291
+ ```
292
+ - **Modify the Script**: In the `run-dev-node.sh` script, replace the line:
293
+
294
+ ```bash
295
+ cargo stylus export-abi
296
+ ```
297
+
298
+ with:
299
+
300
+ ```bash
301
+ cargo run --manifest-path=Cargo.toml --features export-abi
302
+ ```
303
+
304
+ - **Access Denied Issue**: If you encounter an access denied permission error during ABI generation, run the following command and then execute the script again:
305
+ ```bash
306
+ sudo chown -R $USER:$USER target
307
+ ```
308
+
309
+ #### 3. 🚨 Fixing Line Endings and Running Shell Scripts in WSL
310
+
311
+ > ⚠️ This guide provides step-by-step instructions to resolve the Command not found error caused by CRLF line endings in shell scripts when running in a WSL environment.
312
+
313
+ Shell scripts created in Windows often have `CRLF` line endings, which cause issues in Unix-like environments such as WSL. To fix this:
314
+
315
+ **Using `dos2unix`:**
316
+
317
+ 1. Install `dos2unix` (if not already installed):
318
+
319
+ ```bash
320
+ sudo apt install dos2unix
321
+ ```
322
+
323
+ 2. Convert the script's line endings:
324
+
325
+ ```bash
326
+ dos2unix run-dev-node.sh
327
+ ```
328
+
329
+ 3. Make the Script Executable:
330
+
331
+ ```bash
332
+ chmod +x run-dev-node.sh
333
+ ```
334
+
335
+ 4. Run the Script in WSL:
336
+ ```bash
337
+ bash run-dev-node.sh
338
+ ```
339
+
340
+ ---
341
+
177
342
  ## Documentation
178
343
 
179
344
  Visit our [docs](https://arb-stylus.github.io/scaffold-stylus-docs/) to learn how to start building with Scaffold-Stylus.
@@ -4633,7 +4633,6 @@ __metadata:
4633
4633
  version: 0.0.0-use.local
4634
4634
  resolution: "@ss/stylus@workspace:packages/stylus"
4635
4635
  dependencies:
4636
- "@tanstack/react-query": ^5.81.5
4637
4636
  "@types/node": ^20.0.0
4638
4637
  "@types/yargs": ^17.0.32
4639
4638
  "@typescript-eslint/eslint-plugin": ^6.0.0
@@ -4844,7 +4843,7 @@ __metadata:
4844
4843
  languageName: node
4845
4844
  linkType: hard
4846
4845
 
4847
- "@tanstack/react-query@npm:^5.59.15, @tanstack/react-query@npm:^5.81.5":
4846
+ "@tanstack/react-query@npm:^5.59.15":
4848
4847
  version: 5.83.0
4849
4848
  resolution: "@tanstack/react-query@npm:5.83.0"
4850
4849
  dependencies:
@@ -1,263 +0,0 @@
1
- ![Image](./header.png)
2
-
3
- # Stylus Hello World
4
-
5
- Project starter template for writing Arbitrum Stylus programs in Rust using the [stylus-sdk](https://github.com/OffchainLabs/stylus-sdk-rs). It includes a Rust implementation of a basic counter Ethereum smart contract:
6
-
7
- ```js
8
- // SPDX-License-Identifier: UNLICENSED
9
- pragma solidity ^0.8.13;
10
-
11
- contract Counter {
12
- uint256 public number;
13
-
14
- function setNumber(uint256 newNumber) public {
15
- number = newNumber;
16
- }
17
-
18
- function increment() public {
19
- number++;
20
- }
21
- }
22
- ```
23
-
24
- To set up more minimal example that still uses the Stylus SDK, use `cargo stylus new --minimal <YOUR_PROJECT_NAME>` under [OffchainLabs/cargo-stylus](https://github.com/OffchainLabs/cargo-stylus).
25
-
26
- ## Quick Start
27
-
28
- Install [Rust](https://www.rust-lang.org/tools/install), and then install the Stylus CLI tool with Cargo
29
-
30
- ```bash
31
- cargo install --force cargo-stylus cargo-stylus-check
32
- ```
33
-
34
- Add the `wasm32-unknown-unknown` build target to your Rust compiler:
35
-
36
- ```
37
- rustup target add wasm32-unknown-unknown
38
- ```
39
-
40
- You should now have it available as a Cargo subcommand:
41
-
42
- ```bash
43
- cargo stylus --help
44
- ```
45
-
46
- Then, clone the template:
47
-
48
- ```
49
- git clone https://github.com/OffchainLabs/stylus-hello-world && cd stylus-hello-world
50
- ```
51
-
52
- ### Testnet Information
53
-
54
- All testnet information, including faucets and RPC endpoints can be found [here](https://docs.arbitrum.io/stylus/reference/testnet-information).
55
-
56
- ### ABI Export
57
-
58
- You can export the Solidity ABI for your program by using the `cargo stylus` tool as follows:
59
-
60
- ```bash
61
- cargo stylus export-abi
62
- ```
63
-
64
- which outputs:
65
-
66
- ```js
67
- /**
68
- * This file was automatically generated by Stylus and represents a Rust program.
69
- * For more information, please see [The Stylus SDK](https://github.com/OffchainLabs/stylus-sdk-rs).
70
- */
71
-
72
- // SPDX-License-Identifier: MIT-OR-APACHE-2.0
73
- pragma solidity ^0.8.23;
74
-
75
- interface ICounter {
76
- function number() external view returns (uint256);
77
-
78
- function setNumber(uint256 new_number) external;
79
-
80
- function mulNumber(uint256 new_number) external;
81
-
82
- function addNumber(uint256 new_number) external;
83
-
84
- function increment() external;
85
- }
86
- ```
87
-
88
- Exporting ABIs uses a feature that is enabled by default in your Cargo.toml:
89
-
90
- ```toml
91
- [features]
92
- export-abi = ["stylus-sdk/export-abi"]
93
- ```
94
-
95
- ## Deploying
96
-
97
- You can use the `cargo stylus` command to also deploy your program to the Stylus testnet. We can use the tool to first check
98
- our program compiles to valid WASM for Stylus and will succeed a deployment onchain without transacting. By default, this will use the Stylus testnet public RPC endpoint. See here for [Stylus testnet information](https://docs.arbitrum.io/stylus/reference/testnet-information)
99
-
100
- ```bash
101
- cargo stylus check
102
- ```
103
-
104
- If successful, you should see:
105
-
106
- ```bash
107
- Finished release [optimized] target(s) in 1.88s
108
- Reading WASM file at stylus-hello-world/target/wasm32-unknown-unknown/release/stylus-hello-world.wasm
109
- Compressed WASM size: 8.9 KB
110
- Program succeeded Stylus onchain activation checks with Stylus version: 1
111
- ```
112
-
113
- Next, we can estimate the gas costs to deploy and activate our program before we send our transaction. Check out the [cargo-stylus](https://github.com/OffchainLabs/cargo-stylus) README to see the different wallet options for this step:
114
-
115
- ```bash
116
- cargo stylus deploy \
117
- --private-key-path=<PRIVKEY_FILE_PATH> \
118
- --estimate-gas
119
- ```
120
-
121
- You will then see the estimated gas cost for deploying before transacting:
122
-
123
- ```bash
124
- Deploying program to address e43a32b54e48c7ec0d3d9ed2d628783c23d65020
125
- Estimated gas for deployment: 1874876
126
- ```
127
-
128
- The above only estimates gas for the deployment tx by default. To estimate gas for activation, first deploy your program using `--mode=deploy-only`, and then run `cargo stylus deploy` with the `--estimate-gas` flag, `--mode=activate-only`, and specify `--activate-program-address`.
129
-
130
- Here's how to deploy:
131
-
132
- ```bash
133
- cargo stylus deploy \
134
- --private-key-path=<PRIVKEY_FILE_PATH>
135
- ```
136
-
137
- The CLI will send 2 transactions to deploy and activate your program onchain.
138
-
139
- ```bash
140
- Compressed WASM size: 8.9 KB
141
- Deploying program to address 0x457b1ba688e9854bdbed2f473f7510c476a3da09
142
- Estimated gas: 1973450
143
- Submitting tx...
144
- Confirmed tx 0x42db…7311, gas used 1973450
145
- Activating program at address 0x457b1ba688e9854bdbed2f473f7510c476a3da09
146
- Estimated gas: 14044638
147
- Submitting tx...
148
- Confirmed tx 0x0bdb…3307, gas used 14044638
149
- ```
150
-
151
- Once both steps are successful, you can interact with your program as you would with any Ethereum smart contract.
152
-
153
- ## Network Configuration
154
-
155
- This template includes enhanced deployment scripts that support automatic RPC URL resolution from viem's chain definitions. You can now specify a network name instead of manually providing RPC URLs.
156
-
157
- ### Using Network Names
158
-
159
- Instead of setting `RPC_URL` in your environment, you can use the `NETWORK` environment variable:
160
-
161
- ```bash
162
- # Deploy to Arbitrum One (mainnet)
163
- NETWORK=arbitrum yarn deploy
164
- NETWORK=mainnet yarn deploy # alias for arbitrum
165
-
166
- # Deploy to Arbitrum Sepolia testnet
167
- NETWORK=arbitrumSepolia yarn deploy
168
- NETWORK=testnet yarn deploy # alias for arbitrumSepolia
169
- ```
170
-
171
- ### Available Networks
172
-
173
- This template supports Arbitrum networks only. You can test which networks are available and their RPC URLs:
174
-
175
- ```bash
176
- yarn test:networks
177
- ```
178
-
179
- This will show you all supported networks and their corresponding RPC endpoints.
180
-
181
- ### Fallback Behavior
182
-
183
- If a network name is not supported (only `arbitrum`, `arbitrumSepolia`, `mainnet`, and `testnet` are supported), the system will:
184
-
185
- 1. Show a warning message indicating the network isn't supported
186
- 2. Fall back to the `RPC_URL` environment variable (or default to `http://localhost:8547`)
187
- 3. Continue with deployment using the fallback endpoint
188
-
189
- ### Environment Variables
190
-
191
- You can still use the traditional approach with `RPC_URL`:
192
-
193
- ```bash
194
- RPC_URL=https://your-custom-rpc.com yarn deploy
195
- ```
196
-
197
- Or combine both (network takes precedence):
198
-
199
- ```bash
200
- NETWORK=mainnet RPC_URL=https://fallback-rpc.com yarn deploy
201
- ```
202
-
203
- ## Calling Your Program
204
-
205
- This template includes an example of how to call and transact with your program in Rust using [ethers-rs](https://github.com/gakonst/ethers-rs) under the `examples/counter.rs`. However, your programs are also Ethereum ABI equivalent if using the Stylus SDK. **They can be called and transacted with using any other Ethereum tooling.**
206
-
207
- By using the program address from your deployment step above, and your wallet, you can attempt to call the counter program and increase its value in storage:
208
-
209
- ```rs
210
- abigen!(
211
- Counter,
212
- r#"[
213
- function number() external view returns (uint256)
214
- function setNumber(uint256 number) external
215
- function increment() external
216
- ]"#
217
- );
218
- let counter = Counter::new(address, client);
219
- let num = counter.number().call().await;
220
- println!("Counter number value = {:?}", num);
221
-
222
- let _ = counter.increment().send().await?.await?;
223
- println!("Successfully incremented counter via a tx");
224
-
225
- let num = counter.number().call().await;
226
- println!("New counter number value = {:?}", num);
227
- ```
228
-
229
- Before running, set the following env vars or place them in a `.env` file (see: [.env.example](./.env.example)) in this project:
230
-
231
- ```
232
- RPC_URL=https://sepolia-rollup.arbitrum.io/rpc
233
- STYLUS_CONTRACT_ADDRESS=<the onchain address of your deployed program>
234
- PRIV_KEY_PATH=<the file path for your priv key to transact with>
235
- ```
236
-
237
- Next, run:
238
-
239
- ```
240
- cargo run --example counter --target=<YOUR_ARCHITECTURE>
241
- ```
242
-
243
- Where you can find `YOUR_ARCHITECTURE` by running `rustc -vV | grep host`. For M1 Apple computers, for example, this is `aarch64-apple-darwin` and for most Linux x86 it is `x86_64-unknown-linux-gnu`
244
-
245
- ## Build Options
246
-
247
- By default, the cargo stylus tool will build your project for WASM using sensible optimizations, but you can control how this gets compiled by seeing the full README for [cargo stylus](https://github.com/OffchainLabs/cargo-stylus). If you wish to optimize the size of your compiled WASM, see the different options available [here](https://github.com/OffchainLabs/cargo-stylus/blob/main/OPTIMIZING_BINARIES.md).
248
-
249
- ## Peeking Under the Hood
250
-
251
- The [stylus-sdk](https://github.com/OffchainLabs/stylus-sdk-rs) contains many features for writing Stylus programs in Rust. It also provides helpful macros to make the experience for Solidity developers easier. These macros expand your code into pure Rust code that can then be compiled to WASM. If you want to see what the `stylus-hello-world` boilerplate expands into, you can use `cargo expand` to see the pure Rust code that will be deployed onchain.
252
-
253
- First, run `cargo install cargo-expand` if you don't have the subcommand already, then:
254
-
255
- ```
256
- cargo expand --all-features --release --target=<YOUR_ARCHITECTURE>
257
- ```
258
-
259
- Where you can find `YOUR_ARCHITECTURE` by running `rustc -vV | grep host`. For M1 Apple computers, for example, this is `aarch64-apple-darwin`.
260
-
261
- ## License
262
-
263
- This project is fully open source, including an Apache-2.0 or MIT license at your choosing under your own copyright.
@@ -1,59 +0,0 @@
1
- import * as fs from "fs";
2
- import * as path from "path";
3
- import deployStylusContract from "./deploy_contract";
4
- import {
5
- clearDeploymentDir,
6
- ensureDeploymentDirectory,
7
- getDeploymentConfig,
8
- isContractFolder,
9
- printDeployedAddresses,
10
- } from "./utils/";
11
- import { DeployOptions } from "./utils/type";
12
-
13
- /**
14
- * Deploy all contracts in the stylus folder
15
- * @param deployOptions - The deploy options
16
- * @returns void
17
- */
18
- export default async function deployAllStylusContracts(
19
- deployOptions: DeployOptions,
20
- ) {
21
- const contractsRoot = ".";
22
- const entries = fs.readdirSync(contractsRoot, { withFileTypes: true });
23
-
24
- const config = getDeploymentConfig(deployOptions);
25
- clearDeploymentDir();
26
- ensureDeploymentDirectory(config.deploymentDir);
27
-
28
- console.log(`📄 Deploying all contracts`);
29
- console.log(`📡 Using endpoint: ${config.chain?.rpcUrl}`);
30
- if (config.chain) {
31
- console.log(`🌐 Network specified: ${config.chain?.name}`);
32
- }
33
- console.log(`🔑 Using private key: ${config.privateKey.substring(0, 10)}...`);
34
- console.log(`📁 Deployment directory: ${config.deploymentDir}`);
35
-
36
- for (const entry of entries) {
37
- if (!entry.isDirectory()) continue;
38
- const contractFolder = path.join(contractsRoot, entry.name);
39
- if (isContractFolder(contractFolder)) {
40
- try {
41
- await deployStylusContract(
42
- {
43
- contract: entry.name,
44
- ...deployOptions,
45
- },
46
- {
47
- isSingleCommand: false,
48
- },
49
- );
50
- } catch (e) {
51
- console.error(`❌ Failed to deploy contract in: ${contractFolder}`);
52
- console.error(e);
53
- }
54
- }
55
- }
56
-
57
- console.log("\n\n");
58
- printDeployedAddresses(config.deploymentDir);
59
- }