---
# System prepended metadata

title: 'Task #1: Create and deploy a simple, smart contract with cargo casper and cargo test'

---

# Task #1: Create and deploy a simple, smart contract with cargo casper and cargo test

**Prerequisites**

*Installing Rust*

![](https://i.imgur.com/v90krAU.png)

*Check your version*

![](https://i.imgur.com/EciBacu.png)

*CMake*

![](https://i.imgur.com/cZ4fI60.png)

**Development Environment Setup**

*Installing the Casper Crates*

![](https://i.imgur.com/PgixPmJ.png)

*Build the Contract*

![](https://i.imgur.com/jEGk7br.png)

*Test the Contract*

![](https://i.imgur.com/Tt9WJDf.png)

**Compile to WASM**

![](https://i.imgur.com/vglJYma.png)

**Local Network Testing**

*Setting up the Network*

![](https://i.imgur.com/2Y6aybR.png)

**Deploying Contracts**

*The Casper Client*

![](https://i.imgur.com/aggMBvv.png)

*Check the Client Version*

![](https://i.imgur.com/eHsui16.png)

**Sending a Deployment to the Testnet**

![](https://i.imgur.com/izVwkZr.png)

**Check Deploy Status**

![](https://i.imgur.com/SyReWRw.png)

# Task #2: Complete one of the existing tutorials for writing smart contracts

> Multi-Signature Tutorial

---

**Building the Smart Contract**

![](https://i.imgur.com/VbuBzWZ.png)

**Compile the smart contract and create the WASM file**

![](https://i.imgur.com/IUjWJyY.png)

**Setting up a local Casper Network**

*Network is up and running*

![](https://i.imgur.com/Kqghh7F.png)

*Check faucet account*

![](https://i.imgur.com/7VjMfQg.png)

**Testing the Client**

```
(env) root@kaedenlaci72:~/keys-manager/client# npm run start:atomic

> keys-manager@1.0.0 start:atomic
> node -r dotenv/config ./src/scenario-atomic.js


0.1 Fund main account.

Signed by: account-hash-ac873ad1b785f6714028e6eb8ef0b5340315aac49fd7332bbf5e86c2d6631913
Deploy hash: a36b2a8a87d8dda9c6b85dbe401c0e4c0993472cbc08597b98071555fb8ce673
Deploy result:
{
  deploy: {
    hash: 'a36b2a8a87d8dda9c6b85dbe401c0e4c0993472cbc08597b98071555fb8ce673',
    header: {
      account: '012a125d66bf5297d67afd380da38d4c6f786b961d14ed4c060cf8f50309ec732e',
      timestamp: '2021-09-24T20:37:56.503Z',
      ttl: '30m',
      gas_price: 1,
      body_hash: '3fa37b96529ba8ab27d25bf61a6998d4ef9c34deafebd1b1e21b1c7395916451',
      dependencies: [],
      chain_name: 'casper-net-1'
    },
    payment: { ModuleBytes: [Object] },
    session: { Transfer: [Object] },
    approvals: [ [Object] ]
  }
}

[x] Current state of the account:
{
  _accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
  namedKeys: [],
  mainPurse: 'uref-dfb07d6c93cc50fc01499e36662c25ef2e6786d5295bcdf8e1ac4a359ed9aabc-007',
  associatedKeys: [
    {
      accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
      weight: 1
    }
  ],
  actionThresholds: { deployment: 1, keyManagement: 1 }
}

[x]0.2 Install Keys Manager contract
Signed by: account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc
Deploy hash: 8a2c0db24c4f0dbae8388a7847d752f1a3e33a812a3f627f1f93a8207205425d
Deploy result:
{
  deploy: {
    hash: '8a2c0db24c4f0dbae8388a7847d752f1a3e33a812a3f627f1f93a8207205425d',
    header: {
      account: '0202be8b25b6fb9100b994edd5070b333e06fbede3ca10588f49a8b8cba18a308145',
      timestamp: '2021-09-24T20:39:04.095Z',
      ttl: '30m',
      gas_price: 1,
      body_hash: '8b75c87f0c5c33503df86050553e6a490fdee8d5154d9eececdc7c22618217c8',
      dependencies: [],
      chain_name: 'casper-net-1'
    },
    payment: { ModuleBytes: [Object] },
    session: { ModuleBytes: [Object] },
    approvals: [ [Object] ]
  }
}

[x] Current state of the account:
{
  _accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
  namedKeys: [
    {
      name: 'keys_manager',
      key: 'hash-5f5a4d0dec59f12e5c64168ada290e7a25afb72d9ecc1c2a9e85beac50a9b34b'
    },
    {
      name: 'keys_manager_hash',
      key: 'uref-84b5f4c665ad9081cc073589f45d10518989e80cf2d15442591b0a3d358cc64f-007'
    }
  ],
  mainPurse: 'uref-dfb07d6c93cc50fc01499e36662c25ef2e6786d5295bcdf8e1ac4a359ed9aabc-007',
  associatedKeys: [
    {
      accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
      weight: 1
    }
  ],
  actionThresholds: { deployment: 1, keyManagement: 1 }
}

1. Set faucet's weight to 3

Signed by: account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc
Deploy hash: 70f353504eb526d99b01eae8576e330aa40f697e6559d637b4b9fad3920c39b7
Deploy result:
{
  deploy: {
    hash: '70f353504eb526d99b01eae8576e330aa40f697e6559d637b4b9fad3920c39b7',
    header: {
      account: '0202be8b25b6fb9100b994edd5070b333e06fbede3ca10588f49a8b8cba18a308145',
      timestamp: '2021-09-24T20:40:09.595Z',
      ttl: '30m',
      gas_price: 1,
      body_hash: 'ec7fd6c62f306be67c6dc660ebf224d72d3ee02f070e7cf52e05437e5dc8e4fb',
      dependencies: [],
      chain_name: 'casper-net-1'
    },
    payment: { ModuleBytes: [Object] },
    session: { StoredContractByName: [Object] },
    approvals: [ [Object] ]
  }
}

[x] Current state of the account:
{
  _accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
  namedKeys: [
    {
      name: 'keys_manager',
      key: 'hash-5f5a4d0dec59f12e5c64168ada290e7a25afb72d9ecc1c2a9e85beac50a9b34b'
    },
    {
      name: 'keys_manager_hash',
      key: 'uref-84b5f4c665ad9081cc073589f45d10518989e80cf2d15442591b0a3d358cc64f-007'
    }
  ],
  mainPurse: 'uref-dfb07d6c93cc50fc01499e36662c25ef2e6786d5295bcdf8e1ac4a359ed9aabc-007',
  associatedKeys: [
    {
      accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
      weight: 3
    }
  ],
  actionThresholds: { deployment: 1, keyManagement: 1 }
}

2. Set Keys Management Threshold to 3

Signed by: account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc
Deploy hash: 86c0a78dc3f1c16b6595dad4590ba1e6e0970a9092bbf2af4dcc5b63485e799f
Deploy result:
{
  deploy: {
    hash: '86c0a78dc3f1c16b6595dad4590ba1e6e0970a9092bbf2af4dcc5b63485e799f',
    header: {
      account: '0202be8b25b6fb9100b994edd5070b333e06fbede3ca10588f49a8b8cba18a308145',
      timestamp: '2021-09-24T20:41:14.546Z',
      ttl: '30m',
      gas_price: 1,
      body_hash: '3f3394304ff22fe422511e62eed631bc501385f67fdd1fe71891f7d375550324',
      dependencies: [],
      chain_name: 'casper-net-1'
    },
    payment: { ModuleBytes: [Object] },
    session: { StoredContractByName: [Object] },
    approvals: [ [Object] ]
  }
}

[x] Current state of the account:
{
  _accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
  namedKeys: [
    {
      name: 'keys_manager',
      key: 'hash-5f5a4d0dec59f12e5c64168ada290e7a25afb72d9ecc1c2a9e85beac50a9b34b'
    },
    {
      name: 'keys_manager_hash',
      key: 'uref-84b5f4c665ad9081cc073589f45d10518989e80cf2d15442591b0a3d358cc64f-007'
    }
  ],
  mainPurse: 'uref-dfb07d6c93cc50fc01499e36662c25ef2e6786d5295bcdf8e1ac4a359ed9aabc-007',
  associatedKeys: [
    {
      accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
      weight: 3
    }
  ],
  actionThresholds: { deployment: 1, keyManagement: 3 }
}

3. Set Deploy Threshold to 2.

Signed by: account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc
Deploy hash: 83a7ec344d48620c826538a3685ed70112959c0262303356bed62b7249853098
Deploy result:
{
  deploy: {
    hash: '83a7ec344d48620c826538a3685ed70112959c0262303356bed62b7249853098',
    header: {
      account: '0202be8b25b6fb9100b994edd5070b333e06fbede3ca10588f49a8b8cba18a308145',
      timestamp: '2021-09-24T20:42:20.478Z',
      ttl: '30m',
      gas_price: 1,
      body_hash: '609e820d1eb41cd0fe90e6c5c4cf179afd2c9d9ba19bb0f21ca310a85450f228',
      dependencies: [],
      chain_name: 'casper-net-1'
    },
    payment: { ModuleBytes: [Object] },
    session: { StoredContractByName: [Object] },
    approvals: [ [Object] ]
  }
}

[x] Current state of the account:
{
  _accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
  namedKeys: [
    {
      name: 'keys_manager',
      key: 'hash-5f5a4d0dec59f12e5c64168ada290e7a25afb72d9ecc1c2a9e85beac50a9b34b'
    },
    {
      name: 'keys_manager_hash',
      key: 'uref-84b5f4c665ad9081cc073589f45d10518989e80cf2d15442591b0a3d358cc64f-007'
    }
  ],
  mainPurse: 'uref-dfb07d6c93cc50fc01499e36662c25ef2e6786d5295bcdf8e1ac4a359ed9aabc-007',
  associatedKeys: [
    {
      accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
      weight: 3
    }
  ],
  actionThresholds: { deployment: 2, keyManagement: 3 }
}

4. Add first new key with weight 1.

Signed by: account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc
Deploy hash: 0fdf515d7c36b8f5290dece0e0a89c0c40f7854acf67379c1e974d27f9eb53cb
Deploy result:
{
  deploy: {
    hash: '0fdf515d7c36b8f5290dece0e0a89c0c40f7854acf67379c1e974d27f9eb53cb',
    header: {
      account: '0202be8b25b6fb9100b994edd5070b333e06fbede3ca10588f49a8b8cba18a308145',
      timestamp: '2021-09-24T20:43:26.340Z',
      ttl: '30m',
      gas_price: 1,
      body_hash: '049475ed134576795ce1a084996ffdeed7ad92d5a5df22a52ccba5e656d7960c',
      dependencies: [],
      chain_name: 'casper-net-1'
    },
    payment: { ModuleBytes: [Object] },
    session: { StoredContractByName: [Object] },
    approvals: [ [Object] ]
  }
}

[x] Current state of the account:
{
  _accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
  namedKeys: [
    {
      name: 'keys_manager',
      key: 'hash-5f5a4d0dec59f12e5c64168ada290e7a25afb72d9ecc1c2a9e85beac50a9b34b'
    },
    {
      name: 'keys_manager_hash',
      key: 'uref-84b5f4c665ad9081cc073589f45d10518989e80cf2d15442591b0a3d358cc64f-007'
    }
  ],
  mainPurse: 'uref-dfb07d6c93cc50fc01499e36662c25ef2e6786d5295bcdf8e1ac4a359ed9aabc-007',
  associatedKeys: [
    {
      accountHash: 'account-hash-b2dcd441da8027197ad2c83503473652818515941e518e60174aafb86c33ec5d',
      weight: 1
    },
    {
      accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
      weight: 3
    }
  ],
  actionThresholds: { deployment: 2, keyManagement: 3 }
}

5. Add second new key with weight 1.

Signed by: account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc
Deploy hash: 1f6bdb4bd261306587cd6d12dac6e3d025ed625471563b772db088e81ada99da
Deploy result:
{
  deploy: {
    hash: '1f6bdb4bd261306587cd6d12dac6e3d025ed625471563b772db088e81ada99da',
    header: {
      account: '0202be8b25b6fb9100b994edd5070b333e06fbede3ca10588f49a8b8cba18a308145',
      timestamp: '2021-09-24T20:44:31.275Z',
      ttl: '30m',
      gas_price: 1,
      body_hash: '882b5cf9d03ca0a8c0021424bbe11a77b9d50ea7726f4b535a3d1b3ac21698e3',
      dependencies: [],
      chain_name: 'casper-net-1'
    },
    payment: { ModuleBytes: [Object] },
    session: { StoredContractByName: [Object] },
    approvals: [ [Object] ]
  }
}

[x] Current state of the account:
{
  _accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
  namedKeys: [
    {
      name: 'keys_manager',
      key: 'hash-5f5a4d0dec59f12e5c64168ada290e7a25afb72d9ecc1c2a9e85beac50a9b34b'
    },
    {
      name: 'keys_manager_hash',
      key: 'uref-84b5f4c665ad9081cc073589f45d10518989e80cf2d15442591b0a3d358cc64f-007'
    }
  ],
  mainPurse: 'uref-dfb07d6c93cc50fc01499e36662c25ef2e6786d5295bcdf8e1ac4a359ed9aabc-007',
  associatedKeys: [
    {
      accountHash: 'account-hash-462a0f9d9314d60108c3b9c2e543d2d243d6b68e0ed323e7f5ee7f80c87424d2',
      weight: 1
    },
    {
      accountHash: 'account-hash-b2dcd441da8027197ad2c83503473652818515941e518e60174aafb86c33ec5d',
      weight: 1
    },
    {
      accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
      weight: 3
    }
  ],
  actionThresholds: { deployment: 2, keyManagement: 3 }
}

6. Make a transfer from faucet using the new accounts.

Signed by: account-hash-b2dcd441da8027197ad2c83503473652818515941e518e60174aafb86c33ec5d
Signed by: account-hash-462a0f9d9314d60108c3b9c2e543d2d243d6b68e0ed323e7f5ee7f80c87424d2
Deploy hash: 83613c798df6a8a99573003bf8ec2b894f2b99c57db17d996654b2c525fc769b
Deploy result:
{
  deploy: {
    hash: '83613c798df6a8a99573003bf8ec2b894f2b99c57db17d996654b2c525fc769b',
    header: {
      account: '0202be8b25b6fb9100b994edd5070b333e06fbede3ca10588f49a8b8cba18a308145',
      timestamp: '2021-09-24T20:45:37.178Z',
      ttl: '30m',
      gas_price: 1,
      body_hash: '19369357b0c69b808639174a4ea67d384ea28b42da0791d6f02bf05d73439e67',
      dependencies: [],
      chain_name: 'casper-net-1'
    },
    payment: { ModuleBytes: [Object] },
    session: { Transfer: [Object] },
    approvals: [ [Object], [Object] ]
  }
}

[x] Current state of the account:
{
  _accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
  namedKeys: [
    {
      name: 'keys_manager',
      key: 'hash-5f5a4d0dec59f12e5c64168ada290e7a25afb72d9ecc1c2a9e85beac50a9b34b'
    },
    {
      name: 'keys_manager_hash',
      key: 'uref-84b5f4c665ad9081cc073589f45d10518989e80cf2d15442591b0a3d358cc64f-007'
    }
  ],
  mainPurse: 'uref-dfb07d6c93cc50fc01499e36662c25ef2e6786d5295bcdf8e1ac4a359ed9aabc-007',
  associatedKeys: [
    {
      accountHash: 'account-hash-462a0f9d9314d60108c3b9c2e543d2d243d6b68e0ed323e7f5ee7f80c87424d2',
      weight: 1
    },
    {
      accountHash: 'account-hash-b2dcd441da8027197ad2c83503473652818515941e518e60174aafb86c33ec5d',
      weight: 1
    },
    {
      accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
      weight: 3
    }
  ],
  actionThresholds: { deployment: 2, keyManagement: 3 }
}

7. Remove the first account

Signed by: account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc
Deploy hash: 27ef5b0fb0ae7688962e0ecb0ab505b0a56b59d886b1540197f9a55bc3ca8bfb
Deploy result:
{
  deploy: {
    hash: '27ef5b0fb0ae7688962e0ecb0ab505b0a56b59d886b1540197f9a55bc3ca8bfb',
    header: {
      account: '0202be8b25b6fb9100b994edd5070b333e06fbede3ca10588f49a8b8cba18a308145',
      timestamp: '2021-09-24T20:46:42.176Z',
      ttl: '30m',
      gas_price: 1,
      body_hash: '82bc06a948931ba00d520785d4d11af9cd9fa5feca96dfa9577cd267cc418ea2',
      dependencies: [],
      chain_name: 'casper-net-1'
    },
    payment: { ModuleBytes: [Object] },
    session: { StoredContractByName: [Object] },
    approvals: [ [Object] ]
  }
}

[x] Current state of the account:
{
  _accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
  namedKeys: [
    {
      name: 'keys_manager',
      key: 'hash-5f5a4d0dec59f12e5c64168ada290e7a25afb72d9ecc1c2a9e85beac50a9b34b'
    },
    {
      name: 'keys_manager_hash',
      key: 'uref-84b5f4c665ad9081cc073589f45d10518989e80cf2d15442591b0a3d358cc64f-007'
    }
  ],
  mainPurse: 'uref-dfb07d6c93cc50fc01499e36662c25ef2e6786d5295bcdf8e1ac4a359ed9aabc-007',
  associatedKeys: [
    {
      accountHash: 'account-hash-462a0f9d9314d60108c3b9c2e543d2d243d6b68e0ed323e7f5ee7f80c87424d2',
      weight: 1
    },
    {
      accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
      weight: 3
    }
  ],
  actionThresholds: { deployment: 2, keyManagement: 3 }
}

8. Remove the second account

Signed by: account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc
Deploy hash: 0b3a2df127c8b941c1ec6acc327e3eedcc916de17293a069db7093bdd590594e
Deploy result:
{
  deploy: {
    hash: '0b3a2df127c8b941c1ec6acc327e3eedcc916de17293a069db7093bdd590594e',
    header: {
      account: '0202be8b25b6fb9100b994edd5070b333e06fbede3ca10588f49a8b8cba18a308145',
      timestamp: '2021-09-24T20:47:48.106Z',
      ttl: '30m',
      gas_price: 1,
      body_hash: '0ea70bfe79b29284cc761dc5a175df5967d49d41177d2b2b2b69057683672e4d',
      dependencies: [],
      chain_name: 'casper-net-1'
    },
    payment: { ModuleBytes: [Object] },
    session: { StoredContractByName: [Object] },
    approvals: [ [Object] ]
  }
}

[x] Current state of the account:
{
  _accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
  namedKeys: [
    {
      name: 'keys_manager',
      key: 'hash-5f5a4d0dec59f12e5c64168ada290e7a25afb72d9ecc1c2a9e85beac50a9b34b'
    },
    {
      name: 'keys_manager_hash',
      key: 'uref-84b5f4c665ad9081cc073589f45d10518989e80cf2d15442591b0a3d358cc64f-007'
    }
  ],
  mainPurse: 'uref-dfb07d6c93cc50fc01499e36662c25ef2e6786d5295bcdf8e1ac4a359ed9aabc-007',
  associatedKeys: [
    {
      accountHash: 'account-hash-eba8d6a8a24cf4eb3fe8ee288bf73373ec4986b564fb0052759f7f61f61255fc',
      weight: 3
    }
  ],
  actionThresholds: { deployment: 2, keyManagement: 3 }
}
```

# Task #3: Demonstrate key management concepts by modifying the client in the Multi-Sig

**Scenario 5: managing accounts with multiple keys**

---

Go to source code directory at ~/keys-manager/client/src, create a code file for Scenario 5 as below:

```
(env) root@kaedenlaci72:~/keys-manager/client/src# cat scenario_5.js
const keyManager = require('./key-manager');
const TRANSFER_AMOUNT = process.env.TRANSFER_AMOUNT || 2500000000;

(async function () {

    // To achieve the task, we will:
    // 1. Set weight of all safe accounts to 3.
    // 2. Set weight of browserAccount and mobileAccount to 1.
    // 3. Set Keys Management Threshold to 3.
    // 4. Set Deploy Threshold to 2.
    // 5. Deploy account changes using 'setAll' function.

    const masterKey = keyManager.randomMasterKey();
    const safeAccount = masterKey.deriveIndex(1);
    const safeAccount1 = masterKey.deriveIndex(2);
    const safeAccount2 = masterKey.deriveIndex(2);
    const browserAccount = masterKey.deriveIndex(3);
    const mobileAccount = masterKey.deriveIndex(4);

    console.log("Main account: " + safeAccount.publicKey.toHex());
    console.log("Safe account #1: " + safeAccount1.publicKey.toHex());
    console.log("Safe account #2: " + safeAccount2.publicKey.toHex());
    console.log("Browser account: " + browserAccount.publicKey.toHex());
    console.log("Mobile account: " + mobileAccount.publicKey.toHex());

    let deploy;

    console.log("\n0.1 Funding safe account.");
    await keyManager.fundAccount(safeAccount);
    await keyManager.printAccount(safeAccount);

    console.log("\n0.2 Install Keys Manager contract");
    deploy = keyManager.keys.buildContractInstallDeploy(safeAccount);
    await keyManager.sendDeploy(deploy, [safeAccount]);
    await keyManager.printAccount(safeAccount);

    // 1. Set weight of all safe accounts to 3.
    const safeAccountWeight = 3;
    // 2. Set weight of browserAccount and mobileAccount to 1.
    const keyAccountWeight = 1;
    const accounts = [
        { publicKey: safeAccount.publicKey, weight: safeAccountWeight },
        { publicKey: safeAccount1.publicKey, weight: safeAccountWeight },
        { publicKey: safeAccount2.publicKey, weight: safeAccountWeight },
        { publicKey: browserAccount.publicKey, weight: keyAccountWeight },
        { publicKey: mobileAccount.publicKey, weight: keyAccountWeight },
    ];

    // 3. Set Keys Management Threshold to 3.
    const keyManagementThreshold = 3;
    // 4. Set Deploy Threshold to 2.
    const deployThreshold = 2;

    // 5. Deploy account changes using 'setAll' function.
    console.log("\n 1. Set weight of both safe accounts to 3.");
    console.log("\n 2. Set weight of browserAccount and mobileAccount to 1.");
    console.log("\n 3. Set Keys Management Threshold to 3.");
    console.log("\n 4. Set Deploy Threshold to 2.");
    console.log("\n Update keys deploy.");

    deploy = keyManager.keys.setAll(safeAccount, deployThreshold, keyManagementThreshold, accounts);
    await keyManager.sendDeploy(deploy, [safeAccount]);
    await keyManager.printAccount(safeAccount);

})();
```
After run this code by modify the source code at package.json, we had:

```
(env) root@kaedenlaci72:~/keys-manager/client# npm run start:scenario_5

> keys-manager@1.0.0 start:scenario_5
> node -r dotenv/config ./src/scenario_5.js

Main account: 020308ea1197a58ecb72b6520220280b49e6c486e5e1b0be79bd1de6cf68b093624f
Safe account #1: 020218030d9fa0b3f0d18537baeebd3424dd95089cfed500d2794f8486600a68abad
Safe account #2: 020218030d9fa0b3f0d18537baeebd3424dd95089cfed500d2794f8486600a68abad
Browser account: 0202178e0c6191246f487ae20d2ccfaeef6ab507f08b6526a4e62762604b4e0ced05
Mobile account: 02037b384f6cfd9b72ea11afc88e96ad9d725445fa6be5cb77ed0c1293eb99286f96

0.1 Funding safe account.
Signed by: account-hash-ac873ad1b785f6714028e6eb8ef0b5340315aac49fd7332bbf5e86c2d6631913
Deploy hash: 8eac5fef33b45d45f745d355053eeae5aeee97a7fc151452988be1605532313a
Deploy result:
{
  deploy: {
    hash: '8eac5fef33b45d45f745d355053eeae5aeee97a7fc151452988be1605532313a',
    header: {
      account: '012a125d66bf5297d67afd380da38d4c6f786b961d14ed4c060cf8f50309ec732e',
      timestamp: '2021-09-24T20:40:13.602Z',
      ttl: '30m',
      gas_price: 1,
      body_hash: '4bb11987a738ee8a207eba1de06b7b2716066de5bc14e450b80387264a158b97',
      dependencies: [],
      chain_name: 'casper-net-1'
    },
    payment: { ModuleBytes: [Object] },
    session: { Transfer: [Object] },
    approvals: [ [Object] ]
  }
}

[x] Current state of the account:
{
  _accountHash: 'account-hash-613c7910deb16fe6f4e667735d0d6b42f0b256ee48f5a7619211961e7261c9a9',
  namedKeys: [],
  mainPurse: 'uref-b540957939639ba376c5f51c7377ff691efd7224773205f70bb37759a62336a3-007',
  associatedKeys: [
    {
      accountHash: 'account-hash-613c7910deb16fe6f4e667735d0d6b42f0b256ee48f5a7619211961e7261c9a9',
      weight: 1
    }
  ],
  actionThresholds: { deployment: 1, keyManagement: 1 }
}

0.2 Install Keys Manager contract
Signed by: account-hash-613c7910deb16fe6f4e667735d0d6b42f0b256ee48f5a7619211961e7261c9a9
Deploy hash: 6d543139e5d30394160b0913d6dcb299b6736cb5973c28cb4c71c14d9113b181
Deploy result:
{
  deploy: {
    hash: '6d543139e5d30394160b0913d6dcb299b6736cb5973c28cb4c71c14d9113b181',
    header: {
      account: '020308ea1197a58ecb72b6520220280b49e6c486e5e1b0be79bd1de6cf68b093624f',
      timestamp: '2021-09-24T20:41:18.734Z',
      ttl: '30m',
      gas_price: 1,
      body_hash: '8b75c87f0c5c33503df86050553e6a490fdee8d5154d9eececdc7c22618217c8',
      dependencies: [],
      chain_name: 'casper-net-1'
    },
    payment: { ModuleBytes: [Object] },
    session: { ModuleBytes: [Object] },
    approvals: [ [Object] ]
  }
}

[x] Current state of the account:
{
  _accountHash: 'account-hash-613c7910deb16fe6f4e667735d0d6b42f0b256ee48f5a7619211961e7261c9a9',
  namedKeys: [
    {
      name: 'keys_manager',
      key: 'hash-f67107aecf32697f395fd4b166d3c632e64151b8b091ea853cd0ff4966a4dabd'
    },
    {
      name: 'keys_manager_hash',
      key: 'uref-a7b14ea11f497c7ac3a560f75585bbc1e33e26b6d30057ec57c8347dcdb437f6-007'
    }
  ],
  mainPurse: 'uref-b540957939639ba376c5f51c7377ff691efd7224773205f70bb37759a62336a3-007',
  associatedKeys: [
    {
      accountHash: 'account-hash-613c7910deb16fe6f4e667735d0d6b42f0b256ee48f5a7619211961e7261c9a9',
      weight: 1
    }
  ],
  actionThresholds: { deployment: 1, keyManagement: 1 }
}

 1. Set weight of both safe accounts to 3.

 2. Set weight of browserAccount and mobileAccount to 1.

 3. Set Keys Management Threshold to 3.

 4. Set Deploy Threshold to 2.

 Update keys deploy.
Signed by: account-hash-613c7910deb16fe6f4e667735d0d6b42f0b256ee48f5a7619211961e7261c9a9
Deploy hash: 9eacd3a5994eed29855d258c9c66a8c9e922c6fe035fad51051a1a03533c927d
Deploy result:
{
  deploy: {
    hash: '9eacd3a5994eed29855d258c9c66a8c9e922c6fe035fad51051a1a03533c927d',
    header: {
      account: '020308ea1197a58ecb72b6520220280b49e6c486e5e1b0be79bd1de6cf68b093624f',
      timestamp: '2021-09-24T20:42:24.286Z',
      ttl: '30m',
      gas_price: 1,
      body_hash: '47bbdd74b799be021f2776e88ed9f47a1c7d1f60d8221fe24ea93629986571e3',
      dependencies: [],
      chain_name: 'casper-net-1'
    },
    payment: { ModuleBytes: [Object] },
    session: { StoredContractByName: [Object] },
    approvals: [ [Object] ]
  }
}

[x] Current state of the account:
{
  _accountHash: 'account-hash-613c7910deb16fe6f4e667735d0d6b42f0b256ee48f5a7619211961e7261c9a9',
  namedKeys: [
    {
      name: 'keys_manager',
      key: 'hash-f67107aecf32697f395fd4b166d3c632e64151b8b091ea853cd0ff4966a4dabd'
    },
    {
      name: 'keys_manager_hash',
      key: 'uref-a7b14ea11f497c7ac3a560f75585bbc1e33e26b6d30057ec57c8347dcdb437f6-007'
    }
  ],
  mainPurse: 'uref-b540957939639ba376c5f51c7377ff691efd7224773205f70bb37759a62336a3-007',
  associatedKeys: [
    {
      accountHash: 'account-hash-4162fe506afa939907bd29bf051653aac0cb19130bf188c5b780a5cb92c8e4d4',
      weight: 3
    },
    {
      accountHash: 'account-hash-429668e62e587b82f28989f2ba5d47c5748155d26e21e69957b9ee89e47544bd',
      weight: 1
    },
    {
      accountHash: 'account-hash-613c7910deb16fe6f4e667735d0d6b42f0b256ee48f5a7619211961e7261c9a9',
      weight: 3
    },
    {
      accountHash: 'account-hash-ae060a848358afd7ede083a487e12197c35ca06fc108693fc10abcceba1e7ab0',
      weight: 1
    }
  ],
  actionThresholds: { deployment: 2, keyManagement: 3 }
}
```


# Task #4: Learn to transfer tokens to an account on the Casper Testnet

**Put the transfer in deploy**

![](https://i.imgur.com/7JCWq4P.png)

**Get the transfer in deploy**

![](https://i.imgur.com/1VpA7uB.png)

# Task #5: Learn to Delegate and Undelegate on the Casper Testnet.

**Delegate to validator on Portal**

![](https://i.imgur.com/twjo7Y5.png)

**Undelegate from validator on Portal**

![](https://i.imgur.com/nmY9Sre.png)


