Starknet Foundry
repository·master·Indexed 18 days ago
https://github.com/foundry-rs/starknet-foundryA high-performance development toolkit for Starknet contracts written in Rust. It includes snforge, a testing framework for writing and running tests, and sncast, a CLI tool for interacting with smart contracts, sending transactions, and retrieving chain data. The toolkit is built on the native Cairo test runner and Blockifier, supporting Cairo Native execution via the --run-native flag.
What's inside Starknet Foundry
- Starknet Foundry is a comprehensive toolchain designed for developing Starknet smart contracts. Inspired by the Ethereum Foundry, it provides a suite of tools to assist developers throughout the smart contract lifecycle, specifically for writing, deploying, and testing contracts on the Starknet network.
Overview of `snforge` for Testing
mastersnforgeis the testing framework for Starknet Foundry. It allows you to:- Write and Run Tests: Create contract tests and execute them against a local devnet.
- Use Cheatcodes: Manipulate the state of the VM (e.g., changing
caller_address,block_timestamp, orbalance) to test edge cases. - Test Contract Internals: Inspect storage, events, and messages sent to L1.
- Advanced Testing: Perform Fork Testing (testing against a real network state), Fuzz Testing (randomized input testing), and Profiling (measuring resource usage).
- Estimate Resources: Calculate gas and VM resource consumption.
Overview of `sncast` for Starknet Interaction
mastersncastis the CLI tool used for interacting with the Starknet network and contracts. Key capabilities include:- Account Management: Create, import, and manage Starknet accounts.
- Contract Lifecycle: Declare and deploy new contracts, or interact with existing ones.
- Contract Interaction: Invoke functions (transactions) or call functions (read-only) on contracts.
- Transaction Inspection: Perform dry runs, inspect transaction status, and verify contracts.
- Advanced Utilities: Perform multicalls, use hardware wallets (Ledger), and transform calldata.
Overview of sncast CLI
mastersncastis a command line tool provided by Starknet Foundry for performing Starknet RPC calls and interacting with Starknet contracts. It supports subcommands for various blockchain operations like calling functions, deploying contracts, and invoking transactions.Note on Accounts: Currently,
sncastonly supports accounts using the default signature based on the Stark curve. Some operations (e.g.,declare,deploy,invoke) require paying fees and must be signed using an account.$ sncast <subcommand>Overview of Starknet Foundry
masterStarknet Foundry is a high-performance toolkit for developing Starknet contracts, written in Rust. It is built on top of the native Cairo test runner and Blockifier.
The toolkit is composed of two primary modules:
- snforge: A Starknet testing framework (comparable to Truffle, Hardhat, or DappTools) used for writing and running tests.
- sncast: An all-in-one CLI tool for interacting with Starknet smart contracts, sending transactions, and retrieving chain data.
For detailed usage, refer to the Starknet Foundry Book.
Use the `testing` module for Starknet Foundry tests
masterThetestingmodule provides utility functions designed to assist in writing and debugging Starknet tests within the Foundry environment. It contains specialized functions that allow you to inspect the state of the Virtual Machine (VM) during execution.Manage accounts with sncast account subcommands
masterThe
sncast accountcommand group provides a suite of tools for managing Starknet accounts within thesncastCLI. You can use these subcommands to perform the following lifecycle operations:import: Add an existing account to your local management.create: Generate a new account.deploy: Deploy a contract to act as an account.delete: Remove an account from local management.list: View all currently managed accounts.
Use sncast utils subcommands
masterThe
sncast utilscommand group provides a set of utility functions for common Starknet development tasks. You can access these utilities via the following subcommands:serialize: Handle data serialization.class-hash: Compute class hashes.contract-address: Derive contract addresses.selector: Compute function selectors.
Use the `signature` module for ECDSA signatures
masterThe
signaturemodule provides the necessary structures and traits to manage key pairs and create ECDSA signatures. It supports multiple curves:signature::stark_curve: Implementation for the STARK curve.signature::secp256k1_curve: Implementation for the Secp256k1 Curve.signature::secp256r1_curve: Implementation for the Secp256r1 Curve.
⚠️ Security Warning: Cryptography in Starknet Foundry is experimental and has not been audited. Use at your own risk.
Access snforge_std documentation
masterThe
snforge_stdlibrary provides standard testing utilities for Starknet development. For detailed API references, function signatures, and usage guides, visit the official documentation sites.- Library Reference: snforge-library
- Full Documentation: snforge_std docs
Explore the `sncast` CLI Reference
masterThe
sncastCLI is the primary command-line interface for Starknet Foundry. It provides a comprehensive suite of commands for interacting with Starknet networks, managing accounts, deploying contracts, and inspecting state.Key command groups include:
- Account Management:
account(import, create, deploy, delete) - Contract Lifecycle:
declare,declare-from,deploy,invoke,call - Multicall:
multicall(new, run, execute) - Data Retrieval:
get(balance, class-hash-at, nonce, spec-version, state-update, tx, tx-status) - Utilities:
utils(serialize, class-hash, selector) - System & Config:
show-config,config-path,ledger,verify,alias.
- Account Management:
Use the `fs` module for filesystem interactions
masterThe
fsmodule provides utilities for interacting with the filesystem within Starknet Foundry. It includes traits for file handling and parsing, as well as functions for reading specific file formats.Important: Any files parsed by these functions must adhere to the project's file format rules.