### Install Dependencies Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/examples/erc721/scripts/README.md Run this command to install the necessary project dependencies. ```shell yarn ``` -------------------------------- ### Install Cargo Stylus Locally Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Installs the cargo-stylus tool from a local source repository. This is useful for development or testing changes to the tool itself. ```shell cargo install cargo-stylus ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/examples/erc721/scripts/README.md Copy the example environment file to create your own configuration. ```shell cp .env.example .env ``` -------------------------------- ### Install Cargo Stylus and Set Up Build Target Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Install the cargo-stylus tool and add the necessary build target for WASM compilation. This is a prerequisite for using most cargo-stylus commands. ```bash cargo install cargo-stylus rustup target add wasm32-unknown-unknown ``` -------------------------------- ### Install colorama for Stylus Debugging Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Install the colorama package using pip within a virtual environment. This is a prerequisite for some Stylus debugging features. ```bash $ python3 -m venv myvenv $ source ./myvenv/bin/activate (myvenv) $ pip3 install colorama ``` -------------------------------- ### Debugger Session Example Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md An example of an lldb session after replaying a transaction. It shows the debugger attaching, stopping at a breakpoint, and allowing code inspection. ```lldb 1 location added to breakpoint 1 warning: This version of LLDB has no plugin for the language "rust". Inspection of frame variables will be limited. Process 9256 stopped * thread #1, name = 'main', queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 frame #0: 0x000000010102cbb8 libstylus_hello_world.dylib`user_entrypoint(len=4) at lib.rs:33:5 30 // Define some persistent storage using the Solidity ABI. 31 // `Counter` will be the entrypoint. 32 sol_storage! { -> 33 #[entrypoint] 34 pub struct Counter { 35 uint256 number; 36 } Target 0: (cargo-stylus) stopped. Process 9256 launched: '~/.cargo/bin/cargo-stylus' (arm64) (lldb) c Process 9256 resuming call completed successfully Process 9256 exited with status = 0 (0x00000000) (lldb) q ``` -------------------------------- ### Start Local Nitro Node Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/test/README.md Starts a local Nitro development node using Docker. Ensure the necessary ports are exposed for RPC communication. ```bash docker run -it --rm --name nitro-dev -p 8547:8547 \ offchainlabs/nitro-node:v3.5.3-rc.3-653b078 \ --dev --http.addr 0.0.0.0 --http.api=net,web3,eth,arb,arbdebug,debug ``` -------------------------------- ### Clone and Build Cargo Stylus Locally Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Clones the cargo-stylus repository and installs it locally. This process involves cloning a specific release version, navigating to the directory, and running an installation script. ```shell git clone --branch [VERSION_TAG] https://github.com/OffchainLabs/stylus-sdk-rs.git cd stylus-sdk-rs/cargo-stylus ./install.sh ``` -------------------------------- ### Deploy Solidity Counter Contract Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/examples/single_call/scripts/README.md Deploy the `Counter.sol` Solidity contract using Hardhat Ignition. This script requires Node.js and Yarn to be installed. ```bash yarn hardhat ignition deploy ignition/modules/deploy_counter.js --network arb_sepolia ``` -------------------------------- ### Run Nitro Debug Node Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Starts a local Nitro development node. Ensure the port is accessible for debugging. ```bash docker run -it --rm --name nitro-dev -p 8547:8547 offchainlabs/nitro-node:v3.5.3-rc.3-653b078 --dev --http.addr 0.0.0.0 --http.api=net,web3,eth,arb,arbdebug,debug ``` -------------------------------- ### Stylus Contract Check Success Example Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md This output indicates that your contract has successfully passed Stylus onchain activation checks. ```shell Finished release [optimized] target(s) in 1.88s Reading WASM file at hello-stylus/target/wasm32-unknown-unknown/release/hello-stylus.wasm Compressed WASM size: 3 KB Contract succeeded Stylus onchain activation checks with Stylus version: 1 ``` -------------------------------- ### FileCheck Directives for Cargo Stylus Tests Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/test/README.md Example of using FileCheck directives within a .test file to verify the output of cargo-stylus commands. This is essential for writing new tests. ```bash # RUN: %cargo-stylus replay --tx-hash %{counter_tx} --rpc-url %{rpc_url} 2>&1 | FileCheck %s # CHECK: Starting debug session ``` -------------------------------- ### Stylus Contract Check Failure Example Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md This output shows detailed information when a WASM contract fails Stylus checks, indicating why it will be rejected onchain. ```shell Reading WASM file at bad-export.wat Compressed WASM size: 55 B Stylus checks failed: contract predeployment check failed when checking against ARB_WASM_ADDRESS 0x0000…0071: (code: -32000, message: contract activation failed: failed to parse contract) Caused by: binary exports reserved symbol stylus_ink_left Location: prover/src/binary.rs:493:9, data: None ``` -------------------------------- ### Deploy Rust SingleCall Contract Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/examples/single_call/scripts/README.md Deploy the `SingleCall` Rust contract to a network using the `cargo stylus deploy` command. Ensure you have `cargo-stylus` installed and provide the necessary RPC URL and private key path. ```bash cargo stylus deploy -e https://sepolia-rollup.arbitrum.io/rpc --private-key-path=./.path_to_your_key_file ``` -------------------------------- ### Compile and Deploy Stylus Hello World Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Clones the stylus-hello-world repository, sets environment variables for RPC URL and private key, and deploys the contract. ```bash git clone https://github.com/Offchainlabs/stylus-hello-world cd stylus-hello-world export RPC_URL=http://localhost:8547 export PRIV_KEY=0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659 cargo stylus deploy --private-key=$PRIV_KEY --endpoint=$RPC_URL ``` -------------------------------- ### Create Minimal Stylus Project Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Creates a new Stylus project with a minimal set of files, providing a barebones structure for a Stylus entrypoint. ```bash cargo stylus new --minimal ``` -------------------------------- ### Create a New Stylus Project Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Scaffolds a new Arbitrum Stylus project using a default template. This command initializes a new Rust project configured for Stylus development. ```bash cargo stylus new my-contract ``` -------------------------------- ### Run replay with stylusdb debugger Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Initiate a replay of a transaction using the `stylusdb` debugger by specifying `--debugger stylusdb`. ```bash $ cargo stylus replay --debugger stylusdb --tx [other args] ``` -------------------------------- ### Create a New Stylus Project Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Generates a new Stylus project from a template. Use the `--minimal` flag for a stripped-down project structure. ```shell # Create a full-featured Counter example project cargo stylus new my-token-contract ``` ```shell # Create a minimal project with just the essentials cargo stylus new --minimal minimal-contract ``` -------------------------------- ### Basic TestVM Initialization Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/stylus-test/README.md Initializes a Counter Stylus contract with a default TestVM for unit testing. ```rust let vm = TestVM::default(); let mut contract = Counter::from(&vm); ``` -------------------------------- ### Correct Contract Path Specification for Solidity Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Shows the correct method for specifying Solidity contracts with the `--contracts` flag by only providing the contract address, without any path suffix. This ensures proper debugging of mixed contract types. ```bash # Only specify the Solidity contract address without a path car go stylus replay --debugger stylusdb \ --tx=0xb590941f5de2a2164b76143ef4ca9d27df2d7c718c058fd2bbef4ac56b72d149 \ --contracts 0xa6e41ffd769491a42a6e5ce453259b93983a22ef:.,0x1294b86822ff4976BfE136cB06CF43eC7FCF2574 ``` -------------------------------- ### Run All Cargo Stylus Tests Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/test/README.md Executes the entire Cargo Stylus test suite from the project's root directory. This command is useful for a comprehensive test run. ```bash ./test/run-tests.sh ``` -------------------------------- ### Run Minting Script Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/examples/erc721/scripts/README.md Execute this command to run the ERC-721 token minting script. ```shell yarn mint ``` -------------------------------- ### Incorrect Contract Path Specification for Solidity Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Demonstrates an incorrect way to specify Solidity contracts using the `--contracts` flag with a directory path, which will result in an error. Solidity contracts should only be specified by address. ```bash # This will error because ../erc20 is a Solidity contract directory car go stylus replay --debugger stylusdb \ --tx=0xb590941f5de2a2164b76143ef4ca9d27df2d7c718c058fd2bbef4ac56b72d149 \ --contracts 0xa6e41ffd769491a42a6e5ce453259b93983a22ef:.,0x1294b86822ff4976BfE136cB06CF43eC7FCF2574:../erc20 ``` -------------------------------- ### Deploy Stylus Contract to Testnet Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Deploys the compiled Stylus contract to a specified Arbitrum testnet endpoint. Requires a private key path and the RPC endpoint URL. ```bash cargo stylus deploy --private-key-path=/path/to/key.txt --endpoint="https://sepolia-rollup.arbitrum.io/rpc" ``` -------------------------------- ### Check Contract Deployability Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Analyzes the contract to ensure it can be deployed to the Arbitrum network. This command performs checks before the actual deployment process. ```bash cargo stylus check ``` -------------------------------- ### Export Stylus Project ABI to File or Stdout Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Exports the Solidity ABI for the current Stylus project. Can output to stdout, a specified file, or generate JSON format with the `--json` flag. ```shell # Export ABI to stdout cargo stylus export-abi ``` ```shell # Export JSON ABI to file cargo stylus export-abi --output=./abi.json --json ``` ```shell # Export with specific Rust features cargo stylus export-abi --rust-features=feature1,feature2 ``` -------------------------------- ### Deploy Non-Rust WASM Project Command Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Use `cargo stylus deploy` with the `--wasm-file` flag to deploy non-Rust WASM projects, such as WAT files. ```shell cargo stylus deploy --wasm-file=add.wat ``` -------------------------------- ### Standard LLDB Commands for Debugging Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md A collection of common LLDB commands for controlling execution, inspecting variables, and managing breakpoints during debugging sessions. ```bash (stylusdb) c ``` ```bash (stylusdb) n ``` ```bash (stylusdb) s ``` ```bash (stylusdb) p number ``` ```bash (stylusdb) expr -f hex -- number.limbs[0] ``` ```bash (stylusdb) bt ``` ```bash (stylusdb) breakpoint list ``` ```bash (stylusdb) breakpoint delete 1 ``` ```bash (stylusdb) q ``` -------------------------------- ### Define Storage-Backed Structs and Methods in Rust Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/README.md Use `sol_storage!` macro to define storage-backed Rust structs that are equivalent to Solidity contracts. Public methods can be defined using `#[public]` for on-chain interaction. ```rust use stylus_sdk::{alloy_primitives::U256, prelude::*}; // Generate Solidity-equivalent, Rust structs backed by storage. sol_storage! { #[entrypoint] pub struct Counter { uint256 number; } } #[public] impl Counter { // Gets the number value from storage. pub fn number(&self) -> Result> { Ok(self.number.get()) } // Sets a number in storage to a user-specified value. pub fn set_number(&mut self, new_number: U256) -> Result<(), Vec> { self.number.set(new_number); Ok(()) } } ``` -------------------------------- ### Inspect Emitted Logs with TestVM Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/stylus-test/README.md Use `TestVM::raw_log` to emit logs and `TestVM::get_emitted_logs` to retrieve and assert their content. Ensure logs are correctly formatted before assertion. ```rust #[test] fn test_logs() { let vm = TestVM::new(); let topic1 = B256::from([1u8; 32]); let topic2 = B256::from([2u8; 32]); let data = vec![3, 4, 5]; vm.raw_log(&[topic1, topic2], &data).unwrap(); let logs = vm.get_emitted_logs(); assert_eq!(logs.len(), 1); assert_eq!(logs[0].0, vec![topic1, topic2]); assert_eq!(logs[0].1, data); } ``` -------------------------------- ### Enable verbose usertrace Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md To include calls from `stylus_sdk::`, use the `--verbose-usertrace` flag with the `usertrace` command. ```bash $ cargo stylus usertrace \ --tx=0x88b0ad9daa0b701d868a5f9a0132db7c0402178ba44ed8dec4ba76784c7194fd \ --endpoint=$RPC_URL --verbose-usertrace ``` -------------------------------- ### Run usertrace command for transaction tracing Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Use the `cargo stylus usertrace` command to trace a specific transaction. This attaches to `stylusdb` and provides a function call tree. ```bash $ cargo stylus usertrace \ --tx=0x88b0ad9daa0b701d868a5f9a0132db7c0402178ba44ed8dec4ba76784c7194fd \ --endpoint=$RPC_URL ``` -------------------------------- ### Run Cargo Stylus Tests with Custom RPC Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/test/README.md Runs the Cargo Stylus test suite using a custom RPC URL. Set the RPC_URL environment variable before executing the test script. ```bash RPC_URL=http://localhost:8545 ./test/run-tests.sh ``` -------------------------------- ### Trace external library calls with usertrace Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md To trace calls from external libraries like `std`, `core`, or custom contracts, use the `--trace-external-usertrace` option with a comma-separated list of library names. ```bash cargo stylus usertrace \ --tx=0x88b0ad9daa0b701d868a5f9a0132db7c0402178ba44ed8dec4ba76784c7194fd \ --endpoint=$RPC_URL --verbose-usertrace --trace-external-usertrace="std,core,other_contract" ``` -------------------------------- ### Basic Storage Assertions with TestVM Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/stylus-test/README.md Performs basic storage assertions on a Counter contract using TestVM. ```rust assert_eq!(U256::ZERO, contract.number()); contract.increment(); assert_eq!(U256::from(1), contract.number()); ``` -------------------------------- ### Custom TestVM Configuration with TestVMBuilder Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/stylus-test/README.md Configures a TestVM with custom sender address, contract address, message value, and RPC URL using TestVMBuilder. ```rust use stylus_test::{TestVM, TestVMBuilder}; use alloy_primitives::{address, Address, U256}; let vm: TestVM = TestVMBuilder::new() .sender(address!("dCE82b5f92C98F27F116F70491a487EFFDb6a2a9")) .contract_address(address!("DeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF")) .value(U256::from(1)) .rpc_url("http://localhost:8547") .build(); ``` -------------------------------- ### Deploy Stylus Contract to Arbitrum Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Deploys a Stylus contract to an Arbitrum chain and activates it. Options include specifying the endpoint, private key path, gas estimation, and build verification. ```shell # Deploy to default testnet and estimate gas cargo stylus deploy --private-key-path=./key.txt --estimate-gas ``` ```shell # Deploy to mainnet without Docker verification cargo stylus deploy --endpoint="https://arb1.arbitrum.io/rpc" \ --private-key-path=./key.txt --no-verify ``` ```shell # Deploy without activation (for advanced use cases) cargo stylus deploy --private-key-path=./key.txt --no-activate ``` -------------------------------- ### Stylus Contract Deployment Gas Estimation Result Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md This output shows the estimated gas required for deploying a Stylus contract. ```shell Compressed WASM size: 3 KB Deploying contract to address 0x457b1ba688e9854bdbed2f473f7510c476a3da09 Estimated gas: 12756792 ``` -------------------------------- ### Debug multi-contract transactions with stylusdb Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md For multi-contract transactions, provide contract addresses and paths using the `--contracts` argument when running `cargo stylus replay` with `stylusdb`. ```bash $ cargo stylus replay --debugger stylusdb --tx \ --contracts ADDR:PATH,0xe1080224B632A93951A7CFA33EeEa9Fd81558b5e:../ \ --endpoint=$RPC_URL ``` -------------------------------- ### Estimate Gas for Stylus Contract Deployment Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Estimate the gas required for deploying and activating your Stylus contract before performing the actual deployment. ```shell cargo stylus deploy \ --private-key-path= \ --estimate-gas ``` -------------------------------- ### Export Solidity ABIs with cargo-stylus Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Use this command to export the Solidity ABI for your Stylus project. It simplifies the process of generating ABIs for contracts written in Rust for Stylus. ```shell cargo stylus export-abi ``` -------------------------------- ### List registered contracts in StylusDB Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md View all contracts currently registered with the StylusDB debugger session, including their paths and breakpoint counts. ```bash (stylusdb) stylus-contract list ``` -------------------------------- ### Add contract to StylusDB debugger Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Use the `stylus-contract add` command to register a contract with its address and library path in the StylusDB debugger session. ```bash (stylusdb) stylus-contract add 0xA6E41fFD769491a42A6e5Ce453259b93983a22EF ./target/debug/libmy_contract.dylib ``` -------------------------------- ### View Cargo Stylus Help Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Displays the help message for the cargo-stylus subcommand, listing available commands and options. ```shell cargo stylus --help ``` -------------------------------- ### Deploy Non-Rust WASM Project Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Deploy WASM projects not written in Rust, including individual WASM files or WebAssembly Text (WAT) files, using the `--wasm-file` flag. ```js (module (memory 0 0) (export "memory" (memory 0)) (type $t0 (func (param i32) (result i32))) (func $add_one (export "add_one") (type $t0) (param $p0 i32) (result i32) local.get $p0 i32.const 1 i32.add) (func (export "user_entrypoint") (param $args_len i32) (result i32) (i32.const 0) )) ``` -------------------------------- ### Deploy Stylus Contract Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Deploy your Stylus contract onchain. This command sends two transactions by default: one to deploy the code and another to activate the contract. ```shell cargo stylus deploy \ --private-key-path= ``` -------------------------------- ### Show call stack in StylusDB Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Display the current call stack to understand the execution flow between different contracts and functions. ```bash (stylusdb) stylus-contract stack ``` -------------------------------- ### Stylus Contract Deployment Confirmation Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md This output confirms the successful deployment and activation of a Stylus contract onchain, including transaction hashes and gas used. ```shell Compressed WASM size: 3 KB Deploying contract to address 0x457b1ba688e9854bdbed2f473f7510c476a3da09 Estimated gas: 12756792 Submitting tx... Confirmed tx 0x42db…7311, gas used 11657164 Activating contract at address 0x457b1ba688e9854bdbed2f473f7510c476a3da09 Estimated gas: 14251759 Submitting tx... Confirmed tx 0x0bdb…3307, gas used 14204908 ``` -------------------------------- ### Check Non-Rust WASM Project Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Use `cargo stylus check` with the `--wasm-file` flag to check the validity of non-Rust WASM projects, such as WAT files. ```shell cargo stylus check --wasm-file=add.wat ``` -------------------------------- ### Define a Counter Stylus Contract Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/stylus-test/README.md Defines a basic Counter smart contract using Stylus SDK, including storage and public methods. ```rust use stylus_sdk::{alloy_primitives::U256, prelude::*}; sol_storage! { #[entrypoint] pub struct Counter { uint256 number; } } #[public] impl Counter { pub fn number(&self) -> U256 { self.number.get() } pub fn increment(&mut self) { let number = self.number.get(); self.set_number(number + U256::from(1)); } #[payable] pub fn add_from_msg_value(&mut self) { let number = self.number.get(); self.set_number(number + self.vm().msg_value()); } } ``` -------------------------------- ### Replay Transaction with Solidity Contract Debugging Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Replays a transaction using the Stylus debugger, marking specific addresses as Solidity contracts to aid in tracing cross-contract calls. Use this to debug mixed Stylus/Solidity interactions. ```bash $ cargo stylus replay --debugger stylusdb --tx \ --addr-solidity=0xda52b25ddb0e3b9cc393b0690ac62245ac772527 \ --endpoint=$RPC_URL ``` -------------------------------- ### Show Current Stylus Debugger Context Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Displays the current contract context within the Stylus debugger. Use this to verify which contract is currently being debugged. ```bash (stylusdb) stylus-contract context show Current context: 0xe1080224B632A93951A7CFA33EeEa9Fd81558b5e ``` -------------------------------- ### Set breakpoint on entrypoint in StylusDB Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Set a breakpoint on the contract's entrypoint function using `user_entrypoint`. ```bash (stylusdb) stylus-contract breakpoint 0xA6E41fFD769491a42A6e5Ce453259b93983a22EF user_entrypoint ``` -------------------------------- ### Replay Transaction with Debugger Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Replays a specific transaction using 'cargo stylus replay' to attach a debugger (lldb or gdb). This allows stepping through the contract execution. ```bash cargo stylus replay \ --tx=0x88b0ad9daa0b701d868a5f9a0132db7c0402178ba44ed8dec4ba76784c7194fd \ --endpoint=$RPC_URL ``` -------------------------------- ### Stylus Debugger Output for Solidity Calls Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Illustrates the output displayed by the Stylus debugger when it encounters a call to a marked Solidity contract. This output includes the contract address and function selector. ```text ════════ Solidity Contract Call ════════ Contract: 0xda52b25ddb0e3b9cc393b0690ac62245ac772527 Function selector: 0xd09de08a (increment()) NOTE: This is a Solidity contract - skipping to next contract ``` -------------------------------- ### Mock External Calls with TestVM Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/stylus-test/README.md Mock both successful and revert cases for external calls using `TestVM::mock_call`. This allows testing contract interactions without actual external execution. Assert the return value for success and the revert data for errors. ```rust #[test] fn test_mock_calls() { let vm = TestVM::new(); let target = Address::from([2u8; 20]); let data = vec![1, 2, 3, 4]; let expected_return = vec![5, 6, 7, 8]; // Mock a regular call. vm.mock_call(target, data.clone(), Ok(expected_return.clone())); let ctx = stylus_core::calls::Call::new(); let result = vm.call(&ctx, target, &data).unwrap(); assert_eq!(result, expected_return); // Mock an error case. let error_data = vec![9, 9, 9]; vm.mock_call(target, data.clone(), Err(error_data.clone())); match vm.call(&ctx, target, &data) { Err(Error::Revert(returned_data)) => assert_eq!(returned_data, error_data), _ => panic!("Expected revert error"), } } ``` -------------------------------- ### Check Stylus Contract Deployability Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Validates that a contract can be deployed and activated on Arbitrum Stylus. You can specify an endpoint, a WASM file path, or a target contract address. ```shell # Check the current project against default testnet cargo stylus check ``` ```shell # Check against a specific network cargo stylus check --endpoint="https://arb1.arbitrum.io/rpc" ``` ```shell # Check a specific WASM file cargo stylus check --wasm-file=./path/to/contract.wasm ``` -------------------------------- ### Verify Deployed Stylus Contract Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Verifies a previously deployed contract on an Arbitrum chain. Requires the deployment transaction hash and optionally allows skipping Docker verification. ```shell # Verify a contract on Arbitrum Sepolia cargo stylus verify --deployment-tx=0x1234abcd... ``` ```shell # Verify a contract on mainnet cargo stylus verify --endpoint="https://arb1.arbitrum.io/rpc" \ --deployment-tx=0x5678efgh... ``` -------------------------------- ### Run Specific Cargo Stylus Test Category Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/test/README.md Executes a specific category of tests within the Cargo Stylus suite, such as replay or usertrace tests. Use the 'lit -v' command followed by the directory path. ```bash lit -v test/replay/ ``` ```bash lit -v test/usertrace/ ``` -------------------------------- ### Error Message for Incorrect Solidity Contract Path Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Displays the error message received when attempting to specify a Solidity contract with a directory path using the `--contracts` flag. This indicates that only the address should be provided for Solidity contracts. ```text error: could not find `Cargo.toml` in `/path/to/erc20` or any parent directory Error: failed to replay tx Caused by: failed to open ../erc20/target/aarch64-apple-darwin/debug/: No such file or directory ``` -------------------------------- ### Increment Counter via SingleCall Contract Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/examples/single_call/scripts/README.md Execute the `increment` script to call the `Counter` contract's `increment()` function via the `SingleCall` router. This script demonstrates the interaction between the Stylus `SingleCall` contract and the deployed Solidity `Counter` contract. ```bash yarn run increment ``` -------------------------------- ### Add WASM Build Target Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Adds the `wasm32-unknown-unknown` target to the Rust toolchain, which is necessary for compiling Rust code to WebAssembly for Stylus contracts. ```shell rustup target add wasm32-unknown-unknown ``` -------------------------------- ### Set breakpoint on external contract function Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Within the `stylusdb` interactive session, use `stylus-contract breakpoint` to set a breakpoint on a specific function in an external contract. ```bash (stylusdb) stylus-contract breakpoint 0xe1080224B632A93951A7CFA33EeEa9Fd81558b5e external_contract::ServiceContract::increment ``` -------------------------------- ### Export Contract ABI Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/README.md Generates the Application Binary Interface (ABI) for the Stylus contract, typically saved to a JSON file. This is useful for interacting with the contract from other applications or frontends. ```bash cargo stylus export-abi --output=./abi.json --json ``` -------------------------------- ### Mocking Message Value with TestVM Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/stylus-test/README.md Mocks the message value of a transaction using TestVM and asserts contract logic. ```rust vm.set_value(U256::from(2)); contract.add_from_msg_value(); assert_eq!(U256::from(3), contract.number()); ``` -------------------------------- ### Switch debugging context in StylusDB Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Change the active debugging context to a specific contract by its address. This affects which contract's code is currently being debugged. ```bash (stylusdb) stylus-contract context 0xe1080224B632A93951A7CFA33EeEa9Fd81558b5e ``` -------------------------------- ### Send Increment Transaction Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Sends an 'increment' transaction to the deployed contract using cast. The output shows transaction details and status. ```bash $ export ADDR=0xda52b25ddb0e3b9cc393b0690ac62245ac772527 $ cast send --rpc-url=$RPC_URL --private-key=$PRIV_KEY $ADDR "increment()" ``` -------------------------------- ### Set breakpoint on specific function in StylusDB Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Set a breakpoint on a specific function within a contract using its address and the function's fully qualified name. ```bash (stylusdb) stylus-contract breakpoint 0xA6E41fFD769491a42A6e5Ce453259b93983a22EF stylus_hello_world::Counter::increment ``` -------------------------------- ### Set breakpoint on internal function in StylusDB Source: https://github.com/offchainlabs/stylus-sdk-rs/blob/main/cargo-stylus/docs/StylusDebugger.md Set a breakpoint on an internal function within a contract by providing its fully qualified name. ```bash (stylusdb) stylus-contract breakpoint 0xA6E41fFD769491a42A6e5Ce453259b93983a22EF stylus_hello_world::Counter::set_number ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.