# 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`  - [x] Check if rust is up to date : `rustup update && rustup --version`  2. Installing Dependencies - [x] Cmake : `sudo apt install cmake && cmake --version`  3. Installing the Casper Crates - [x] Installing the Casper Crates : `cargo install cargo-casper`  4. Creating a Project - [x] Create a new sample project : `cargo casper my-project`  5. Compiling to WASM (The Casper blockchain uses WebAssembly) - [x] Go into the contract folder : `cd my-project/contract/`  - [x] Install the Rust toolchain : `rustup install $(cat rust-toolchain)`  - [x] Specify the target build as WebAssembly (wasm32) : `rustup target add --toolchain $(cat rust-toolchain) wasm32-unknown-unknown`  6. Build the Contract - [x] Compile the smart contract into WASM : `cargo build --release`  7. Test the Contract - [x] Go into the test folder : `cd ../tests`  - [x] Run the test : `cargo test`  8. Verifying the test - [x] Open the contract main.rs file :  - [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`  ### 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`  - [x] Check pip : `sudo apt install python3-pip && pip --version`  - [x] Install PKG : `sudo apt install pkg-config`  - [x] Install LIBSSL : `sudo apt install libssl-dev`  - [x] Install gcc & g++ : `sudo apt install build-essential && gcc --version && g++ --version`  - [x] Create and activate a new virtual environment : `python3 -m venv env && source env/bin/activate`  - [x] Upgrade pip on virtual environnement : `pip install --upgrade pip`  - [x] Install jq,supervisor,toml : `pip install jq supervisor toml`  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`  - [x] Clone the casper-node software, also in your working directory. : `git clone https://github.com/casper-network/casper-node`  - [x] Activate the NCTL environment && Compile the NCTL binary scripts : `source casper-node/utils/nctl/activate` - [x] Compile the NCTL binary scripts : `nctl-compile`  - [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``  2. Clone the Contracts: `git clone https://github.com/casper-ecosystem/counter` 3. Create a Local Network : `nctl-assets-setup && nctl-start`  4. View the Network State - [x] Get the account hash : `nctl-view-faucet-account`  "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`  "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`  5. Deploy the Counter Contract - [x] Sets the WASM target (execute on counter contract directory): `make prepare`  - [x] Builds the contract and verifies them : `make test`  - [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"  - [x] Verify the successfully deployement : `casper-client get-deploy --node-address http://localhost:11101 95a0303f923af90cd5e26d0871e22a6378c78ca77bf1d5539712cdaaf3fb6b68`  6. View the Updated Network State - [x] Get the NEW state root hash : `casper-client get-state-root-hash --node-address http://localhost:11101`  "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`  - [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"`  - [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"`  - [x] Retrieve the specific deploy detail: `casper-client query-state --node-address http://localhost:11101 --state-root-hash 5360ddd7a300b5f07f634bd41901e84bf59c7071e530443e0e54038c0223f3c7 --key deploy-95a0303f923af90cd5e26d0871e22a6378c78ca77bf1d5539712cdaaf3fb6b68`  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"`  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`  "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"`  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`  10. View the Final Network State - [x] Get the NEW state root hash : `casper-client get-state-root-hash --node-address http://localhost:11101`  "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"`  ### 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`  - [x] Compile the Smart Contracts : `cd keys-manager/ && cd contract && cargo build --release`  - [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 ```  and run : `npm install`  - [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  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",`  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`  ### 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  - [x] Fund your Account : [Faucet](https://testnet.cspr.live/tools/faucet) (wait a few minutes)  - [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://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)  Undelegate : [link](https://testnet.cspr.live/deploy/32d70ae904db3fc0b8da73dc0ad5439a65d70592a2464cb7ab634363ed673fb0) 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up