|
| 1 | +# Extrinsics |
| 2 | +`cargo-contract` provides CLI support for uploading, instantiating and calling your contracts directly from the command |
| 3 | +line. |
| 4 | + |
| 5 | +## Common arguments |
| 6 | + |
| 7 | +``` |
| 8 | +--suri |
| 9 | +``` |
| 10 | +The Secret URI used for signing the extrinsic. For development chains, the well known endowed accounts can be used e.g. |
| 11 | +`//Alice`. For other accounts, the actual secret key must be provided e.g. an `0x` prefixed 64 bit hex string, or the |
| 12 | +seed phrase. See usage of [`subkey`](https://docs.substrate.io/v3/tools/subkey/) for examples, and docs for the expected |
| 13 | +values in the [parsing code](https://docs.rs/sp-core/latest/sp_core/crypto/trait.Pair.html#method.from_string_with_seed). |
| 14 | + |
| 15 | +:warning: **WARNING** :warning: |
| 16 | + |
| 17 | +It is strongly recommended NOT to use secret keys from actual value bearing chains on the command line, since they are |
| 18 | +visible on screen and are often saved to the command line shell's history. For now this tool should only be used for |
| 19 | +development and testnets. It is a priority to implement a safer method of signing here before using this tool with value |
| 20 | +bearing chains. |
| 21 | + |
| 22 | +``` |
| 23 | +--password |
| 24 | +``` |
| 25 | +*Optional*. The password for the `--suri`, see https://docs.substrate.io/v3/tools/subkey/#password-protected-keys. |
| 26 | + |
| 27 | +``` |
| 28 | +--manifest-path |
| 29 | +``` |
| 30 | +*Optional*. The path to the `Cargo.toml` of the contract crate. Use this to run commands on a contract from outside of |
| 31 | +its project directory. |
| 32 | + |
| 33 | +``` |
| 34 | +--url |
| 35 | +``` |
| 36 | +*Optional*. The websockets url of an RPC node on the target chain. Defaults to a locally running node at |
| 37 | +"ws://localhost:9944". |
| 38 | + |
| 39 | +``` |
| 40 | +---dry-run |
| 41 | +``` |
| 42 | +*Optional*. All extrinsic commands can be run without altering the chain state. Useful for testing if a command will be |
| 43 | +successful, estimating gas costs or querying the result of `ink!` readonly messages. |
| 44 | + |
| 45 | +``` |
| 46 | +--storage-deposit-limit |
| 47 | +``` |
| 48 | +*Optional*. The maximum amount of balance that can be charged from the caller to pay for the storage consumed. |
| 49 | + |
| 50 | +## Commands |
| 51 | + |
| 52 | +### `upload` |
| 53 | + |
| 54 | +Upload the Wasm code of the contract to the target chain. Invokes the [`upload_code`](https://github.com/paritytech/substrate/blob/master/frame/contracts/src/lib.rs#L509) |
| 55 | +dispatchable. |
| 56 | + |
| 57 | +e.g. `cargo contract upload --suri //Alice` |
| 58 | + |
| 59 | +Assumes that `cargo contract build` has already been run to produce the contract artifacts. |
| 60 | + |
| 61 | +### `instantiate` |
| 62 | + |
| 63 | +Create an instance of a contract on chain. If the code has already been uploaded via `upload`, specify the resulting |
| 64 | +`--code-hash` which will result in a call to [`instantiate`](https://github.com/paritytech/substrate/blob/master/frame/contracts/src/lib.rs#L460). |
| 65 | +If no `--code-hash` is specified it will attempt to both upload the code and instantiate via the |
| 66 | +[`instantiate_with_code`](https://github.com/paritytech/substrate/blob/master/frame/contracts/src/lib.rs#L419) |
| 67 | +dispatchable. |
| 68 | + |
| 69 | +e.g. |
| 70 | +``` |
| 71 | +cargo contract instantiate \ |
| 72 | + --constructor new \ |
| 73 | + --args false \ |
| 74 | + --suri //Alice \ |
| 75 | + --code-hash 0xbc1b42256696c8a4187ec3ed79fc602789fc11287c4c30926f5e31ed8169574e |
| 76 | +``` |
| 77 | +- `--constructor` the name of the contract constructor method to invoke. |
| 78 | +- `--args` accepts a space separated list of values, encoded in order as the arguments of the constructor to invoke. |
| 79 | +- `--code-hash` the hash of the uploaded code, returned from a call to `contract upload` or a previous |
| 80 | +`contract instantiate` |
| 81 | + |
| 82 | +### `call` |
| 83 | + |
| 84 | +Invoke a message on an instance of a contract via the [`call`](https://github.com/paritytech/substrate/blob/master/frame/contracts/src/lib.rs#L359) |
| 85 | +dispatchable. |
| 86 | + |
| 87 | +e.g. |
| 88 | +``` |
| 89 | +cargo contract call \ |
| 90 | + --contract 5FKy7RwXBCCACCEPjM5WugkhUd787FjdgieTkdj7TPngJzxN \ |
| 91 | + --message transfer \ |
| 92 | + --args 5FKy7RwXBCCACCEPjM5WugkhUd787FjdgieTkdj7TPngJzxN 1000 \ |
| 93 | + --suri //Alice |
| 94 | +``` |
| 95 | + |
| 96 | +- `--contract` the account id of the contract to invoke, returned after a successful `contract instantiate`. |
| 97 | +- `--message` the name of the contract message to invoke. |
| 98 | +- `--args` accepts a space separated list of values, encoded in order as the arguments of the message to invoke. |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | + |
0 commit comments