# Blockchain CLI
## Reference implementation
[](https://github.com/slavik-pastushenko/blockchain-rust/actions/workflows/test.yml)
[](https://docs.rs/blockchain-cli)
[](https://crates.io/crates/blockchain-cli)



A Rust library provides a command-line interface (CLI) for interacting with blockchain.
## Features
- Create a blockchain
- Add a transaction
- Get a transaction
- Get all transactions
- Generate a block
- Change a reward
- Change a difficulty
## Usage
Run the following Cargo command in your project directory::
```bash
cargo add blockchain-cli
```

```rust
extern crate blockchain;
use blockchain::Chain;
fn main() {
// Initialise a new blockchain
let mut chain = Chain::new(
String::from("bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh"),
2,
100.0
);
// Add a transaction
chain.add_transaction(
String::from("mxwgXGHxtjmGJ1cFebRW9emcV2vV1aPGfk"),
String::from("n2zet2T3KNRjD69oF9ZquLsigH1ZBJcraR"),
1.25
);
// Get a transaction
let transaction = chain.get_transaction(
String::from("6e8c5dc01145016e5a979683ba7e13bafaf85e765490aa33c0bba1f41cf581ed")
);
match transaction {
Some(trx) => println!("📦 Transaction: {:?}", trx),
None => println!("❌ Transaction was not found"),
}
// Get all transactions
let transactions = chain.get_transactions();
println!("📦 Transactions: {:?}", transactions);
// Others
}
```
## Contributing
- Build an application:
```bash
cargo build
```
- Test an application:
```bash
cargo test
```
- Run an application:
```bash
cargo run
```
- Generate documentation in HTML format:
```bash
cargo doc --open
```