### Get Read Proof Example Source: https://github.com/use-ink/cargo-contract/blob/master/docs/rpc.md Example of fetching a read proof using `state_getReadProof`. Demonstrates passing a storage key as a parameter. ```bash cargo contract rpc state_getReadProof \ '(0x4b9cce91a924c0f4d469b3d62e02f9682079560c6cfc45c1a9498812dfff4b3a)' ``` -------------------------------- ### Insert Key Example Source: https://github.com/use-ink/cargo-contract/blob/master/docs/rpc.md Example of inserting a key using the `author_insertKey` RPC method. Demonstrates providing parameters like the key type, account, and a nonce. ```bash cargo contract rpc author_insertKey '"sr25"' '"//ALICE"' \ 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY ``` -------------------------------- ### Install cargo-contract Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Installs the cargo-contract CLI tool, including necessary Rust components and optional dependencies like dylint for linting. ```bash rustup component add rust-src cargo install --force --locked cargo-contract # For linting: export TOOLCHAIN_VERSION=nightly-2024-09-05 rustup install $TOOLCHAIN_VERSION rustup component add rust-src --toolchain $TOOLCHAIN_VERSION rustup run $TOOLCHAIN_VERSION cargo install cargo-dylint dylint-link ``` -------------------------------- ### Install cargo-contract Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Installs the cargo-contract CLI tool, including necessary Rust components and optional dependencies like dylint for linting. ```bash rustup component add rust-src cargo install --force --locked cargo-contract # For linting: export TOOLCHAIN_VERSION=nightly-2024-09-05 rustup install $TOOLCHAIN_VERSION rustup component add rust-src --toolchain $TOOLCHAIN_VERSION rustup run $TOOLCHAIN_VERSION cargo install cargo-dylint dylint-link ``` -------------------------------- ### Install and Use cargo-contract with Docker Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Provides instructions for pulling the Docker image and using it to create and build ink! smart contracts, ensuring a consistent build environment. ```bash # Pull the latest stable image. docker pull paritytech/contracts-ci-linux # Create a new contract in your current directory. docker run --rm -it -v $(pwd):/sources paritytech/contracts-ci-linux \ cargo contract new --target-dir /sources my_contract # Build the contract. docker run --rm -it -v $(pwd):/sources paritytech/contracts-ci-linux \ cargo contract build --manifest-path=/sources/my_contract/Cargo.toml # Windows PowerShell equivalent for creating a contract: docker run --rm -it -v ${pwd}:/sources paritytech/contracts-ci-linux \ cargo contract new --target-dir /sources my_contract ``` -------------------------------- ### Get Help for cargo-contract Commands Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Displays help information for available commands and their parameters. Use the --help flag for specific command details. ```bash cargo contract help cargo contract new --help ``` -------------------------------- ### Install and Use cargo-contract with Docker Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Provides instructions for pulling the Docker image and using it to create and build ink! smart contracts, ensuring a consistent build environment. ```bash # Pull the latest stable image. docker pull paritytech/contracts-ci-linux # Create a new contract in your current directory. docker run --rm -it -v $(pwd):/sources paritytech/contracts-ci-linux \ cargo contract new --target-dir /sources my_contract # Build the contract. docker run --rm -it -v $(pwd):/sources paritytech/contracts-ci-linux \ cargo contract build --manifest-path=/sources/my_contract/Cargo.toml # Windows PowerShell equivalent for creating a contract: docker run --rm -it -v ${pwd}:/sources paritytech/contracts-ci-linux \ cargo contract new --target-dir /sources my_contract ``` -------------------------------- ### Check Key Existence Example Source: https://github.com/use-ink/cargo-contract/blob/master/docs/rpc.md Example of checking if a key exists using the `author_hasKey` RPC method. Shows how to provide the account's SS58 address. ```bash cargo contract rpc author_hasKey 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY '"sr25"' \ ``` -------------------------------- ### Create a New ink! Smart Contract Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Initializes a new ink! smart contract project with basic scaffolding code. The example contract provided is 'Flipper', a simple contract that toggles a boolean value. ```bash cargo contract new my_contract ``` -------------------------------- ### Get Next Account Index Example Source: https://github.com/use-ink/cargo-contract/blob/master/docs/rpc.md Example of retrieving the next account index using `system_accountNextIndex`. Requires the account's SS58 address in string format. ```bash cargo contract rpc system_accountNextIndex \ '"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"' ``` -------------------------------- ### Get Help for cargo-contract Commands Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Displays help information for available commands and their parameters. Use the --help flag for specific command details. ```bash cargo contract help cargo contract new --help ``` -------------------------------- ### Create a New ink! Smart Contract Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Initializes a new ink! smart contract project with basic scaffolding code. The example contract provided is 'Flipper', a simple contract that toggles a boolean value. ```bash cargo contract new my_contract ``` -------------------------------- ### Build ink! Smart Contract - Rust Source: https://github.com/use-ink/cargo-contract/blob/master/crates/build/README.md Demonstrates how to use the `contract_build` crate to execute a build process for an ink! smart contract. It shows the setup of `ExecuteArgs` with various configuration options like manifest path, verbosity, build mode, features, network, artifacts, and output type. ```rust use contract_build::{ ManifestPath, Verbosity, BuildArtifacts, BuildMode, Features, MetadataSpec, Network, OutputType, UnstableFlags, Target, ImageVariant, }; let manifest_path = ManifestPath::new("my-contract/Cargo.toml").unwrap(); let args = contract_build::ExecuteArgs { manifest_path, verbosity: Verbosity::Default, build_mode: BuildMode::Release, features: Features::default(), network: Network::Online, build_artifact: BuildArtifacts::All, unstable_flags: UnstableFlags::default(), keep_debug_symbols: false, extra_lints: false, output_type: OutputType::Json, image: ImageVariant::Default, metadata_spec: Some(MetadataSpec::Ink), target_dir: None, }; contract_build::execute(args); ``` -------------------------------- ### Get Contract Info Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Fetches and displays information about a smart contract deployed on the chain. ```rust cargo contract info ``` -------------------------------- ### Get Contract Storage Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Fetches and displays the storage contents of a smart contract on the chain. ```rust cargo contract storage ``` -------------------------------- ### cargo-contract Decode Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Decodes a contract's input or output data, such as events or message invocations. Input must be hex-encoded, starting with '0x'. ```rust cargo contract decode ``` -------------------------------- ### Decode Contract Data Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Decodes contract input or output data, such as events, messages, or constructor invocations. Input must be hex-encoded, starting with '0x'. ```rust cargo contract decode ``` -------------------------------- ### Run Docker Container for Contract Build Source: https://github.com/use-ink/cargo-contract/blob/master/build-image/README.md Demonstrates how to run the Docker container, mounting the current directory as the contract workspace, to perform a build. ```bash docker run -d \ --name ink-container \ --mount type=bind,source="$(pwd)",target="/contract" \ useink/contracts-verifiable ``` -------------------------------- ### Build Docker Image with Specific Cargo Contract Version Source: https://github.com/use-ink/cargo-contract/blob/master/build-image/README.md Shows how to build a local Docker image for the verifiable build process, specifying a particular version of cargo-contract. ```bash docker buildx build -t useink/contracts-verifiable:0.0.1-local --build-arg CARGO_CONTRACT_VERSION=6.0.0-alpha . ``` -------------------------------- ### cargo-contract Build Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Compiles a smart contract into a PolkaVM binary, generates metadata, and bundles them into a .contract file for on-chain deployment. ```rust cargo contract build ``` -------------------------------- ### Build Contract Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Compiles a smart contract into a PolkaVM binary, generates metadata, and bundles them into a .contract file for on-chain deployment. ```rust cargo contract build ``` -------------------------------- ### Run Docker Container for Debugging Source: https://github.com/use-ink/cargo-contract/blob/master/build-image/README.md Provides instructions to run the Docker container interactively with a bash shell, allowing for debugging and inspection of the build environment. ```bash docker container run \ -it --rm --entrypoint /bin/bash \ --mount type=bind,source="$(pwd)",target="/contract" \ useink/contracts-verifiable:0.0.1-local ``` -------------------------------- ### Instantiate Contract Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Creates a new instance of a smart contract on the blockchain. ```rust cargo contract instantiate ``` -------------------------------- ### Common Arguments for cargo-contract Source: https://github.com/use-ink/cargo-contract/blob/master/crates/extrinsics/README.md Details common arguments used across various cargo-contract commands for signing, configuration, and execution. Includes options like --suri for signing, --password for protected keys, --manifest-path for specifying Cargo.toml, --url for RPC node connection, -x/--execute for on-chain execution, and --storage-deposit-limit for storage cost. ```bash --suri The Secret URI used for signing the extrinsic. For development chains, the well known endowed accounts can be used e.g. `//Alice`. For other accounts, the actual secret key must be provided e.g. an `0x` prefixed 64 bit hex string, or the seed phrase. See usage of [`subkey`](https://docs.substrate.io/reference/command-line-tools/subkey/) for examples, and docs for the expected values in the [parsing code](https://docs.rs/sp-core/latest/sp_core/crypto/trait.Pair.html#method.from_string_with_seed). :warning: **WARNING** :warning: It is strongly recommended NOT to use secret keys from actual value bearing chains on the command line, since they are visible on screen and are often saved to the command line shell's history. For now this tool should only be used for development and testnets. It is a priority to implement a safer method of signing here before using this tool with value bearing chains. --password *Optional*. The password for the `--suri`, see https://docs.substrate.io/reference/command-line-tools/subkey/#password-protected-keys. --manifest-path *Optional*. The path to the `Cargo.toml` of the contract crate. Use this to run commands on a contract from outside of its project directory. --url *Optional*. The websockets url of an RPC node on the target chain. Defaults to a locally running node at "ws://localhost:9944". -x/--execute *Optional*. All extrinsic commands run without altering the chain state by default. This flag specifies that the extrinsic needs to be executed on chain. --storage-deposit-limit *Optional*. The maximum amount of balance that can be charged from the caller to pay for the storage consumed. ``` -------------------------------- ### Verifiable Builds with cargo-contract Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Builds a smart contract using the provided Docker image to ensure deterministic compilation, which is often required by block explorers for source code verification. ```bash cargo contract build --verifiable ``` -------------------------------- ### Verifiable Builds with cargo-contract Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Builds a smart contract using the provided Docker image to ensure deterministic compilation, which is often required by block explorers for source code verification. ```bash cargo contract build --verifiable ``` -------------------------------- ### cargo-contract Instantiate Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Creates an instance of a contract on-chain. ```rust cargo contract instantiate ``` -------------------------------- ### cargo-contract instantiate extrinsic Source: https://github.com/use-ink/cargo-contract/blob/master/crates/extrinsics/README.md Creates an instance of a contract on the chain. It can either upload code and instantiate using `instantiate_with_code` or instantiate from existing uploaded code using `instantiate` by specifying `--code-hash`. Requires specifying the constructor and arguments. ```bash cargo contract instantiate \ --constructor new \ --args false \ --suri //Alice \ --code-hash 0xbc1b42256696c8a4187ec3ed79fc602789fc11287c4c30926f5e31ed8169574e - `--constructor` the name of the contract constructor method to invoke. - `--args` accepts a space separated list of values, encoded in order as the arguments of the constructor to invoke. - `--code-hash` the hash of the uploaded code, returned from a call to `contract upload` or a previous `contract instantiate` ``` -------------------------------- ### Specify Contract Artifact for Instantiate Source: https://github.com/use-ink/cargo-contract/blob/master/crates/extrinsics/README.md Instantiates a contract by directly specifying its artifact file path. This command is used when the contract is not in the current working directory. ```bash cargo instantiate ../path/to/mycontract.contract ``` -------------------------------- ### Generate Contract Schema Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Generates the contract's schema and prints it to standard output. ```rust cargo contract schema-generate ``` -------------------------------- ### Verify Contract Schema Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Verifies a metadata file or contract bundle against a schema file. ```rust cargo contract verify-schema ``` -------------------------------- ### cargo-contract upload extrinsic Source: https://github.com/use-ink/cargo-contract/blob/master/crates/extrinsics/README.md Uploads the contract binary to the target chain. This command invokes the `upload_code` dispatchable and assumes `cargo contract build` has been executed. ```bash cargo contract upload --suri //Alice ``` -------------------------------- ### cargo-contract Schema Generate Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Generates the schema for a contract and prints it to standard output. ```rust cargo contract schema-generate ``` -------------------------------- ### Fetch Contract Information Source: https://github.com/use-ink/cargo-contract/blob/master/docs/info.md Fetches and displays information for a specified contract using its account ID. Supports optional parameters for RPC URL, chain configuration, output format (JSON, binary), and retrieving all contract addresses. ```bash cargo contract info \ --contract 5DVGLfDGBvqMr9nCg48g99oD8Mz3sruWmb6ek5UbWvDnbTgZ --contract : The account ID of the instantiated contract to examine. --url : The URL of the RPC endpoint (default: ws://localhost:9944). --config : The chain configuration to use (default: Polkadot). --chain : The name of a production chain (conflicts with --url and --config). --output-json: Export output as JSON. --binary: Output the contract as a binary blob. If used with --output-json, outputs the contract's binary as a JSON object with a hex string. --all: Output all contract addresses. Cannot be used with --binary. ``` -------------------------------- ### Upload Contract Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Uploads a compiled smart contract to a chain that supports pallet-contracts. ```rust cargo contract upload ``` -------------------------------- ### cargo-contract Verify Schema Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Verifies a metadata file or contract bundle against a schema file. ```rust cargo contract verify-schema ``` -------------------------------- ### cargo-contract Upload Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Uploads a contract to a pallet-contracts enabled chain. ```rust cargo contract upload ``` -------------------------------- ### Verify Contract Binary Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Verifies if a given contract binary matches the build result of a specified workspace. ```rust cargo contract verify ``` -------------------------------- ### cargo-contract Verify Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Verifies that a given contract binary matches the build result of a specified workspace. ```rust cargo contract verify ``` -------------------------------- ### Cargo Contract Compatibility and Publishing Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Details compatibility requirements (Metadata V14+) and the process for publishing new versions of cargo-contract, including version bumping, dependency updates, and release tagging. ```APIDOC Metadata Version: V14+ Publishing Steps: 1. Bump all crate versions. 2. Execute `cargo update`. 3. Get PR approval. 4. Publish crates in order: metadata -> analyze -> transcode -> build -> extrinsics -> cargo-contract. 5. Tag release: `git tag -s vX.X.X && git push origin vX.X.X`. 6. Create GitHub release with changelog. ``` -------------------------------- ### RPC Command Options Source: https://github.com/use-ink/cargo-contract/blob/master/docs/rpc.md Optional flags that can be used with the `cargo contract rpc` command to configure the connection and output. ```bash --url Specify the RPC endpoint URL (default: ws://localhost:9944) --config Use a specific chain configuration (default: Polkadot) --chain Specify the production chain name (conflicts with --url and --config) --output-json Export the output in JSON format ``` -------------------------------- ### cargo-contract Info Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Fetches and displays information about a contract on-chain. ```rust cargo contract info ``` -------------------------------- ### Check Contract Build Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Checks if the smart contract code builds for PolkaVM without generating any artifacts. ```rust cargo contract check ``` -------------------------------- ### cargo-contract Storage Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Fetches and displays the storage of a contract on-chain. ```rust cargo contract storage ``` -------------------------------- ### Specify Contract Artifact for Call Source: https://github.com/use-ink/cargo-contract/blob/master/crates/extrinsics/README.md Calls a contract by specifying the contract artifact file path. This is an alternative to having the contract in the current working directory. ```bash cargo call ..path/to/mycontract.json ``` -------------------------------- ### cargo-contract RPC Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Invokes an RPC call to the node. ```rust cargo contract rpc ``` -------------------------------- ### cargo-contract Check Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Checks if the code builds for PolkaVM without generating a .contract artifact. ```rust cargo contract check ``` -------------------------------- ### Invoke RPC Call Source: https://github.com/use-ink/cargo-contract/blob/master/docs/rpc.md General syntax for invoking an RPC call to the node. Requires the method name and its parameters. ```bash cargo contract rpc [Options] METHOD [PARAMS] ``` -------------------------------- ### Invoke RPC Call Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Invokes an arbitrary RPC call to the connected node. ```rust cargo contract rpc ``` -------------------------------- ### Specify Contract Artifact for Upload Source: https://github.com/use-ink/cargo-contract/blob/master/crates/extrinsics/README.md Uploads a contract artifact by directly specifying its path. This is useful when the current working directory is not the contract's source code directory. ```bash cargo upload ../path/to/mycontract.polkavm ``` -------------------------------- ### Resolve Contract Account Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Maps an H160 contract address to its corresponding Substrate AccountId. ```rust cargo contract account ``` -------------------------------- ### cargo-contract Encode Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Encodes a contract's input calls and their arguments. ```rust cargo contract encode ``` -------------------------------- ### Encode Contract Data Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Encodes contract input calls and their arguments for transmission. ```rust cargo contract encode ``` -------------------------------- ### cargo-contract Call Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Invokes a message on an existing contract on-chain. ```rust cargo contract call ``` -------------------------------- ### cargo-contract Account Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Resolves an H160 contract address to its corresponding Substrate AccountId. ```rust cargo contract account ``` -------------------------------- ### cargo-contract call extrinsic Source: https://github.com/use-ink/cargo-contract/blob/master/crates/extrinsics/README.md Invokes a message on an existing contract instance using the `call` dispatchable. Requires the contract's account ID, the message name, and arguments. ```bash cargo contract call \ --contract 5FKy7RwXBCCACCEPjM5WugkhUd787FjdgieTkdj7TPngJzxN \ --message transfer \ --args 5FKy7RwXBCCACCEPjM5WugkhUd787FjdgieTkdj7TPngJzxN 1000 \ --suri //Alice - `--contract` the account id of the contract to invoke, returned after a successful `contract instantiate`. - `--message` the name of the contract message to invoke. - `--args` accepts a space separated list of values, encoded in order as the arguments of the message to invoke. ``` -------------------------------- ### Call Contract Message Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Invokes a specific message (function) on an existing smart contract instance on the chain. ```rust cargo contract call ``` -------------------------------- ### cargo-contract remove extrinsic Source: https://github.com/use-ink/cargo-contract/blob/master/crates/extrinsics/README.md Removes the contract binary from the target chain by invoking the `remove_code` dispatchable. This command requires that `cargo contract build` and `cargo contract upload` have been run. It will only succeed if no instances of the code exist, or if they have been terminated or had their code updated. ```bash cargo contract remove --suri //Alice Assumes that `cargo contract build` and `cargo contract upload` have already been run to produce the contract artifacts. This command will only succeed if there are no contract instances of this code. Contracts which have already been instantiated from this code must either `terminate` themselves or have their code changed via a `set_code` call to `pallet_revive`. ``` cargo contract remove \ --suri //Alice \ --code-hash 0xbc1b42256696c8a4187ec3ed79fc602789fc11287c4c30926f5e31ed8169574e ``` - `--code-hash` the hash of the uploaded code, returned from a call to `contract upload`. If not specified the code hash will be taken from the contract artifacts. ``` -------------------------------- ### Remove Contract Source: https://github.com/use-ink/cargo-contract/blob/master/README.md Removes a smart contract from a pallet-contracts enabled chain. ```rust cargo contract remove ``` -------------------------------- ### cargo-contract Remove Source: https://github.com/use-ink/cargo-contract/blob/master/crates/cargo-contract/README.md Removes a contract from a pallet-contracts enabled chain. ```rust cargo contract remove ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.