Setup Cargo Project
In this section, we'll create a new Cargo project to serve as the front-end application for interacting with the counter contract. Follow the steps below to set up your project and include the necessary dependencies.
Step 1: Create a New Cargo Project
Run the following command from the root directory of your counter project to create a new Cargo project:
cargo new --lib counter-app
Your project structure should now look like this:
counter/
├── contract
│ ├── out
│ │ └── debug
│ │ ├── counter-abi.json
│ │ └── counter.json
│ ├── pint.toml
│ └── src
│ └── contract.pnt
└── counter-app
├── Cargo.toml
└── src
└── lib.rs
Step 2: Add Dependencies
Now, add the necessary dependencies to your Rust project by running the following command:
cd counter-app
cargo add anyhow
cargo add clap --features derive
cargo add essential-app-utils
cargo add essential-hash
cargo add essential-rest-client
cargo add essential-types
cargo add pint-abi
cargo add tokio --features full
cargo add essential-app-utils --features test-utils --dev
cargo add essential-builder --dev
cargo add essential-builder-db --dev
cargo add essential-node --dev
cargo add serde_json --dev
Your Cargo.toml
file should now look like this:
[package]
name = "counter-app"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1.0.93"
clap = { version = "4.5.21", features = ["derive"] }
essential-app-utils = "0.6.0"
essential-hash = "0.7.0"
essential-rest-client = "0.6.0"
essential-types = "0.5.0"
pint-abi = "0.6.0"
tokio = { version = "1.41.1", features = ["full"] }
[dev-dependencies]
essential-app-utils = { version = "0.6.0", features = ["test-utils"] }
essential-builder = "0.10.0"
essential-builder-db = "0.5.0"
essential-node = "0.8.0"
serde_json = "1.0.132"
Step 3: Add a Test
Lastly, add a test to your front-end application by using the following command:
mkdir tests
touch tests/counter.rs
After adding the test, your project structure should look like this:
counter
├── contract
│ ├── out
│ │ └── debug
│ │ ├── counter-abi.json
│ │ └── counter.json
│ ├── pint.toml
│ └── src
│ └── contract.pnt
└── counter-app
├── Cargo.lock
├── Cargo.toml
├── src
│ └── lib.rs
└── tests
└── counter.rs
At this point, your Rust project is set up with all the necessary dependencies, and a basic test has been added to your front-end application.