|
| 1 | +# stacks-cli |
| 2 | + |
| 3 | +A CLI for building and signing Stacks transactions and interacting with Clarity contracts. |
| 4 | + |
| 5 | +### Features |
| 6 | + |
| 7 | +* **Transaction Building:** |
| 8 | + * `publish`: Deploy Clarity smart contracts. |
| 9 | + * `contract-call`: Call public functions on deployed contracts. |
| 10 | + * `token-transfer`: Transfer STX between accounts. |
| 11 | +* **Key Management:** |
| 12 | + * `generate-sk`: Generate a new Stacks private key. |
| 13 | + * `addresses`: Derive Stacks and Bitcoin addresses from a private key. |
| 14 | +* **Decoding Helpers:** |
| 15 | + * `decode-tx`: Decode a hex-encoded transaction. |
| 16 | + * `decode-header`: Decode a hex-encoded block header. |
| 17 | + * `decode-block`: Decode a hex-encoded block. |
| 18 | + * `decode-microblock`: Decode a hex-encoded microblock. |
| 19 | + * `decode-microblocks`: Decode a hex-encoded stream of microblocks. |
| 20 | + |
| 21 | +### Build & Run |
| 22 | + |
| 23 | +```bash |
| 24 | +# Build the CLI |
| 25 | +cargo build -p stacks-cli |
| 26 | + |
| 27 | +# See top-level help |
| 28 | +cargo run -p stacks-cli -- --help |
| 29 | +``` |
| 30 | +*Note the extra `--` to pass flags to the binary instead of cargo.* |
| 31 | + |
| 32 | +### Global Options |
| 33 | +* `--testnet[=<chain-id>]` - Generate a transaction for the testnet. An optional custom chain ID can be provided in hex (e.g., `--testnet=0x12345678`). |
| 34 | + |
| 35 | +### Examples |
| 36 | + |
| 37 | +**Note:** All arguments are positional. |
| 38 | + |
| 39 | +```bash |
| 40 | +# Publish a contract on testnet |
| 41 | +cargo run -p stacks-cli -- --testnet publish <SENDER_PRIVATE_KEY> <FEE_RATE> <NONCE> <CONTRACT_NAME> <PATH_TO_CLARITY_FILE> |
| 42 | + |
| 43 | +# Call a contract function |
| 44 | +# Function arguments are passed using flags: -e (evaluate), -x (hex), or --hex-file |
| 45 | +cargo run -p stacks-cli -- contract-call <SENDER_PRIVATE_KEY> <FEE_RATE> <NONCE> <CONTRACT_ADDRESS> <CONTRACT_NAME> <FUNCTION_NAME> -e "'ST1...'" -e "u100" |
| 46 | + |
| 47 | +# Transfer STX (amount is in micro-STX, memo is optional) |
| 48 | +cargo run -p stacks-cli -- token-transfer <SENDER_PRIVATE_KEY> <FEE_RATE> <NONCE> <RECIPIENT_ADDRESS> <AMOUNT_USTX> "my memo" |
| 49 | + |
| 50 | +# Generate a new key and associated addresses |
| 51 | +cargo run -p stacks-cli -- generate-sk |
| 52 | + |
| 53 | +# Decode a hex-encoded transaction from a string or stdin |
| 54 | +cargo run -p stacks-cli -- decode-tx <HEX_ENCODED_TRANSACTION> |
| 55 | +``` |
| 56 | + |
| 57 | +See `--help` on each subcommand for complete options (e.g., `cargo run -p stacks-cli -- publish -h`). |
0 commit comments