# Get Started With Casper Submited by **@quentingosset** --- ### Step 1: Create and deploy a simple, smart contract with cargo casper and cargo test 1. Installing Rust - [x] Install Rust : `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh` ![](https://i.imgur.com/hNWE5ce.png) - [x] Check if rust is up to date : `rustup update && rustup --version` ![](https://i.imgur.com/NjLxB62.png) 2. Installing Dependencies - [x] Cmake : `sudo apt install cmake && cmake --version` ![](https://i.imgur.com/sFUUbEM.png) 3. Installing the Casper Crates - [x] Installing the Casper Crates : `cargo install cargo-casper` ![](https://i.imgur.com/0dUWIWC.png) 4. Creating a Project - [x] Create a new sample project : `cargo casper my-project` ![](https://i.imgur.com/5BIww4t.png) 5. Compiling to WASM (The Casper blockchain uses WebAssembly) - [x] Go into the contract folder : `cd my-project/contract/` ![](https://i.imgur.com/2zm0eDJ.png) - [x] Install the Rust toolchain : `rustup install $(cat rust-toolchain)` ![](https://i.imgur.com/qjbgl9u.png) - [x] Specify the target build as WebAssembly (wasm32) : `rustup target add --toolchain $(cat rust-toolchain) wasm32-unknown-unknown` ![](https://i.imgur.com/Yqo9evj.png) 6. Build the Contract - [x] Compile the smart contract into WASM : `cargo build --release` ![](https://i.imgur.com/aa6zakr.png) 7. Test the Contract - [x] Go into the test folder : `cd ../tests` ![](https://i.imgur.com/nHW2HkZ.png) - [x] Run the test : `cargo test` ![](https://i.imgur.com/9wYWeox.png) 8. Verifying the test - [x] Open the contract main.rs file : ![](https://i.imgur.com/P5aQuLs.png) - [x] Edit the KEY value `const KEY: &str = "special_value";` into `const KEY: &str = "new_value";` - [x] Re-run test and check if test is failed : `cargo test` ![](https://i.imgur.com/Vp3MFE0.png) ### Step 2: Complete one of the existing tutorials for writing smart contracts :::info [A Counter Contract Tutorial](https://docs.casperlabs.io/en/latest/dapp-dev-guide/tutorials/counter/index.html) ::: 1. Install NCTL ([More Info](https://docs.casperlabs.io/en/latest/dapp-dev-guide/setup-nctl.html)): 1.1. Installing a Virtual Environment - [x] Check python3 : `python3 --version` ![](https://i.imgur.com/mkXdaD2.png) - [x] Check pip : `sudo apt install python3-pip && pip --version` ![](https://i.imgur.com/b3vjd7I.png) - [x] Install PKG : `sudo apt install pkg-config` ![](https://i.imgur.com/1w23INb.png) - [x] Install LIBSSL : `sudo apt install libssl-dev` ![](https://i.imgur.com/fwwgKPM.png) - [x] Install gcc & g++ : `sudo apt install build-essential && gcc --version && g++ --version` ![](https://i.imgur.com/fpPMzN2.png) - [x] Create and activate a new virtual environment : `python3 -m venv env && source env/bin/activate` ![](https://i.imgur.com/LhdxcR0.png) - [x] Upgrade pip on virtual environnement : `pip install --upgrade pip` ![](https://i.imgur.com/vxcOqm6.png) - [x] Install jq,supervisor,toml : `pip install jq supervisor toml` ![](https://i.imgur.com/Nwuw7CG.png) 1.2. Setting up the Network - [x] Clone the casper-node-launcher software in your working directory : `cd work_directory/ && git clone https://github.com/casper-network/casper-node-launcher` ![](https://i.imgur.com/k1VJkuX.png) - [x] Clone the casper-node software, also in your working directory. : `git clone https://github.com/casper-network/casper-node` ![](https://i.imgur.com/70Ii9j5.png) - [x] Activate the NCTL environment && Compile the NCTL binary scripts : `source casper-node/utils/nctl/activate` - [x] Compile the NCTL binary scripts : `nctl-compile` ![](https://i.imgur.com/6WStLQX.png) - [x] install Casper Client ([More info](https://docs.casperlabs.io/en/latest/workflow/setup.html?highlight=casper-client#the-casper-command-line-client)): ``rustup toolchain install nightly && cargo +nightly-2021-06-17 install casper-client --locked`` ![](https://i.imgur.com/97dT7l3.png) 2. Clone the Contracts: `git clone https://github.com/casper-ecosystem/counter`![](https://i.imgur.com/S6z5j31.png) 3. Create a Local Network : `nctl-assets-setup && nctl-start` ![](https://i.imgur.com/BQ8y3Ut.png) 4. View the Network State - [x] Get the account hash : `nctl-view-faucet-account` ![](https://i.imgur.com/T4LLdEX.png) "account_hash":"account-hash-fc39092b4a70b6f961125da52183c31bb7976b03fca887e2b589a018fdd075e3" "secret_key":"/home/stuxr/work_directory/casper-node/utils/nctl/assets/net-1/faucet/secret_key.pem" - [x] Get the state root hash : `casper-client get-state-root-hash --node-address http://localhost:11101` ![](https://i.imgur.com/lzV49JV.png) "state_root_hash": "ca8d49254357a2c940c1cba8c78f7bff1b61bfc5af4a2bac3b770ceb6cde3ef7 - [x] Get the network state : `casper-client query-state --node-address http://localhost:11101 --state-root-hash ca8d49254357a2c940c1cba8c78f7bff1b61bfc5af4a2bac3b770ceb6cde3ef7 --key account-hash-fc39092b4a70b6f961125da52183c31bb7976b03fca887e2b589a018fdd075e3` ![](https://i.imgur.com/Sd0Robl.png) 5. Deploy the Counter Contract - [x] Sets the WASM target (execute on counter contract directory): `make prepare` ![](https://i.imgur.com/RTBgXzr.png) - [x] Builds the contract and verifies them : `make test` ![](https://i.imgur.com/ZcUVj05.png) - [x] Deploy the contract on to the network : `casper-client put-deploy --node-address http://localhost:11101 --chain-name casper-net-1 --secret-key /home/stuxr/work_directory/casper-node/utils/nctl/assets/net-1/faucet/secret_key.pem --payment-amount 5000000000000 --session-path ./counter/target/wasm32-unknown-unknown/release/counter-define.wasm` "deploy_hash": "95a0303f923af90cd5e26d0871e22a6378c78ca77bf1d5539712cdaaf3fb6b68" ![](https://i.imgur.com/3q7cCRD.png) - [x] Verify the successfully deployement : `casper-client get-deploy --node-address http://localhost:11101 95a0303f923af90cd5e26d0871e22a6378c78ca77bf1d5539712cdaaf3fb6b68` ![](https://i.imgur.com/Mjb2TId.png) 6. View the Updated Network State - [x] Get the NEW state root hash : `casper-client get-state-root-hash --node-address http://localhost:11101` ![](https://i.imgur.com/FRLvtcD.png) "state_root_hash": "5360ddd7a300b5f07f634bd41901e84bf59c7071e530443e0e54038c0223f3c7" - [x] Get the network state : `casper-client query-state --node-address http://localhost:11101 --state-root-hash 5360ddd7a300b5f07f634bd41901e84bf59c7071e530443e0e54038c0223f3c7 --key account-hash-fc39092b4a70b6f961125da52183c31bb7976b03fca887e2b589a018fdd075e3` ![](https://i.imgur.com/5swZ1TB.png) - [x] Retrieve the specific counter contract details: `casper-client query-state --node-address http://localhost:11101 --state-root-hash 5360ddd7a300b5f07f634bd41901e84bf59c7071e530443e0e54038c0223f3c7 --key account-hash-fc39092b4a70b6f961125da52183c31bb7976b03fca887e2b589a018fdd075e3 -q "counter"` ![](https://i.imgur.com/7MAEIP4.png) - [x] Retrieve the specific counter variable details: `casper-client query-state --node-address http://localhost:11101 --state-root-hash 5360ddd7a300b5f07f634bd41901e84bf59c7071e530443e0e54038c0223f3c7 --key account-hash-fc39092b4a70b6f961125da52183c31bb7976b03fca887e2b589a018fdd075e3 -q "counter/count"` ![](https://i.imgur.com/ArjPU8A.png) - [x] Retrieve the specific deploy detail: `casper-client query-state --node-address http://localhost:11101 --state-root-hash 5360ddd7a300b5f07f634bd41901e84bf59c7071e530443e0e54038c0223f3c7 --key deploy-95a0303f923af90cd5e26d0871e22a6378c78ca77bf1d5539712cdaaf3fb6b68` ![](https://i.imgur.com/rN2uP6o.png) 7. Increment the Counter (Option 1) - [x] Increment the Counter : `casper-client put-deploy --node-address http://localhost:11101 --chain-name casper-net-1 --secret-key /home/stuxr/work_directory/casper-node/utils/nctl/assets/net-1/faucet/secret_key.pem --payment-amount 5000000000000 --session-name "counter" --session-entry-point "counter_inc"` ![](https://i.imgur.com/PPqL7yJ.png) 8. View the Updated Network State Again - [x] Get the NEW state root hash : `casper-client get-state-root-hash --node-address http://localhost:11101` ![](https://i.imgur.com/6JPjgLQ.png) "state_root_hash": "703af0e5a8b51e39521dc47a51258041841e86a1c43611e04eb24b79a4915720" - [x] Get the network state : `casper-client query-state --node-address http://localhost:11101 --state-root-hash 703af0e5a8b51e39521dc47a51258041841e86a1c43611e04eb24b79a4915720 --key account-hash-fc39092b4a70b6f961125da52183c31bb7976b03fca887e2b589a018fdd075e3 -q "counter/count"` ![](https://i.imgur.com/OEsOY6w.png) 9. Increment the Counter Again (Option 2) - [x] Increment the Counter : `casper-client put-deploy --node-address http://localhost:11101 --chain-name casper-net-1 --secret-key /home/stuxr/work_directory/casper-node/utils/nctl/assets/net-1/faucet/secret_key.pem --payment-amount 5000000000000 --session-path ./counter/target/wasm32-unknown-unknown/release/counter-call.wasm` ![](https://i.imgur.com/hkoEAWo.png) 10. View the Final Network State - [x] Get the NEW state root hash : `casper-client get-state-root-hash --node-address http://localhost:11101` ![](https://i.imgur.com/5XSE3xp.png) "state_root_hash": "e03859c4fd09a2d5ad6cfa6cb8b027cbb8ec9b3385e0dda6ea6b81f857c233bb" - [x] Get the network state : `casper-client query-state --node-address http://localhost:11101 --state-root-hash 49c5801727259b026d8dfe82449a69bed0d4bb09ca29d59a6770bceff817f9bc --key account-hash-fc39092b4a70b6f961125da52183c31bb7976b03fca887e2b589a018fdd075e3 -q "counter/count"` ![](https://i.imgur.com/kdBjp8e.png) ### Step 3: Demonstrate key management concepts by modifying the client in the Multi-Sig tutorial to address one of the additional scenarios :::info [Scenario 4: managing lost or stolen keys](https://docs.casperlabs.io/en/latest/dapp-dev-guide/tutorials/multi-sig/examples.html#scenario-4-managing-lost-or-stolen-keys) ::: 1. Installing the contract and JS client - [x] Clone repository ([Repo here](https://github.com/casper-ecosystem/keys-manager)) : `git clone https://github.com/casper-ecosystem/keys-manager.git` ![](https://i.imgur.com/oEuF1yA.png) - [x] Compile the Smart Contracts : `cd keys-manager/ && cd contract && cargo build --release` ![](https://i.imgur.com/BPyW0Vr.png) - [x] Setting up the Client `cd keys-manager/client/ && touch .env && nano .env` add this line : ``` BASE_KEY_PATH=<ENTER_YOUR_PATH>/casper-node/utils/nctl/assets/net-1/faucet/ NODE_URL=http://localhost:11101/rpc ``` ![](https://i.imgur.com/wYrfNAO.png) and run : `npm install` ![](https://i.imgur.com/BqMHat0.png) - [x] Test the client : `npm run start:atomic` A lot of step will be executed >0.1 Fund main account. > 0.2 Install Keys Manager contract > 1. Set faucet's weight to 3 > 2. Set Keys Management Threshold to 3 > 3. Set Deploy Threshold to 2. > 4. Add first new key with weight 1. > 5. Add second new key with weight 1. > 6. Make a transfer from faucet using the new accounts. > 7. Remove the first account > 8. Remove the second account ![](https://i.imgur.com/QUzO4Yj.png) 2. Additionnal Scenario : Managing lost or stolen keys - [x] Update package.json, add a new command and update package.json : `"start:stolen": "node -r dotenv/config ./src/stolen.js",` ![](https://i.imgur.com/i4LTCTd.png) and run `npm update` - [x] Create the scenario ([Link here](https://gist.github.com/quentingosset/bad3e8d87e0f632a425e832839af594b)) : `cd src/ && touch stolen.js` - [x] Run the scenario : `npm run start:stolen` ![](https://i.imgur.com/wBYThtk.png) ### Step 4: Learn to transfer tokens to an account on the Casper Testnet. 1. Setting up an Account : - [x] Key generation using a Block Explorer : [Block Explorer](https://testnet.cspr.live/create-account) - [x] Save public key & download key ![](https://i.imgur.com/ShW0hGT.png) - [x] Fund your Account : [Faucet](https://testnet.cspr.live/tools/faucet) (wait a few minutes) ![](https://i.imgur.com/JG2ko0u.png) - [x] Acquire Node Address from network peers : [TESTNET Peers](https://testnet.cspr.live/tools/peers) 2. Execute the transfert : `casper-client transfer --id 1 --transfer-id 123456789012345 --node-address http://95.179.131.73:7777 --amount 2500000000 --payment-amount 100 --secret-key casper_testnet/secret_key.pem --chain-name casper-test --target-account 017d96b9a63abcb61c870a4f55187a0a7ac24096bdb5fc585c12a686a4d892009e` ![](https://i.imgur.com/buFcTqV.png) ![](https://i.imgur.com/Qz0VKE8.png) https://testnet.cspr.live/deploy/e56cd69300649a8da6ce456bf37e89b0c3d7636c999ba548b27b6efc409221f4 ### Step 5: Learn to Delegate and Undelegate on the Casper Testnet. Follow theses steps : [Guide](https://docs.casperlabs.io/en/latest/workflow/staking.html#delegating-tokens) Delegate : [link](https://testnet.cspr.live/deploy/79b4ebb9e58b69e2f07c2c2be1f25b9bb1501d071735b00e40d2b06e55099542) ![](https://i.imgur.com/vHbigRp.png) Undelegate : [link](https://testnet.cspr.live/deploy/32d70ae904db3fc0b8da73dc0ad5439a65d70592a2464cb7ab634363ed673fb0) ![](https://i.imgur.com/rcuHQKL.png)