## Get Started With Casper Hackathon: The Friendly Hackathon: Start Building on Casper! Submitter: **Soptq** ## Challenge ### Create and deploy a simple, smart contract with cargo casper and cargo test The screenshot of deploying the contract to testnet: ![](https://i.imgur.com/AXkPU2L.png) The screenshot of the deployment status: ![](https://i.imgur.com/PGUaiDg.png) ### Complete one of the existing tutorials for writing smart contracts *Multi-Signature Tutorial* The screenshot of building the contract: ![](https://i.imgur.com/o8RmmuM.png) The screenshot of building the client: ![](https://i.imgur.com/dFecw7n.png) The screenshot of testing the client: ![](https://i.imgur.com/PHKPjjA.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 keys* > In this example, you have two keys. One key can only perform deployments, while the second key can perform key management and deployments. The key with account address a1 can deploy and make account changes, but the second key with account address b2 can only deploy. ```javascript=d const keyManager = require('./key-manager'); const TRANSFER_AMOUNT = process.env.TRANSFER_AMOUNT || 2500000000; (async function () { // 1. Set mainAccount's weight to 2. // 2. Set Keys Management Threshold to 2. // 3. Set Deploy Threshold to 1. // 4. Add first new key with weight 1 (deploy key). 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(); let mainAccount = masterKey.deriveIndex(1); // deployment and management let deployAccount = masterKey.deriveIndex(2); // only for deployment console.log("\n0.1 Fund main account.\n"); await keyManager.fundAccount(mainAccount); await keyManager.printAccount(mainAccount); console.log("\n[x]0.2 Install Keys Manager contract"); deploy = keyManager.keys.buildContractInstallDeploy(mainAccount); await keyManager.sendDeploy(deploy, [mainAccount]); await keyManager.printAccount(mainAccount); // 1. Set mainAccount's weight to 2 console.log("\n1. Set faucet's weight to 2\n"); deploy = keyManager.keys.setKeyWeightDeploy(mainAccount, mainAccount, 2); await keyManager.sendDeploy(deploy, [mainAccount]); await keyManager.printAccount(mainAccount); // 2. Set Keys Management Threshold to 2. console.log("\n2. Set Keys Management Threshold to 2\n"); deploy = keyManager.keys.setKeyManagementThresholdDeploy(mainAccount, 2); await keyManager.sendDeploy(deploy, [mainAccount]); await keyManager.printAccount(mainAccount); // 3. Set Deploy Threshold to 1. console.log("\n3. Set Deploy Threshold to 1.\n"); deploy = keyManager.keys.setDeploymentThresholdDeploy(mainAccount, 1); await keyManager.sendDeploy(deploy, [mainAccount]); await keyManager.printAccount(mainAccount); // 4. Add first new key with weight 1 (first account). console.log("\n4. Add first new key with weight 1.\n"); deploy = keyManager.keys.setKeyWeightDeploy(mainAccount, deployAccount, 1); await keyManager.sendDeploy(deploy, [mainAccount]); await keyManager.printAccount(mainAccount); })(); ``` ### Learn to transfer tokens to an account on the Casper Testnet. Screnshot of transfering tokens: ![](https://i.imgur.com/Q4Zplov.png) Screenshot of the deployment status: ![](https://i.imgur.com/EutfgzF.png) Screenshot of the state root hash: ![](https://i.imgur.com/uVmjiix.png) Screenshot of the target account state: ![](https://i.imgur.com/TKAe2pV.png) Screenshot of the target account balance: ![](https://i.imgur.com/thnEeNJ.png) ### Learn to Delegate and Undelegate on the Casper Testnet Screenshot of delegating on the Casper Testnet: ![](https://i.imgur.com/3B8IVAD.png) Screenshot of undelegating on the Casper Testnet: ![](https://i.imgur.com/2vYiPoB.png)