### Install starkli using starkliup Source: https://github.com/xjonathanlei/starkli/blob/master/README.md This snippet demonstrates the recommended installation method for the starkli CLI tool. It involves downloading the `starkliup` installation script using `curl` and executing it with `sh`. After `starkliup` is installed, it can be run without arguments to install or update starkli, leveraging prebuilt binaries for convenience. ```shell curl https://get.starkli.sh | sh starkliup ``` -------------------------------- ### Install Starkli using starkliup Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/installation.md Installs Starkli using the `starkliup` script, which downloads prebuilt binaries and manages shell configuration. This is the recommended method for Linux, macOS, WSL, and Android. Restart your shell session after installation for the command to be available. ```shell curl https://get.starkli.sh | sh ``` ```shell starkliup ``` -------------------------------- ### Install Starkli from Source Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/installation.md Installs Starkli directly from its GitHub repository using Cargo. This method requires Rust to be installed and is useful for accessing unreleased features. Note that shell completions are not automatically configured with this method. ```shell cargo install --locked --git https://github.com/xJonathanLEI/starkli ``` -------------------------------- ### Basic Deployment Example Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/deploying-contracts.md A simple example of how to invoke the `starkli deploy` command with a placeholder class hash and constructor arguments. ```console starkli deploy ``` -------------------------------- ### Install Starknet Ledger App via Command Line Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/ledger.md Instructions for installing the Starknet Ledger app using the `ledgerctl` command-line tool. This method is a fallback if Ledger Live installation fails and requires downloading pre-compiled app artifacts. The app installed this way is not signed by Ledger. ```console ledgerctl install -f app_nanoplus.json ``` -------------------------------- ### Upgrade starkliup script Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/installation.md To upgrade the `starkliup` script itself to the latest version, re-run the initial `curl` command. This ensures you have the most recent version of the installer. ```shell curl https://get.starkli.sh | sh ``` -------------------------------- ### Free RPC Vendor Configuration Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/profiles.md Configures a network to use a free RPC vendor. This example specifies the 'blast' vendor, which Starkli can use to connect to the network. ```toml [default.networks.mainnet] chain_id = "SN_MAIN" provider = { type = "free", vendor = "blast" } ``` -------------------------------- ### Example: ETH Transfer Invoke Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/invoking-contracts.md Demonstrates a practical example of invoking the `transfer` function on the ETH contract. It shows how to specify the recipient address and the amount, noting that `u256` types require two field elements. ```console starkli invoke 0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 transfer 0x1234 100 0 ``` -------------------------------- ### Starkli Invoke Command Example Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/argument-resolution.md Demonstrates how scheme omission simplifies command-line arguments for `starkli invoke` when the first positional arguments are implicitly an address and a selector. ```console starkli invoke addr:eth selector:transfer ... ``` ```console starkli invoke eth transfer ... ``` -------------------------------- ### Check Supported JSON-RPC Version Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/providers.md This command displays the verbose version output of Starkli, which includes information about the supported JSON-RPC specification version. This is useful for ensuring compatibility between your Starkli installation and the Starknet network you are interacting with. ```console starkli -vV ``` -------------------------------- ### Multicall Support in Starkli Invoke Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/invoking-contracts.md Demonstrates how to execute multiple contract calls within a single transaction by separating individual calls with a forward slash (`/`). This example includes an ETH transfer and an approve call. ```console starkli invoke eth transfer 0x1234 u256:100 / eth approve 0x4321 u256:300 ``` -------------------------------- ### Generate Starkli Shell Completions Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/shell-completions.md Command to generate shell completion scripts for Starkli. The output is printed to standard output and can be redirected to a file for installation. This command supports various shells like bash, fish, zsh, powershell, and elvish. ```shell starkli completions ``` ```shell starkli completions fish ``` -------------------------------- ### Initialize Scarb Project Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/tutorials/starkli-101.md Creates a new Scarb project directory and navigates into it. This is the first step in setting up a Cairo smart contract project. ```console mkdir my_contract cd ./my_contract/ scarb init ``` -------------------------------- ### Initialize Starkli Account Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/tutorials/starkli-101.md Initializes a new Starknet account using a specified account class (e.g., OpenZeppelin) and saves the account configuration to a file. This command assumes the STARKNET_KEYSTORE environment variable is already set. ```shell $ starkli account oz init /path/to/account.json ``` -------------------------------- ### Deploy Starknet Contract Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/tutorials/starkli-101.md Deploys an instance of a Starknet contract. Requires the class hash and constructor arguments. The `--watch` flag monitors the deployment status. Argument resolution (e.g., `str:starkli`) can simplify input. ```APIDOC starkli deploy Deploys a contract instance. Parameters: CLASS_HASH: The hash of the contract class to deploy. CTOR_ARGS: Constructor arguments for the contract. Options: --watch: Monitor the deployment process. Example: $ starkli deploy --watch 0x0756ea65987892072b836b9a56027230bbe8fbed5e0370cff22778d071a0798e str:starkli Notes: Constructor arguments can be provided directly or using argument resolution like `str:value` for strings. ``` -------------------------------- ### Initialize Starkli Signer Keystore Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/tutorials/starkli-101.md Creates a new pair of cryptographic keys for signing Starknet transactions and saves them to a keystore file. Requires a password for encryption. This is the first step in preparing to interact with the Starknet network. ```shell $ starkli signer keystore new /path/to/key.json ``` -------------------------------- ### Deploy Starknet Account Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/tutorials/starkli-101.md Deploys the initialized Starknet account to the Starknet network. The command calculates the estimated deployment fee and requires the account address to be pre-funded with ETH before proceeding with the deployment transaction. ```shell $ starkli account deploy /path/to/account.json ``` -------------------------------- ### Configure Scarb.toml for Starknet Contract Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/tutorials/starkli-101.md Updates the Scarb manifest file to include the `starknet` dependency and define a `starknet-contract` target, essential for Starknet development. ```toml [package] name = "my_contract" version = "0.1.0" [dependencies] starknet = "=2.1.0" [[target.starknet-contract]] ``` -------------------------------- ### Create Keystore - Starkli Signer Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/signers.md Creates a new encrypted keystore file at the specified path. This keystore can be used with Starkli commands by referencing its path via the `--keystore` option or the `STARKNET_KEYSTORE` environment variable. A password is required during creation and for subsequent use. ```console starkli signer keystore new /path/to/keystore ``` -------------------------------- ### Cairo Contract Source Code Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/tutorials/starkli-101.md Defines a simple Starknet contract with `name_get` and `name_set` functions, storage, events, and a constructor. This code uses the Starknet Cairo syntax. ```rust // ** ./src/lib.cairo ** #[starknet::interface] trait MyContractInterface { fn name_get(self: @T) -> felt252; fn name_set(ref self: T, name: felt252); } #[starknet::contract] mod my_contract { #[storage] struct Storage { name: felt252, } #[event] #[derive(Drop, starknet::Event)] enum Event { NameChanged: NameChanged, } #[derive(Drop, starknet::Event)] struct NameChanged { previous: felt252, current: felt252, } #[constructor] fn constructor(ref self: ContractState, name: felt252) { self.name.write(name); } #[external(v0)] impl MyContract of super::MyContractInterface { fn name_get(self: @ContractState) -> felt252 { self.name.read() } fn name_set(ref self: ContractState, name: felt252) { let previous = self.name.read(); self.name.write(name); self.emit(NameChanged { previous, current: name }); } } } ``` -------------------------------- ### Set Starknet Keystore Environment Variable Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/tutorials/starkli-101.md Sets the STARKNET_KEYSTORE environment variable to point to the location of the encrypted private key file. This allows subsequent starkli commands to automatically use the specified keystore without needing to pass the path explicitly. ```shell export STARKNET_KEYSTORE="/path/to/key.json" ``` -------------------------------- ### Starkli CLI Commands Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/ref/commands.md Starkli is a command-line interface for interacting with StarkNet. This documentation entry lists the primary commands available. For detailed usage, parameters, and options, append the --help flag to any command (e.g., starkli selector --help). ```APIDOC Starkli CLI Commands: - selector - Description: Retrieves the selector for a given Cairo function name. - Usage: starkli selector - class-hash - Description: Computes the class hash for a given Cairo contract artifact. - Usage: starkli class-hash - to-cairo-string - Description: Converts a given value into its Cairo string representation. - Usage: starkli to-cairo-string - parse-cairo-string - Description: Parses a Cairo string representation back into a value. - Usage: starkli parse-cairo-string - mont - Description: Performs Montgomery multiplication, often used in cryptographic operations. - Usage: starkli mont - call - Description: Calls a function on a StarkNet contract. - Usage: starkli call [arguments...] - transaction - Description: Retrieves details of a specific transaction. - Usage: starkli transaction - block-number - Description: Gets the current block number. - Usage: starkli block-number - block-hash - Description: Gets the hash of a specific block. - Usage: starkli block-hash - block - Description: Retrieves full details of a specific block. - Usage: starkli block - block-time - Description: Gets the timestamp of a specific block. - Usage: starkli block-time - state-update - Description: Retrieves state updates for a given block. - Usage: starkli state-update - transaction-receipt - Description: Retrieves the receipt for a specific transaction. - Usage: starkli transaction-receipt - chain-id - Description: Gets the current chain ID. - Usage: starkli chain-id - balance - Description: Gets the balance of a specific account. - Usage: starkli balance - nonce - Description: Gets the nonce for a specific account. - Usage: starkli nonce - storage - Description: Reads a storage slot from a contract. - Usage: starkli storage - class-hash-at - Description: Gets the class hash of a contract deployed at a specific address. - Usage: starkli class-hash-at - class-by-hash - Description: Retrieves contract class definition by its hash. - Usage: starkli class-by-hash - class-at - Description: Retrieves contract class definition deployed at a specific address. - Usage: starkli class-at - syncing - Description: Checks if the StarkNet node is currently syncing. - Usage: starkli syncing - signer - Description: Manages Starkli's signing keys and accounts. - Usage: starkli signer - account - Description: Manages Starkli's accounts, including deployment and configuration. - Usage: starkli account - invoke - Description: Invokes a function on a StarkNet contract, sending a transaction. - Usage: starkli invoke [arguments...] - declare - Description: Declares a contract class to StarkNet. - Usage: starkli declare [account_options...] - deploy - Description: Deploys a contract class to StarkNet. - Usage: starkli deploy [constructor_calldata...] [account_options...] - completions - Description: Generates shell completion scripts for Starkli. - Usage: starkli completions ``` -------------------------------- ### Build Cairo Contract with Scarb Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/tutorials/starkli-101.md Compiles the Cairo smart contract project using Scarb. This command generates the contract artifact, including the Sierra class JSON file. ```console scarb build ``` -------------------------------- ### Set Starknet Account Environment Variable Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/tutorials/starkli-101.md Sets the STARKNET_ACCOUNT environment variable to the path of the account configuration file. This enables starkli commands to automatically use the specified account for transaction signing and network interaction. ```shell export STARKNET_ACCOUNT="/path/to/account.json" ``` -------------------------------- ### Simplify Invoke with Addr Scheme Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/invoking-contracts.md Shows how to simplify contract invocation by using the `addr` scheme to reference known contract addresses, such as the ETH contract, making commands more readable. ```console starkli invoke addr:eth transfer 0x1234 100 0 ``` -------------------------------- ### Set Starknet Ledger Path Env Var Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/ledger.md Simplify Starkli commands by setting the `STARKNET_LEDGER_PATH` environment variable. This avoids repeatedly specifying the `--ledger-path` for every command. ```shell export STARKNET_LEDGER_PATH="m//starknet'/starkli'/0'/0'/0" ``` -------------------------------- ### Set STARKNET_KEYSTORE Env Var - Starkli Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/signers.md Sets the `STARKNET_KEYSTORE` environment variable to point to an encrypted keystore file. This allows Starkli to automatically use the specified keystore for commands without needing the `--keystore` option, unless overridden by a command-line argument. ```console export STARKNET_KEYSTORE="/path/to/keystore" ``` -------------------------------- ### Use Predefined Network (CLI) Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/providers.md Connect to a Starknet network by specifying a predefined network identifier (e.g., 'mainnet', 'sepolia') using the `--network` flag. Starkli will look up the provider settings for this network in the active profile. ```console starkli block-number --network mainnet ``` -------------------------------- ### Starkli Declare Command Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/tutorials/starkli-101.md Declares a compiled Cairo contract class (Sierra JSON) to the Starknet network using Starkli. The `--watch` flag monitors the transaction status. ```APIDOC starkli declare --watch Description: Declares a contract class to the Starknet network. Parameters: --watch: Monitor the declaration transaction status. : Path to the compiled contract's Sierra JSON artifact. Returns: The declared class hash. Notes: - If the class hash already exists, Starkli will not send a new declaration transaction. - To obtain the class hash separately, use `starkli class-hash `. Example: starkli declare --watch ./target/dev/my_contract_my_contract.sierra.json ``` -------------------------------- ### Convert String to Cairo Short String Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/tutorials/starkli-101.md Converts a given string into its Cairo short string representation, which is a common format for passing string arguments to Starknet contracts. ```APIDOC starkli to-cairo-string Converts a string to its Cairo short string hexadecimal representation. Parameters: STRING: The input string to convert. Returns: The hexadecimal representation of the Cairo short string. Example: $ starkli to-cairo-string starkli 0x737461726b6c69 ``` -------------------------------- ### Starkli EIP-2645 Echo Command Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/eip-2645-hd-paths.md Shows how to use the `starkli eip2645 echo` command to convert Starkli's extended path format into the standard, universally accepted EIP-2645 path. This is useful for interoperability. ```console starkli eip2645 echo "m//starknet'/starkli'/0'/0'/5" # Output: # m/2645'/1195502025'/1470455285'/0'/0'/5 ``` -------------------------------- ### Starkli Deploy Command Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/deploying-contracts.md The `starkli deploy` command is used to deploy instances of a declared contract class. It requires the class hash and any necessary constructor arguments. This command assumes a configured signer and account are available. ```APIDOC starkli deploy - Deploys a contract instance. - Requires a class hash and constructor arguments. - Prerequisites: A configured signer and account. - Underlying mechanism: Sends an INVOKE transaction to the Universal Deployer Contract. - Parameters: - CLASS_HASH: The hash of the contract class to deploy. - CTOR_ARGS: Constructor arguments for the contract, if any. Argument resolution can simplify input. ``` -------------------------------- ### Use Predefined Network (Environment Variable) Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/providers.md Configure the Starknet network identifier by setting the `STARKNET_NETWORK` environment variable. This allows subsequent Starkli commands to connect to the specified network without needing to pass the `--network` flag each time. ```bash export STARKNET_NETWORK="mainnet" starkli block-number ``` -------------------------------- ### Starkli Ledger API Documentation Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/ledger.md API commands for interacting with the Starknet Ledger app via Starkli. These commands allow checking the app version and retrieving public keys for account paths, with options for on-device confirmation. ```APIDOC Starkli Ledger Commands: app-version Description: Retrieves the version of the Starknet Ledger app currently installed and running. Usage: starkli ledger app-version Parameters: None Returns: string: The version number of the Starknet Ledger app (e.g., "1.1.1"). Notes: The Starknet Ledger app must be launched on the device for this command to succeed. get-public-key [--no-display] Description: Retrieves the public key associated with a specific Starknet account path. Usage: starkli ledger get-public-key "m//starknet'/starkli'/0'/0'/0" starkli ledger get-public-key "m//starknet'/starkli'/0'/0'/0" --no-display Parameters: path (string, required): The EIP-2645 HD path for the desired Starknet account. --no-display (flag, optional): If present, disables the on-device confirmation prompt for displaying the public key on the Ledger screen. Returns: string: The public key corresponding to the provided path. Notes: By default, the public key is displayed on the Ledger device for manual confirmation. Using --no-display bypasses this security step. ``` -------------------------------- ### RPC Provider Shorthand Configuration Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/profiles.md A simplified way to configure the RPC provider by directly specifying the endpoint URL as a string. This is equivalent to the object notation with `type = "rpc"` and the URL. ```toml [default.networks.mainnet] chain_id = "SN_MAIN" provider = "https://example.com/" ``` -------------------------------- ### Starkli Account Management Commands Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/accounts.md Manages Starknet accounts, including initialization, deployment, and fetching. Requires appropriate signers and network providers for certain operations. ```APIDOC starkli account init - Initializes an account file for a specific variant. - Requires a signer, often configured via STARKNET_KEYSTORE environment variable. - Parameters: - VARIANT: The identifier of the account variant (e.g., 'argent', 'braavos', 'oz'). - PATH: The file path where the account configuration will be saved. - Example: starkli account oz init /path/to/account starkli account deploy - Deploys the account contract to the Starknet network. - Requires the same signer used during initialization and a configured network provider. - The command estimates the deployment fee and requires the account to be funded before proceeding. - Parameters: - PATH: The path to the account file to deploy. - Example: starkli account deploy /path/to/account - Output Example: The estimated account deployment fee is 0.000011483579723913 ETH. However, to avoid failure, fund at least: 0.000017225369585869 ETH to the following address: 0x01cf4d57ba01109f018dec3ea079a38fc08b789e03de4df937ddb9e8a0ff853a Press [ENTER] once you've funded the address. starkli account fetch
--output - Recreates an account file from on-chain data using the provided account address. - Useful for recovering lost account files or migrating accounts. - Parameters: - ADDRESS: The Starknet address of the account to fetch. - --output PATH: The file path where the fetched account configuration will be saved. - Example: starkli account fetch 0x01cf4d57ba01109f018dec3de4df937ddb9e8a0ff853a --output /path/to/account ``` -------------------------------- ### Simplify Invoke with U256 Scheme Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/invoking-contracts.md Illustrates using the `u256` scheme to automatically handle the conversion of large numbers into the required two field elements for `u256` types, simplifying argument entry. ```console starkli invoke eth transfer 0x1234 u256:100 ``` -------------------------------- ### Simplify Invoke with Scheme Omission Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/invoking-contracts.md Further simplifies commands by omitting the `addr:` prefix when the address is the first positional argument, leveraging Starkli's argument resolution. ```console starkli invoke eth transfer 0x1234 100 0 ``` -------------------------------- ### Invoke Starknet Tx with Ledger Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/ledger.md Use Ledger as a signer for Starknet accounts to initialize, deploy, declare, or invoke contracts. Requires the `--ledger-path` option pointing to the HD path on the Ledger device. The transaction is sent after approval on the Ledger. ```console starkli invoke --ledger-path "m//starknet'/starkli'/0'/0'/0" eth transfer 0x1234 u256:100 -w ``` -------------------------------- ### Use RPC URL Directly (Environment Variable) Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/providers.md Configure the Starknet JSON-RPC endpoint by setting the `STARKNET_RPC` environment variable. This allows subsequent Starkli commands to use the specified RPC URL without needing to pass the `--rpc` flag each time. ```bash export STARKNET_RPC="http://localhost:9545/" starkli block-number ``` -------------------------------- ### Generate Keypair - Starkli Signer Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/signers.md Generates a new public/private key pair. The private key can be used directly with Starkli commands via the `--private-key` option or the `STARKNET_PRIVATE_KEY` environment variable. This method is intended for development purposes only due to security concerns. ```console starkli signer gen-keypair ``` -------------------------------- ### Use RPC URL Directly (CLI) Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/providers.md Connect to a Starknet network by providing a JSON-RPC endpoint URL directly to the command using the `--rpc` flag. This method is suitable for one-off commands or when you need to specify a custom RPC endpoint. ```console starkli block-number --rpc http://localhost:9545/ ``` -------------------------------- ### Set STARKNET_PRIVATE_KEY Env Var - Starkli Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/signers.md Sets the `STARKNET_PRIVATE_KEY` environment variable to use a plain text private key for Starkli commands. This simplifies command invocation but is highly insecure and not recommended for production use. Starkli will display a warning when this method is used. ```console export STARKNET_PRIVATE_KEY= ``` -------------------------------- ### Basic Starkli Invoke Command Syntax Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/invoking-contracts.md The fundamental structure for invoking a contract using Starkli. It requires the contract's address, the function selector, and any necessary arguments. ```console starkli invoke
``` -------------------------------- ### Call Contract Method (Read State) Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/tutorials/starkli-101.md Calls a view function on a deployed Starknet contract to read its state. This operation does not modify the contract's state. ```APIDOC starkli call [ARGS...] Calls a view method on a deployed contract. Parameters: CONTRACT_ADDRESS: The address of the deployed contract. METHOD_NAME: The name of the view function to call. ARGS: Optional arguments for the method. Returns: The result of the view function call, typically in JSON format. Example: $ starkli call 0x06d8e1f3ed72fc87aa896639a0f50a4b9e59adb24de8a42b477957e1a7996e1b name_get [ "0x00000000000000000000000000000000000000000000000000737461726b6c69" ] ``` -------------------------------- ### RPC Provider Configuration with Headers Source: https://github.com/xjonathanlei/starkli/blob/master/book/src/profiles.md Defines a network using the RPC provider with custom HTTP headers. This configuration specifies the network's chain ID and the RPC endpoint URL, along with an API key header. ```toml [default.networks.mainnet] chain_id = "SN_MAIN" provider = { type = "rpc", url = "https://example.com/", headers = [ { name = "Api-Key", value = "xxxx" } ] } ```