Gitcoin Bounty # Create and deploy a simple, smart contract with cargo casper and cargo test Prerequisites Install rustup To build the project, go into the my-project folder, install the Rust toolchain and specify the target build as WebAssembly (wasm32): ![](https://i.imgur.com/xN6jJr3.png) Run the tests from the project folder, not from the tests folder. In this case, you need to navigate from the contract folder into my-project and run make test. ![](https://i.imgur.com/7b4TPFS.png) Compile to WASM To compile the contract to WASM, use npm to run the asbuild script from the project root: ![](https://i.imgur.com/UXs59dn.png) Local Network Testing Create and activate a new virtual environment. Commands applicable to the virtual environment will be prefixed with (env). Run the following commands to set it up. ![](https://i.imgur.com/gJJKPfv.png) Setting up the Network Set up all the assets required to run a local network, including binaries, chainspec, config, faucet, and keys. Also, spin up the network right after. The default network will have 10 nodes, with 5 active nodes and 5 inactive nodes. ![](https://i.imgur.com/ODmbh63.png) Deploying Contracts Run the commands below to install the client on most flavors of Linux and macOS. You will need the nightly version of the compiler. ![](https://i.imgur.com/d5y8SBf.png) Check the Client Version There is an official Rust client, that works with the Casper Testnet and Mainnet. To check the client version run: ![](https://i.imgur.com/6hqlvKi.png) Deployment using the Command Line (Rust Client) ![](https://i.imgur.com/qQdlh6z.png) Check Deploy Status ![](https://i.imgur.com/XbEiTxC.png) # Complete one of the existing tutorials for writing smart contracts ***Multi-Signature Tutorial*** Building the Smart Contract Before building the smart contract for this tutorial, you need to install the Rust Contract SDK. Make sure you have the development environment set up before proceeding. ![](https://i.imgur.com/M5GmmAQ.png) Compile the smart contract and create the WASM file using these commands: ![](https://i.imgur.com/ukfMjvi.png) See your faucet account details with the command below. ![](https://i.imgur.com/s2LHdPT.png) Setting up the Client ![](https://i.imgur.com/HQMn3eX.png) Navigate to your /keys-manager/client folder and run the keys-manager using npm. Your WASM file’s path is relative to the client folder, so you need to run the file from here. ![](https://i.imgur.com/gTHn5Os.png) # Demonstrate key management concepts by modifying the client in the Multi-Sig tutorial to address one of the additional scenarios ***Scenario 2: deploying with special key*** Code for Scenario 2: ``` const keyManager = require('./key-manager'); const TRANSFER_AMOUNT = process.env.TRANSFER_AMOUNT || 2500000000; (async function () { let deploy; // 0. Initial state of the account. // There should be only one associated key (facuet) with weight 1. // Deployment Threshold should be set to 1. // Key Management Threshold should be set to 1. let masterKey = keyManager.randomMasterKey(); // this key can perform only deployment let firstKey = masterKey.deriveIndex(1); // this key can perform both deployment and management let secondKey = masterKey.deriveIndex(2); console.log("\n0.1 Fund main account.\n"); await keyManager.fundAccount(firstKey); console.log("\n[x]0.2 Install Keys Manager contract"); deploy = keyManager.keys.buildContractInstallDeploy(firstKey); await keyManager.sendDeploy(deploy, [firstKey]); await keyManager.printAccount(firstKey); // 1. Set mainAccount's weight to 3 console.log("\n1. Set faucet's weight to 3\n"); deploy = keyManager.keys.setKeyWeightDeploy(firstKey, firstKey, 2); await keyManager.sendDeploy(deploy, [firstKey]); await keyManager.printAccount(firstKey); // 2. Set Keys Management Threshold to 2. console.log("\n2. Set Keys Management Threshold to 2\n"); deploy = keyManager.keys.setKeyManagementThresholdDeploy(firstKey, 2); await keyManager.sendDeploy(deploy, [firstKey]); await keyManager.printAccount(firstKey); // npx kill-port 11101 14101 18101 22101 11102 18102 14102 22102 18103 11103 14103 22103 // 3. Set Deploy Threshold to 1. console.log("\n3. Set Deploy Threshold to 1.\n"); deploy = keyManager.keys.setDeploymentThresholdDeploy(firstKey, 1); await keyManager.sendDeploy(deploy, [firstKey]); await keyManager.printAccount(firstKey); // 4. Add another key just with deployment permission console.log("\n4. Add another key just with deployment permission. \n"); deploy = keyManager.keys.setKeyWeightDeploy(firstKey, secondKey, 1); await keyManager.sendDeploy(deploy, [firstKey]); await keyManager.printAccount(firstKey); })(); ``` Result after start the Scenario 2 script ![](https://i.imgur.com/BRGMvvF.png) # Learn to transfer tokens to an account on the Casper Testnet. Send the transfer ![](https://i.imgur.com/Cb5bbFt.png) Perform the transfer ![](https://i.imgur.com/35YI3EJ.png) # Learn to Delegate and Undelegate on the Casper Testnet Delegate: ![](https://i.imgur.com/YeSIusk.png) Undelegate: ![](https://i.imgur.com/dhLtPK7.png)