### Initialize a new Moccasin project Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/quickstart.rst This command creates a new Moccasin project in a specified directory, setting up the basic project structure. ```bash mox init my_project ``` -------------------------------- ### Navigate to project and display directory structure Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/quickstart.rst These commands navigate into the newly created Moccasin project directory and display its file and folder structure using the 'tree' command. ```bash cd my_project tree . ``` -------------------------------- ### Output of Moccasin contract deployment script Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/quickstart.rst This console output shows the result of running the 'deploy' script, demonstrating the contract's initial and final state after an increment operation. ```console Running run command... Starting count: 0 Ending count: 1 ``` -------------------------------- ### Run Moccasin deployment script Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/quickstart.rst This command executes the 'deploy.py' script within the Moccasin environment, simulating contract deployment and interaction on a local network. ```bash mox run deploy ``` -------------------------------- ### Moccasin default project structure output Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/quickstart.rst This console output shows the minimal directory structure created by Moccasin for a new project, including configuration, scripts, source contracts, and tests. ```console . ├── README.md ├── moccasin.toml ├── script │ ├── __init__.py │ └── deploy.py ├── src │ └── Counter.vy └── tests ├── conftest.py └── test_counter.py ``` -------------------------------- ### Initialize and Compile Moccasin Project Source: https://github.com/cyfrin/moccasin/blob/main/tests/data/installation_project/README.md This snippet provides the essential commands to initialize a new Moccasin project and then compile it using the `mox` command-line interface. These commands are typically the first steps when starting a new project. ```Bash mox init mox compile ``` -------------------------------- ### Initialize Moccasin project with VSCode integration Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/quickstart.rst This command initializes a Moccasin project and creates a '.vscode' folder to facilitate development within VSCode. ```bash mox init my_project --vscode ``` -------------------------------- ### Verify Just Command Runner Installation Source: https://github.com/cyfrin/moccasin/blob/main/CONTRIBUTING.md Checks the installed version of `just`, a command runner similar to Make. This confirms `just` is available to execute project-specific commands. ```bash just --version ``` -------------------------------- ### Python script for deploying a Moccasin contract Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/quickstart.rst This Python script demonstrates how to deploy a 'Counter' smart contract, interact with it by incrementing a value, and print its state using Moccasin's deployment utilities. ```python from src import Counter def deploy(): counter = Counter.deploy() print("Starting count: ", counter.number()) counter.increment() print("Ending count: ", counter.number()) return counter def moccasin_main(): return deploy() ``` -------------------------------- ### Configure ZKsync Network in Moccasin Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/tutorials/zksync-getting-started.rst This TOML configuration snippet defines a ZKsync network, such as Sepolia ZKsync, by specifying its RPC URL and marking it as a ZKsync network. This setup is crucial for Moccasin to interact correctly with the ZKsync chain. ```toml [networks.sepolia-zksync] url = "$SEPOLIA_ZKSYNC_RPC_URL" is_zksync = true ``` -------------------------------- ### Verify Git Installation Source: https://github.com/cyfrin/moccasin/blob/main/CONTRIBUTING.md Checks the installed version of Git to ensure it's correctly set up on the system. A successful output confirms Git is available for use. ```bash git --version ``` -------------------------------- ### Run Moccasin project tests Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/quickstart.rst This command executes the tests defined in the Moccasin project using 'pytest' under the hood, providing a summary of test results. ```bash mox test ``` -------------------------------- ### Verify Docker Installation Source: https://github.com/cyfrin/moccasin/blob/main/CONTRIBUTING.md Checks the installed version of Docker, a platform for developing, shipping, and running applications in containers. This is a prerequisite for using the Dev Container setup. ```bash docker --version ``` -------------------------------- ### Test Contracts on Local ZKsync Network Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/tutorials/zksync-getting-started.rst This command initiates a local ZKsync network and runs your tests against it. It's suitable for developing and verifying contracts in a controlled environment. ```bash mox test --network eravm ``` -------------------------------- ### Verify UV Package Manager Installation Source: https://github.com/cyfrin/moccasin/blob/main/CONTRIBUTING.md Checks the installed version of `uv`, a fast Python package installer and resolver. This verifies `uv` is ready to manage project dependencies. ```bash uv --version ``` -------------------------------- ### Force initialize Moccasin project in existing directory Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/quickstart.rst Use this command to initialize a Moccasin project in a directory that already contains files or folders, forcing the creation of the project structure. ```bash mox init my_project --force ``` -------------------------------- ### Moccasin Project Initialization and Deployment Source: https://github.com/cyfrin/moccasin/blob/main/tests/data/purge_project/README.md This snippet provides the quickstart commands to initialize a new Moccasin project and deploy it. The `mox init` command sets up the project structure, and `mox run deploy` executes the deployment process. ```bash mox init mox run deploy ``` -------------------------------- ### Moccasin Project Quickstart Commands Source: https://github.com/cyfrin/moccasin/blob/main/tests/data/zksync_project/README.md Provides the essential command-line instructions to initialize a new Moccasin project and then compile its components. These commands are part of the 'mox' CLI tool. ```bash mox init mox compile ``` -------------------------------- ### Run Deployment Script on ZKsync Network Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/tutorials/zksync-getting-started.rst After configuring your ZKsync network, this command executes a Python deployment script (e.g., `deploy.py`) on the specified ZKsync network. This is the final step to deploy your contracts to the live or testnet ZKsync environment. ```bash mox run deploy.py --network sepolia-zksync ``` -------------------------------- ### Verify Anvil Blockchain Development Framework Installation Source: https://github.com/cyfrin/moccasin/blob/main/CONTRIBUTING.md Checks the installed version of Anvil, a local blockchain development framework from Foundry. This confirms Anvil is available for local blockchain interactions. ```bash anvil --version ``` -------------------------------- ### Initialize and activate traditional virtual environment with uv Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst These commands initialize a project with `uv`, create a traditional virtual environment, and then activate it. This setup provides a standard Python virtual environment for project dependencies. ```bash uv init uv venv source .venv/bin/activate ``` -------------------------------- ### Access Local Moccasin Documentation in Browser Source: https://github.com/cyfrin/moccasin/blob/main/DOCUMENTATION.md These examples provide common paths and URLs to access the locally built Moccasin documentation in a web browser. The first is typical for live server setups (e.g., VSCode's Live Server), and the second is a direct file system path. ```bash http://127.0.0.1:5500/built_docs/html/index.html ``` ```bash /path/to/your/file/built_docs/html/index.html ``` -------------------------------- ### Example moccasin.toml Configuration Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/core_concepts/moccasin_toml.rst This TOML snippet provides a comprehensive example of a `moccasin.toml` file. It defines project-level settings like dependencies, source directory, and environment variables, alongside network-specific configurations for Sepolia, and a custom `extra_data` section. ```toml [project] dependencies = ["snekmate==0.1.1"] src = "contracts" explorer_api_key = "${ETHERSCAN_API_KEY}" dot_env = ".env" [networks.sepolia] url = "https://ethereum-sepolia-rpc.publicnode.com" chain_id = 11155111 [extra_data] my_key = "other_data" ``` -------------------------------- ### Verify Anvil ZKsync Installation Source: https://github.com/cyfrin/moccasin/blob/main/CONTRIBUTING.md Checks the installed version of `anvil-zksync`, a specific Anvil fork required for running ZKsync-related tests. This ensures the correct environment for ZKsync development. ```bash anvil-zksync --version ``` -------------------------------- ### Verify Python Installation Source: https://github.com/cyfrin/moccasin/blob/main/CONTRIBUTING.md Checks the installed version of Python to ensure it's correctly set up on the system. This command confirms the presence of a Python interpreter. ```bash python --version ``` -------------------------------- ### Moccasin Project Quickstart Commands Source: https://github.com/cyfrin/moccasin/blob/main/tests/data/deployments_project/README.md Provides a quick way to initialize and deploy a Moccasin project using the `mox` CLI tool. These commands are essential for setting up and running a new Moccasin project. ```bash mox init mox run deploy ``` -------------------------------- ### Verify ZKvyper Compiler Installation Source: https://github.com/cyfrin/moccasin/blob/main/CONTRIBUTING.md Checks the installed version of `zkvyper`, the Vyper compiler for ZKsync. This is necessary for compiling Vyper smart contracts for the ZKsync ecosystem. ```bash zkvyper --version ``` -------------------------------- ### Output of Moccasin project test execution Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/quickstart.rst This output displays the results of running tests with 'mox test', including pytest session details, collected items, and test pass/fail status. ```bash Running test command... =================================== test session starts =================================== platform darwin -- Python 3.11.9, pytest-8.3.2, pluggy-1.5.0 rootdir: /your/path/my_project plugins: cov-5.0.0, hypothesis-6.108.5, titanoboa-0.2.1 collected 1 item tests/test_counter.py . [100%] ==================================== 1 passed in 0.01s ==================================== ``` -------------------------------- ### Project Network Configuration Examples in TOML and JSON Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/index.rst Illustrates equivalent configurations for project network settings across expanded TOML, compact TOML (presented as bash), and JSON formats. These examples demonstrate how to define a source path for contracts and configure specific network details like URL and chain ID for Sepolia and ZkSync. ```toml [project] src = "contracts" [project.networks.sepolia] url = "https://..." chain_id = 11155111 [project.networks.zksync] url = "https://..." chain_id = 324 ``` ```bash [project] src = "contracts" networks = { sepolia = { url = "https://...", chain_id = 11155111 }, zksync = { url = "https://...", chain_id = 324 } } ``` ```json { "project": { "src": "contracts", "networks": { "sepolia": { "url": "https://...", "chain_id": 11155111 }, "zksync": { "url": "https://...", "chain_id": 324 } } } } ``` -------------------------------- ### Install Python Dependencies for Moccasin Documentation Source: https://github.com/cyfrin/moccasin/blob/main/DOCUMENTATION.md This command uses the `uv` tool to synchronize and install all necessary Python dependencies, including those specified as 'all-extras', required for building the Moccasin project's documentation locally. It ensures all development and documentation-specific packages are available. ```bash uv sync --all-extras ``` -------------------------------- ### Run Moccasin ZKsync Tests Source: https://github.com/cyfrin/moccasin/blob/main/CONTRIBUTING.md This command initiates the ZKsync-specific tests for the Moccasin project. It requires the necessary ZKsync dependencies to be installed and leverages `just` to invoke the test suite configured in the `justfile`. ```bash just test-z ``` -------------------------------- ### Moccasin Project Quickstart Commands Source: https://github.com/cyfrin/moccasin/blob/main/tests/data/tests_project/README.md These commands provide a quick way to initialize and deploy a Moccasin project using the `mox` command-line interface. `mox init` sets up the necessary project structure, and `mox run deploy` executes the deployment process. ```bash mox init mox run deploy ``` -------------------------------- ### Initialize New Poetry Project Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst These commands create a new Poetry project directory and navigate into it, setting up the basic structure for a Python application managed by Poetry. ```bash poetry new mox-project cd mox-project ``` -------------------------------- ### Install Moccasin from Source using uv Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst These commands clone the Moccasin repository, navigate into it, synchronize dependencies with `uv sync`, activate the virtual environment, and install Moccasin in editable mode using `uv pip install -e .`. ```bash git clone https://github.com/cyfrin/moccasin cd moccasin uv sync source .venv/bin/activate uv pip install -e . ``` -------------------------------- ### Install Moccasin CLI using uv Source: https://github.com/cyfrin/moccasin/blob/main/README.md This command uses the `uv` tool, a fast Python package installer and resolver, to install the Moccasin command-line interface (`mox`). `uv` is recommended for its efficiency in managing Python tools and dependencies. ```bash uv tool install moccasin ``` -------------------------------- ### Moccasin TOML Network Configuration Example Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/core_concepts/networks.rst Illustrates the structure and available options for defining a network within the `moccasin.toml` configuration file. This example shows settings for URL, chain ID, fork status, zkSync compatibility, default account name, password file location, extra data, and deployment database options. ```toml [networks.sepolia] url = "https://ethereum-sepolia-rpc.publicnode.com" chain_id = 11155111 fork = false is_zksync = false default_account_name = "anvil" unsafe_password_file = "~/.moccasin/password" extra_data = { "some_data" = "{$SOME_ENVIRONMENT_VARIABLE}" } save_to_db = true db_path = ".deployments.db" ``` -------------------------------- ### Verify Poetry Installation Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst This command checks the installed version of Poetry to confirm successful installation and readiness for use. ```bash poetry --version ``` -------------------------------- ### Add Moccasin Dependency with Poetry Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst These commands navigate into the project directory and add Moccasin as a dependency to the Poetry project, allowing Poetry to manage its installation and virtual environment integration. ```bash cd mox-project poetry add moccasin ``` -------------------------------- ### Deploy Moccasin Contracts with MetaMask Prompt Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/how-tos/metamask_deployment.rst Command to initiate smart contract deployment using Moccasin, which starts a local server and interfaces with MetaMask for transaction signing and deployment. ```bash mox run deploy_script.py --prompt-metamask ``` -------------------------------- ### Install Moccasin using uv pip install Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst This command installs Moccasin into the active virtual environment using `uv pip install`, which is compatible with standard `pip` installations and allows running `mox` directly. ```bash uv pip install moccasin ``` -------------------------------- ### Sync Python Dependencies with UV Source: https://github.com/cyfrin/moccasin/blob/main/CONTRIBUTING.md Uses the `uv` package manager to synchronize all project dependencies, including those specified as 'extras'. This command ensures all required Python packages are installed and managed correctly. ```bash uv sync --all-extras ``` -------------------------------- ### Install PyPI Smart Contract Dependencies with Mox Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/core_concepts/dependencies.rst Demonstrates the `mox install` command for adding smart contract dependencies from PyPI. This process is powered by the `uv` tool, which is built into `moccasin`, allowing for seamless integration with standard Python package management. ```bash mox install PACKAGE ``` ```bash mox install snekmate ``` -------------------------------- ### Install Poetry using pipx Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst This command installs the Poetry dependency manager globally using pipx, a tool for installing and managing Python applications in isolated environments. ```bash pipx install poetry ``` -------------------------------- ### Verify Moccasin Installation Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst This command checks the installed version of the Moccasin CLI tool to confirm successful installation and readiness for use. ```bash mox --version ``` -------------------------------- ### Example Moccasin Smart Contract Deployment Script Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/how-tos/metamask_deployment.rst A Python function demonstrating how to deploy a smart contract and interact with it within a Moccasin deployment script. This script would be executed by `mox run`. ```python def moccasin_main(): # Deploy your contract my_contract = MyContract.deploy() print(f"Contract deployed at: {my_contract.address}") # Interact with the contract my_contract.some_function() print("Contract interaction completed") ``` -------------------------------- ### Install pipx Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst These commands install `pipx` using `pip` and then ensure that `pipx`'s executables are added to the system's PATH. `pipx` is used for installing and running Python applications in isolated environments. ```bash python -m pip install --user pipx python -m pipx ensurepath ``` -------------------------------- ### Poetry Project Directory Structure Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst This console output illustrates the typical directory structure generated by Poetry when initializing a new project, including source code, configuration, and dependency files. ```bash . ├── mox-project │   ├── mox_project │   │   └── __init__.py │   ├── poetry.lock │   ├── pyproject.toml │   ├── README.md │   └── tests │   └── __init__.py ``` -------------------------------- ### reStructuredText Argparse Directive for Mox Install CLI Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/cli_reference/install.rst This reStructuredText snippet utilizes the `argparse` directive to automatically generate documentation for the `mox install` command. It references the `get_install` function within the `moccasin_wrapper_for_docs` Python module, which is responsible for defining the command's arguments and overall behavior. This approach ensures that the CLI documentation remains synchronized with the actual command implementation. ```APIDOC .. argparse:: :module: moccasin_wrapper_for_docs :func: get_install :prog: mox install ``` -------------------------------- ### Moccasin Network Configuration for MetaMask Deployment Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/how-tos/metamask_deployment.rst Example `moccasin.toml` configuration defining network settings for mainnet and Sepolia, including Infura URLs and chain IDs, necessary for connecting to specific blockchain networks. ```toml [networks.mainnet] url = "https://mainnet.infura.io/v3/YOUR_PROJECT_ID" chain_id = 1 [networks.sepolia] url = "https://sepolia.infura.io/v3/YOUR_PROJECT_ID" chain_id = 11155111 ``` -------------------------------- ### Install Moccasin using pipx Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst This command installs Moccasin into an isolated virtual environment using `pipx`. `pipx` makes Moccasin directly available from the command line without manual virtual environment activation. ```bash pipx install moccasin ``` -------------------------------- ### Install uv Python Package Manager Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst Instructions for installing `uv`, a fast Python package manager, on different operating systems. `uv` helps manage Python environments and packages efficiently and is recommended for Moccasin installation. ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` ```powershell powershell -c "irm https://astral.sh/uv/install.ps1 | iex" ``` -------------------------------- ### Install Moccasin with additional packages using uv Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst This command installs Moccasin along with specified additional Python packages (e.g., pandas) into an isolated environment using `uv tool install --with`. This allows Moccasin to be used with other libraries. ```bash uv tool install moccasin --with pandas ``` -------------------------------- ### Moccasin Configuration within pyproject.toml Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/core_concepts/moccasin_toml.rst This TOML example shows how Moccasin project settings can be integrated into a `pyproject.toml` file. It includes standard Python project metadata and a dedicated `[tool.moccasin]` section for Moccasin-specific configurations, such as source directory, environment file, and network settings. ```toml # unrelated to your moccasin project, aka, "normal" python project settings [project] name = "project-no-config" version = "0.1.0" description = "Add your description here" readme = "README.md" requires-python = ">=3.11, <=3.13" dependencies = [] # moccasin project settings [tool.moccasin.project] src = "contracts" dot_env = ".hello" [tool.moccasin.networks.sepolia] url = "https://ethereum-sepolia-rpc.publicnode.com" ``` -------------------------------- ### Install mamushi for Vyper Code Formatting Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/how-tos/code_formatting.rst Instructions to install the `mamushi` tool, which is a prerequisite for Moccasin's Vyper code formatting feature. It can be installed using `uv` (recommended) or `pip`. ```bash uv tool install mamushi ``` ```bash pip install mamushi ``` -------------------------------- ### Install GitHub Smart Contract Dependencies with Mox Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/core_concepts/dependencies.rst Demonstrates the `mox install` command for adding smart contract dependencies directly from GitHub repositories. This command supports specifying a particular version and is intended for Vyper contract dependencies, not Python scripts. ```bash mox install ORG/REPO[@VERSION] ``` ```bash # Without a version mox install pcaversaccio/snekmate # With a version mox install pcaversaccio/snekmate@0.1.1 ``` -------------------------------- ### Example Moccasin Project Directory Structure Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/how-tos/code_formatting.rst Illustrates a typical Moccasin project's directory layout, highlighting the common locations for Vyper contracts and interfaces, which are relevant for formatting operations. ```text my_project/ ├── moccasin.toml ├── contracts/ │ ├── Token.vy │ ├── Vault.vy │ └── interfaces/ │ └── IERC20.vy └── scripts/ └── deploy.py ``` -------------------------------- ### Moccasin CLI Version Output Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst This console output shows the expected response when verifying the Moccasin CLI installation, displaying its version number. ```bash Moccasin CLI v0.1.0 ``` -------------------------------- ### Example Moccasin Project Directory Structure Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/how-tos/vyper_subcommand.rst Provides a typical directory layout for a Moccasin project, illustrating the placement of configuration files, contract source code, and scripts. ```text my_project/ ├── moccasin.toml ├── contracts/ │ ├── Token.vy │ └── interfaces/ │ └── IERC20.vy └── scripts/ └── deploy.py ``` -------------------------------- ### Activate Poetry Virtual Environment Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst This command activates the virtual environment managed by Poetry for the current project, making its installed dependencies available in the shell session. ```bash eval $(poetry env activate) ``` -------------------------------- ### Clone Moccasin Repository Source: https://github.com/cyfrin/moccasin/blob/main/CONTRIBUTING.md Clones the Moccasin project repository from GitHub to the local machine and then changes the current directory into the newly cloned repository. This is the initial step for manual local development. ```bash git clone https://github.com/cyfrin/moccasin cd moccasin ``` -------------------------------- ### Get Vyper Compiler Help via Moccasin Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/how-tos/vyper_subcommand.rst Illustrates how to access the Vyper compiler's help documentation and available options by using the `--help` flag with the Moccasin `vyper` subcommand. ```bash mox vyper --help ``` -------------------------------- ### Demonstrate Moccasin Script Execution with `moccasin_main` Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/core_concepts/script.rst Compares two Python script examples to explain the behavior of the special `moccasin_main` function. It shows that Moccasin will automatically execute this function if present, providing a designated entry point for script logic, even if other functions are defined. ```python from src import Counter def deploy(): counter = Counter.deploy() print("Starting count: ", counter.number()) counter.increment() print("Ending count: ", counter.number()) return counter deploy() ``` ```python from src import Counter def deploy(): counter = Counter.deploy() print("Starting count: ", counter.number()) counter.increment() print("Ending count: ", counter.number()) return counter def moccasin_main(): deploy() ``` -------------------------------- ### Run Moccasin Integration Tests Source: https://github.com/cyfrin/moccasin/blob/main/CONTRIBUTING.md This command executes the integration tests for the Moccasin project. It uses the `just` command runner to abstract the underlying test command, which is defined in the project's `justfile`. ```bash just test-i ``` -------------------------------- ### Moccasin CLI Commands for Network Selection Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/core_concepts/named_contracts/manifest_named.rst Command-line examples demonstrating how to execute the `moccasin` script on various networks (mainnet, Sepolia, Arbitrum, forked, local) by simply adjusting the `--network` flag. This showcases the portability achieved by using `manifest_named` and the `moccasin.toml` configuration. ```bash # Mainnet mox run get_decimals --network mainnet # Sepolia mox run get_decimals --network sepolia # Arbitrum mox run get_decimals --network arbitrum # These next two are special # Forked mox run get_decimals --network mainnet --fork # Local (pyevm) mox run get_decimals ``` -------------------------------- ### Comprehensive Moccasin Project TOML Configuration Options Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/all_moccasin_toml_parameters.rst Provides a complete example of the `moccasin.toml` configuration file, detailing all available parameters for project settings (directories, dependencies, ABI paths), network configurations (local and live, including security and explorer settings), and default account names. ```toml # Changes the names and locations of specific directories in your project [project] src = "contracts" out = "build" script = "scripts" lib = "dependencies" # You can have pip-style dependencies and also github-style dependencies # These are going to be dependencies for your vyper contracts dependencies = ["snekmate==0.1.1", "pcaversaccio/snekmate@0.1.1"] save_abi_path = "abis" # location to save ABIs from the explorer cov_config = ".coveragerc" # coverage configuration file dot_env = ".env" # environment variables file default_network_name = "pyevm" # default network to use. `pyevm` is the local network. "eravm" is the local ZKSync network db_path = ".deployments.db" # path to the deployments database [networks.pyevm] # The basic EVM local network # cannot set URL, chain_id, fork, is_zksync, prompt_live, explorer_uri, explorer_api_key default_account_name = "anvil" [networks.eravm] # The special ZKSync Era local network # cannot set URL, chain_id, fork, is_zksync, prompt_live, explorer_uri, explorer_api_key default_account_name = "anvil" [networks.contracts] # Default named contract parameters usdc = {"address" = "0x5fbdb2315678afecb367f032d93f642f64180aa3"} # Add network settings to easily interact with networks [networks.sepolia] url = "https://ethereum-sepolia-rpc.publicnode.com" chain_id = 11155111 fork = false is_zksync = false # This is the name of the account that will be unlocked when running on this network default_account_name = "anvil" # If you don't provide a password or private key, moccasin will prompt you to unlock it # If you do, it will unlock it automatically # But be careful about storing passwords and private keys! NEVER store them in plain text unsafe_password_file = "/home/user/.moccasin/password" # Replace with actual path explorer_uri = "https://api.etherscan.io/api" # path for the supported explorer explorer_api_key = "your_api_key" # api key for the supported explorer, overrides the main one explorer_type = "blockscout" # If the explorer URL has "blockscout" or "etherscan" in the name, you don't need this prompt_live = true # A flag that will prompt you before sending a transaction, it defaults to true for "non-testing" networks ``` -------------------------------- ### Build Moccasin Project Documentation Source: https://github.com/cyfrin/moccasin/blob/main/DOCUMENTATION.md This command executes the 'docs' recipe defined in the project's `justfile`. This recipe automates the process of compiling the Moccasin documentation source files into static HTML, making them ready for local viewing. ```bash just docs ``` -------------------------------- ### Display Moccasin CLI Help Source: https://github.com/cyfrin/moccasin/blob/main/README.md This command executes the `mox` CLI with the `--help` flag, which displays a comprehensive list of available commands, their descriptions, and general options for the Moccasin framework. It's useful for quickly understanding the CLI's capabilities. ```bash mox --help ``` -------------------------------- ### Import and Use PyPI Dependencies in Vyper Smart Contracts Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/core_concepts/dependencies.rst Provides an example of importing and utilizing smart contract modules installed from PyPI within a Vyper ERC20 contract. Vyper is designed to directly inject these packages into your contract, simplifying the import process. ```python # Vyper will directly inject the package into your contract from snekmate.auth import ownable as ow initializes: ow from snekmate.tokens import erc20 initializes: erc20[ownable := ow] exports: erc20.__interface__ @deploy @payable def __init__(): erc20.__init__("my_token", "MT", 18, "my_token_dapp", "0x02") ow.__init__() ``` -------------------------------- ### Moccasin CLI DApp UI `index.html` Structure Source: https://github.com/cyfrin/moccasin/blob/main/moccasin/data/metamask_ui/README.md This section describes the main entry point for the DApp's user interface, `index.html`. It details its role in setting up the basic page structure, including inline CSS for styling, core UI elements, and loading `js/main.js` as the bootstrapping module for the entire frontend. ```APIDOC index.html: Purpose: Main entry point for the DApp UI. Contents: - Basic page structure. - Inline CSS for styling. - Core UI elements (status message area, instructions area, interactive buttons). - Loads 'js/main.js' as a JavaScript module to bootstrap the frontend. ``` -------------------------------- ### Install Moccasin using pip Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst This command installs the Moccasin package directly using pip, the standard package installer for Python, typically within an active virtual environment. ```bash pip install moccasin ``` -------------------------------- ### Import and Use GitHub Dependencies in Vyper Smart Contracts Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/core_concepts/dependencies.rst Provides examples of importing and utilizing smart contract modules installed from GitHub within a Vyper ERC20 contract. It shows both relative imports (assuming `moccasin`'s search path) and explicit full-path imports for accessing the dependency. ```python from pcaversaccio.snekmate.src.snekmate.auth import ownable as ow initializes: ow from pcaversaccio.snekmate.src.snekmate.tokens import erc20 initializes: erc20[ownable := ow] exports: erc20.__interface__ @deploy @payable def __init__(): erc20.__init__("my_token", "MT", 18, "my_token_dapp", "0x02") ow.__init__() ``` ```python # This is the "true" search path from lib.github.pcaversaccio.snekmate.src.snekmate.auth import ownable as ow initializes: ow from lib.github.pcaversaccio.snekmate.src.snekmate.tokens import erc20 initializes: erc20[ownable := ow] exports: erc20.__interface__ @deploy @payable def __init__(): erc20.__init__("my_token", "MT", 18, "my_token_dapp", "0x02") ow.__init__() ``` -------------------------------- ### Install Moccasin in isolated environment with uv Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst This command installs Moccasin into its own isolated virtual environment using `uv tool install`. This method is recommended to prevent dependency conflicts with other Python packages. ```bash uv tool install moccasin ``` -------------------------------- ### Install Python 3.11 using uv Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst This command uses `uv` to install a specific version of Python (3.11). This is useful if your system doesn't have the required Python version already installed for Moccasin. ```bash uv python install 3.11 ``` -------------------------------- ### Install Python Packages with Moccasin in Isolated Environment Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/core_concepts/dependencies/virtual_environments.rst Demonstrates how to add Python packages like 'pandas' to a 'moccasin' installation when 'moccasin' was installed using `uv tool install` or `pipx install`. For `uv`, it requires reinstalling 'moccasin' with the `--with` flag. For `pipx`, packages are injected without reinstalling. ```bash # This will reinstall moccasin with pandas uv tool install moccasin --with pandas ``` ```bash # With pipx you don't need to reinstall, you'll just "inject" the python packages you want to use. pipx inject moccasin pandas ``` -------------------------------- ### TOML, Bash, and JSON Configuration Formatting Comparison Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/all_moccasin_toml_parameters.rst Illustrates different ways to represent the same project configuration data using TOML (expanded and compact forms) and JSON, highlighting their structural similarities and how they map to each other. ```toml [project] src = "contracts" [project.networks.sepolia] url = "https://..." chain_id = 11155111 [project.networks.zksync] url = "https://..." chain_id = 324 ``` ```bash [project] src = "contracts" networks = { sepolia = { url = "https://...", chain_id = 11155111 }, zksync = { url = "https://...", chain_id = 324 } } ``` ```json { "project": { "src": "contracts", "networks": { "sepolia": { "url": "https://...", "chain_id": 11155111 }, "zksync": { "url": "https://...", "chain_id": 324 } } } } ``` -------------------------------- ### Moccasin CLI: `mox deploy` Command Reference Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/core_concepts/scripting/deploy.rst Provides the full command-line interface reference for the `mox deploy` command, including its usage syntax, positional arguments, and all available options for configuration, network, and account management. ```bash mox deploy --help ``` ```APIDOC usage: Moccasin CLI deploy [-h] [-d] [-q] [--fork [FORK]] [--network NETWORK | --url URL | --prompt-live [PROMPT_LIVE]] [--account ACCOUNT | --private-key PRIVATE_KEY] [--password PASSWORD | --password-file-path PASSWORD_FILE_PATH] contract_name Deploys a contract named in the config with a deploy script. positional arguments: contract_name Name of contract in your moccasin.toml to deploy. options: -h, --help show this help message and exit -d, --debug Run in debug mode -q, --quiet Suppress all output except errors --fork [FORK] --network NETWORK Alias of the network (from the moccasin.toml). --url URL, --rpc URL RPC URL to run the script on. --prompt-live [PROMPT_LIVE] Prompt the user to make sure they want to run this script. --account ACCOUNT Keystore account you want to use. --private-key PRIVATE_KEY Private key you want to use to get an unlocked account. --password PASSWORD Password for the keystore account. --password-file-path PASSWORD_FILE_PATH Path to the file containing the password for the keystore account. ``` -------------------------------- ### Install Python Packages in Virtual Environment Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/core_concepts/dependencies/virtual_environments.rst Shows various commands to install Python packages like 'pandas' within an activated virtual environment using `uv add`, `uv pip install`, `pip install`, or `poetry add`. These methods are standard for managing dependencies in isolated project environments. ```bash uv add pandas ``` ```bash uv pip install pandas ``` ```bash pip install pandas ``` ```bash poetry add pandas ``` -------------------------------- ### Set up a Python Virtual Environment Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/core_concepts/dependencies/virtual_environments.rst Provides commands to initialize and activate a Python virtual environment using `uv`, `python -m venv`, or `poetry`. These steps prepare an isolated environment for project dependencies. ```bash uv init uv venv source .venv/bin/activate ``` ```bash python -m venv .venv source .venv/bin/activate ``` ```bash poetry init poetry shell ``` -------------------------------- ### Install Moccasin as uv project dependency Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/installing_moccasin.rst This command adds Moccasin as a dependency to the current `uv` project. When installed this way, Moccasin can be run using `uv run mox` within the project's virtual environment. ```bash uv add moccasin ``` -------------------------------- ### Deploy Counter Contract with pyevm Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/core_concepts/networks/pyevm.rst This Python script defines a `deploy` function to deploy a `Counter` contract, interact with it by incrementing its value, and print its state. The `moccasin_main` function serves as the entry point for `moccasin` to execute the deployment logic, utilizing the default `pyevm` network for local simulation. ```python from contracts import Counter from moccasin.boa_tools import VyperContract def deploy() -> VyperContract: counter: VyperContract = Counter.deploy() print("Starting count: ", counter.number()) counter.increment() print("Ending count: ", counter.number()) return counter def moccasin_main() -> VyperContract: return deploy() ``` -------------------------------- ### Illustrate Moccasin Project Directory Structure Source: https://github.com/cyfrin/moccasin/blob/main/docs/source/core_concepts/script.rst Displays a typical Moccasin project directory layout, showcasing the standard organization of files and folders. This includes the `script` directory for Python scripts, the `src` directory for smart contracts, and the `tests` directory, along with configuration files like `moccasin.toml`. ```bash . ├── README.md ├── moccasin.toml ├── script │ └── deploy.py ├── src │ └── Counter.vy └── tests ├── conftest.py └── test_counter.py ```