# Casper Network Gitcoin Hackathon
# Task 1
All prerequisites where setup on Ubuntu 21.04 following https://docs.casperlabs.io/en/latest/dapp-dev-guide/setup-of-rust-contract-sdk.html.
![](https://i.imgur.com/xnXIkQd.png)
## Create and deploy a simple, smart contract with cargo casper and cargo test
- Project created with `cargo casper hackathon`
- Create and deploy
![](https://i.imgur.com/ry10mNX.png)
- Test contract
![](https://i.imgur.com/sZCL75N.png)
- Deploy contract to local devnet using faucet account
![](https://i.imgur.com/aP7fvWV.png)
![](https://i.imgur.com/CAXVkep.png)
## Complete one of the existing tutorials for writing smart contracts
### Counter
- Cloned counter Tutorial: `git clone https://github.com/casper-ecosystem/counter`
- View the Network State
![](https://i.imgur.com/Goo4cYB.png)
- Ran tests
![](https://i.imgur.com/fdituqM.png)
- Built the contract and deployed to the local Casper devnet
- counter-define
![](https://i.imgur.com/S4OMDU9.png)
- counter-call
![](https://i.imgur.com/tZgvs6A.png)
- Retrieve the specific counter contract details
![](https://i.imgur.com/pnKeSfp.png)
- Retrieve the specific counter variable details
![](https://i.imgur.com/IcLpzpw.png)
- Retrieve the specific deploy details
![](https://i.imgur.com/It7lHZQ.png)
- Increment the Counter
![](https://i.imgur.com/scUhuUw.png)
- View the Updated Network State Again (Stored value is now 2...)
![](https://i.imgur.com/tR7lpGm.png)
![](https://i.imgur.com/Cd7VB2p.png)
- Increment the Counter Again (using second contract)
![](https://i.imgur.com/oDqBjUq.png)
- View the Final Network State
![](https://i.imgur.com/ydtDvaJ.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
- Cloned `https://github.com/gitcoindev/keys-manager` and followed setup steps
- Added line to package.json:
`"start:scenario-two": "node -r dotenv/config ./src/scenario-two.js",`
- Added file 'scenario-two.js' to client/src
```javascript
const keyManager = require('./key-manager');
const TRANSFER_AMOUNT = process.env.TRANSFER_AMOUNT || 2500000000;
(async function() {
let deploy;
// init
let masterKey = keyManager.randomMasterKey();
let mainAccount = masterKey.deriveIndex(1);// Main Account
let secondaryAccount = masterKey.deriveIndex(2);//Secondary Account
let testAccount = masterKey.deriveIndex(3);// Test account
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 secondary key with weight 1 which can only deploy.
console.log("\n4. Add secondary key with weight 1.\n");
deploy = keyManager.keys.setKeyWeightDeploy(mainAccount, secondaryAccount, 1);
await keyManager.sendDeploy(deploy, [mainAccount]);
await keyManager.printAccount(mainAccount);
// 6. Make a transfer from faucet using the secondary account.
console.log("\n6. Make a transfer from faucet using the secondary account.\n");
deploy = keyManager.transferDeploy(mainAccount, secondaryAccount, TRANSFER_AMOUNT);
await keyManager.sendDeploy(deploy, [secondaryAccount]);
await keyManager.printAccount(mainAccount);
// 7. Add test key with weight 1 using secondary account.
console.log("\n7. Add first new key with weight 1 using the secondary account. Fail is Expected...\n");
deploy = keyManager.keys.setKeyWeightDeploy(mainAccount, testAccount, 1);
await keyManager.sendDeploy(deploy, [secondaryAccount]);
await keyManager.printAccount(mainAccount);
})();
```
- Output:
```
> keys-manager@1.0.0 start:scenario-two
> node -r dotenv/config ./src/scenario-two.js
0.1 Fund main account.
Signed by: account-hash-ac270d592ae6648f61958cff6e422743c69f118dc358ead49f4ad26a54de7227
Deploy hash: 7589a28f7d076ea1912dfa674b3f55086f6c185ef18f21ada48487724996c96f
Deploy result:
{
deploy: {
hash: '7589a28f7d076ea1912dfa674b3f55086f6c185ef18f21ada48487724996c96f',
header: {
account: '01911085d5b7d86bec517f174021ff3755efc25aa523658e0537df016a35b2d9c2',
timestamp: '2021-09-17T10:49:34.124Z',
ttl: '30m',
gas_price: 1,
body_hash: '33f61db9612f6e1e60eb907ddd23bc20e1fc21a021363b44e8591af3510e569a',
dependencies: [],
chain_name: 'casper-net-1'
},
payment: { ModuleBytes: [Object] },
session: { Transfer: [Object] },
approvals: [ [Object] ]
}
}
[x] Current state of the account:
{
_accountHash: 'account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707',
namedKeys: [],
mainPurse: 'uref-501b02dd61770c7fcced03532f775cf74b5d673aa18a39ebf82745cde3ace147-007',
associatedKeys: [
{
accountHash: 'account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707',
weight: 1
}
],
actionThresholds: { deployment: 1, keyManagement: 1 }
}
[x]0.2 Install Keys Manager contract
Signed by: account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707
Deploy hash: 907e4848ba1019a2db3f71ade6010a784c6f0d752b8b538581dbcea3948ea08a
Deploy result:
{
deploy: {
hash: '907e4848ba1019a2db3f71ade6010a784c6f0d752b8b538581dbcea3948ea08a',
header: {
account: '0202da26a3d30a9a7e83302fad9f91226cea31dd149184bfc9888eb447d03c45a8e1',
timestamp: '2021-09-17T10:50:41.491Z',
ttl: '30m',
gas_price: 1,
body_hash: 'd4b397a20f2addf8a039fad7d73b2aa781b6e954a283463d84047f8a97215c90',
dependencies: [],
chain_name: 'casper-net-1'
},
payment: { ModuleBytes: [Object] },
session: { ModuleBytes: [Object] },
approvals: [ [Object] ]
}
}
[x] Current state of the account:
{
_accountHash: 'account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707',
namedKeys: [
{
name: 'keys_manager',
key: 'hash-ba63cf13afe16e4ee4d271e3f7ffa83953b472557a1574a15a100951f7f65886'
},
{
name: 'keys_manager_hash',
key: 'uref-fcde0b9d3eef40813ad0e3170dc2152ebfa1264537fac03cacfcc328de9de158-007'
}
],
mainPurse: 'uref-501b02dd61770c7fcced03532f775cf74b5d673aa18a39ebf82745cde3ace147-007',
associatedKeys: [
{
accountHash: 'account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707',
weight: 1
}
],
actionThresholds: { deployment: 1, keyManagement: 1 }
}
1. Set faucet's weight to 2
Signed by: account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707
Deploy hash: 4c73ff2ef17e35144ce60b3e054217d352eafd67d4c8c0844060e39e5b286344
Deploy result:
{
deploy: {
hash: '4c73ff2ef17e35144ce60b3e054217d352eafd67d4c8c0844060e39e5b286344',
header: {
account: '0202da26a3d30a9a7e83302fad9f91226cea31dd149184bfc9888eb447d03c45a8e1',
timestamp: '2021-09-17T10:51:46.651Z',
ttl: '30m',
gas_price: 1,
body_hash: 'a820402c5f1fc9f5c2b57610004070ef1fa3930383a802b519d25972be42da1b',
dependencies: [],
chain_name: 'casper-net-1'
},
payment: { ModuleBytes: [Object] },
session: { StoredContractByName: [Object] },
approvals: [ [Object] ]
}
}
[x] Current state of the account:
{
_accountHash: 'account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707',
namedKeys: [
{
name: 'keys_manager',
key: 'hash-ba63cf13afe16e4ee4d271e3f7ffa83953b472557a1574a15a100951f7f65886'
},
{
name: 'keys_manager_hash',
key: 'uref-fcde0b9d3eef40813ad0e3170dc2152ebfa1264537fac03cacfcc328de9de158-007'
}
],
mainPurse: 'uref-501b02dd61770c7fcced03532f775cf74b5d673aa18a39ebf82745cde3ace147-007',
associatedKeys: [
{
accountHash: 'account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707',
weight: 2
}
],
actionThresholds: { deployment: 1, keyManagement: 1 }
}
2. Set Keys Management Threshold to 2
Signed by: account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707
Deploy hash: dc33722c18f3555cbea310ecd536835823af7f97c0827249bfeff0661954ab73
Deploy result:
{
deploy: {
hash: 'dc33722c18f3555cbea310ecd536835823af7f97c0827249bfeff0661954ab73',
header: {
account: '0202da26a3d30a9a7e83302fad9f91226cea31dd149184bfc9888eb447d03c45a8e1',
timestamp: '2021-09-17T10:52:51.915Z',
ttl: '30m',
gas_price: 1,
body_hash: '9357475174b44041d5a89a9091cded242fedc567af82c7fa920d5ec13d5c7f74',
dependencies: [],
chain_name: 'casper-net-1'
},
payment: { ModuleBytes: [Object] },
session: { StoredContractByName: [Object] },
approvals: [ [Object] ]
}
}
[x] Current state of the account:
{
_accountHash: 'account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707',
namedKeys: [
{
name: 'keys_manager',
key: 'hash-ba63cf13afe16e4ee4d271e3f7ffa83953b472557a1574a15a100951f7f65886'
},
{
name: 'keys_manager_hash',
key: 'uref-fcde0b9d3eef40813ad0e3170dc2152ebfa1264537fac03cacfcc328de9de158-007'
}
],
mainPurse: 'uref-501b02dd61770c7fcced03532f775cf74b5d673aa18a39ebf82745cde3ace147-007',
associatedKeys: [
{
accountHash: 'account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707',
weight: 2
}
],
actionThresholds: { deployment: 1, keyManagement: 2 }
}
3. Set Deploy Threshold to 1.
Signed by: account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707
Deploy hash: 82d1c939dea187eaa849781b501a4ed6c9394c0c6c39527aaff6b8a9b02a2b3e
Deploy result:
{
deploy: {
hash: '82d1c939dea187eaa849781b501a4ed6c9394c0c6c39527aaff6b8a9b02a2b3e',
header: {
account: '0202da26a3d30a9a7e83302fad9f91226cea31dd149184bfc9888eb447d03c45a8e1',
timestamp: '2021-09-17T10:53:58.185Z',
ttl: '30m',
gas_price: 1,
body_hash: '4807b024a8e1e7c7d1da5a9101a21f38303d4689905d88d4585eec852fd7216b',
dependencies: [],
chain_name: 'casper-net-1'
},
payment: { ModuleBytes: [Object] },
session: { StoredContractByName: [Object] },
approvals: [ [Object] ]
}
}
[x] Current state of the account:
{
_accountHash: 'account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707',
namedKeys: [
{
name: 'keys_manager',
key: 'hash-ba63cf13afe16e4ee4d271e3f7ffa83953b472557a1574a15a100951f7f65886'
},
{
name: 'keys_manager_hash',
key: 'uref-fcde0b9d3eef40813ad0e3170dc2152ebfa1264537fac03cacfcc328de9de158-007'
}
],
mainPurse: 'uref-501b02dd61770c7fcced03532f775cf74b5d673aa18a39ebf82745cde3ace147-007',
associatedKeys: [
{
accountHash: 'account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707',
weight: 2
}
],
actionThresholds: { deployment: 1, keyManagement: 2 }
}
4. Add secondary key with weight 1.
Signed by: account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707
Deploy hash: 452c8666f381aa47697c55cbffe2d4d5f14d42ad9bb0f0150661c4fae36a7316
Deploy result:
{
deploy: {
hash: '452c8666f381aa47697c55cbffe2d4d5f14d42ad9bb0f0150661c4fae36a7316',
header: {
account: '0202da26a3d30a9a7e83302fad9f91226cea31dd149184bfc9888eb447d03c45a8e1',
timestamp: '2021-09-17T10:55:03.440Z',
ttl: '30m',
gas_price: 1,
body_hash: '6de2568e9e969d47b41aaaf6c78763b5f17966935966853f1efaf8dc9a80728a',
dependencies: [],
chain_name: 'casper-net-1'
},
payment: { ModuleBytes: [Object] },
session: { StoredContractByName: [Object] },
approvals: [ [Object] ]
}
}
[x] Current state of the account:
{
_accountHash: 'account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707',
namedKeys: [
{
name: 'keys_manager',
key: 'hash-ba63cf13afe16e4ee4d271e3f7ffa83953b472557a1574a15a100951f7f65886'
},
{
name: 'keys_manager_hash',
key: 'uref-fcde0b9d3eef40813ad0e3170dc2152ebfa1264537fac03cacfcc328de9de158-007'
}
],
mainPurse: 'uref-501b02dd61770c7fcced03532f775cf74b5d673aa18a39ebf82745cde3ace147-007',
associatedKeys: [
{
accountHash: 'account-hash-65a72d9fe4a001e197bfab736877a8a0cd571369aa1e2d6bc1f7aef2b2b4b7a9',
weight: 1
},
{
accountHash: 'account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707',
weight: 2
}
],
actionThresholds: { deployment: 1, keyManagement: 2 }
}
6. Make a transfer from faucet using the secondary account.
Signed by: account-hash-65a72d9fe4a001e197bfab736877a8a0cd571369aa1e2d6bc1f7aef2b2b4b7a9
Deploy hash: dc9db790b3d9ff982046eb9fc63a9cee2d55b6f9902835537a6cd876f1d22bf3
Deploy result:
{
deploy: {
hash: 'dc9db790b3d9ff982046eb9fc63a9cee2d55b6f9902835537a6cd876f1d22bf3',
header: {
account: '0202da26a3d30a9a7e83302fad9f91226cea31dd149184bfc9888eb447d03c45a8e1',
timestamp: '2021-09-17T10:56:08.699Z',
ttl: '30m',
gas_price: 1,
body_hash: '4fc99ce6388c2a27e12b75357a413b95fcc01d6bc25857ae63695e9f6309b7bf',
dependencies: [],
chain_name: 'casper-net-1'
},
payment: { ModuleBytes: [Object] },
session: { Transfer: [Object] },
approvals: [ [Object] ]
}
}
[x] Current state of the account:
{
_accountHash: 'account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707',
namedKeys: [
{
name: 'keys_manager',
key: 'hash-ba63cf13afe16e4ee4d271e3f7ffa83953b472557a1574a15a100951f7f65886'
},
{
name: 'keys_manager_hash',
key: 'uref-fcde0b9d3eef40813ad0e3170dc2152ebfa1264537fac03cacfcc328de9de158-007'
}
],
mainPurse: 'uref-501b02dd61770c7fcced03532f775cf74b5d673aa18a39ebf82745cde3ace147-007',
associatedKeys: [
{
accountHash: 'account-hash-65a72d9fe4a001e197bfab736877a8a0cd571369aa1e2d6bc1f7aef2b2b4b7a9',
weight: 1
},
{
accountHash: 'account-hash-866c0904563222d7f6fc02dd6114011df04b7e52543d10d96759cbc475966707',
weight: 2
}
],
actionThresholds: { deployment: 1, keyManagement: 2 }
}
7. Add first new key with weight 1 using the secondary account. Fail is Expected...
Signed by: account-hash-65a72d9fe4a001e197bfab736877a8a0cd571369aa1e2d6bc1f7aef2b2b4b7a9
Deploy hash: b85db19337e30773741dcee43477db95f7a8cdb00f50e18bc07343405ec2283e
Deploy result:
(node:156898) UnhandledPromiseRejectionWarning: Error: Contract execution: User error: 2
at getDeploy (/home/nhaga/dev/blockchain/casper/keys-manager/client/src/key-manager.js:48:23)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async printDeploy (/home/nhaga/dev/blockchain/casper/keys-manager/client/src/key-manager.js:91:41)
at async Object.sendDeploy (/home/nhaga/dev/blockchain/casper/keys-manager/client/src/key-manager.js:78:5)
at async /home/nhaga/dev/blockchain/casper/keys-manager/client/src/scenario-two.js:57:5
(Use `node --trace-warnings ...` to show where the warning was created)
(node:156898) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:156898) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
```
## Learn to transfer tokens to an account on the Casper Testnet.
### Using https://testnet.cspr.live/
- Fund account with faucet
![](https://i.imgur.com/mgvu86d.png)
- Transfer
![](https://i.imgur.com/OD3cVjo.png)
![](https://i.imgur.com/gP7BhDd.png)
![](https://i.imgur.com/W4YvSR4.png)
![](https://i.imgur.com/nx08vxK.png)
![](https://i.imgur.com/0mNcCRv.png)
![](https://i.imgur.com/CsqasrF.png)
- Explorer link:
https://testnet.cspr.live/account/020243a99f6724a35ec6cc6216e2f11d7548f1c6947875619bfe08e332f6f83f3578
### Using cli
- Transfer
![](https://i.imgur.com/EVnNAu2.png)
![](https://i.imgur.com/FXhqaw2.png)
- Explorer link:
https://testnet.cspr.live/deploy/b68a370bfb689b2929c1b04643c7aa55aaff7e9d57e006632e869217ebdfe956
## Learn to Delegate and Undelegate on the Casper Testnet
### Using https://testnet.cspr.live/
- Delegating 500 CSPR on Casper Testnet
![](https://i.imgur.com/a3Vy1lY.png)
![](https://i.imgur.com/5N4FH36.png)
![](https://i.imgur.com/Cs9i9GC.png)
![](https://i.imgur.com/B7NCmWE.png)
![](https://i.imgur.com/ZFAC9Ax.png)
Explorer link:
https://testnet.cspr.live/deploy/f735ebf550b9311ebbfac41382dc50fe75cf4f7c5ff84dc38f4e8bb16cf387ca
- Account after hours of delegating
![](https://i.imgur.com/iZxxyNY.png)
- Undelegate 100 CSPR
![](https://i.imgur.com/Md0Mjgl.png)
![](https://i.imgur.com/hg8dPV0.png)
![](https://i.imgur.com/EXYWQGj.png)
![](https://i.imgur.com/h6VV4f5.png)
![](https://i.imgur.com/1CJqEQS.png)
### Using cli
- Delegating 100 CSPR on Casper Testnet with cli
![](https://i.imgur.com/OIPKpWe.png)
![](https://i.imgur.com/wQoU4C7.png)