Skip to content

anhfactor/casper-get-started

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 

Repository files navigation

Get Started With Casper

1. Create and deploy a simple, smart contract with cargo casper and cargo test.

  • Installing rust, cargo-casper with rust package manager
  • Create the project which I named 1-simple-smart-contract
  • Compile contract with WebAssembly and build it
cd contract
rustup install $(cat rust-toolchain)
rustup target add --toolchain $(cat rust-toolchain) wasm32-unknown-unknown
cargo build --release

Screen Shot 2021-09-17 at 08 18 54

  • Test the contract.

Screen Shot 2021-09-17 at 00 02 30

  • Deploy a simple contract

Screen Shot 2021-09-17 at 10 32 00

2. Complete one of the existing tutorials for writing smart contracts.

I choose "A Counter Contract Tutorial".

  • Check faucet account:
nctl-view-faucet-account

Screen Shot 2021-09-17 at 10 21 47

  • Create local network and running node:
nctl-assets-setup && nctl-start

Screen Shot 2021-09-17 at 09 17 56

- Get the state root hash and query actual state.

Screen Shot 2021-09-17 at 10 38 15

  • Deploy counter contract and checking it state:

Screen Shot 2021-09-17 at 10 32 00

  • The counter is currently set to 1

Screen Shot 2021-09-17 at 11 03 01

  • After increment the counter again, the counter is set to 2.

Screen Shot 2021-09-17 at 11 07 23

3. Demonstrate key management concepts by modifying the client in the Multi-Sig tutorial to address one of the additional scenarios.

const keyManager = require('./key-manager');

(async function () {
    // 1. Weight of `fullAccount` to 2
    // 2. Key Management Threshold to 2
    // 3. Deploy Threshold to 1
    // 4. First new key with weight 1 (deploy key)

    let deploy;

    // 0. Initial state of the account.
    // There should be only one associated key (faucet) with weight 1.
    // Deployment Threshold should be set to 1.
    // Key Management Threshold should be set to 1.
    let masterKey = keyManager.randomMasterKey();
    let fullAccount = 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(fullAccount);
    await keyManager.printAccount(fullAccount);
    
    console.log("\n[x]0.2 Install Keys Manager contract");
    deploy = keyManager.keys.buildContractInstallDeploy(fullAccount);
    await keyManager.sendDeploy(deploy, [fullAccount]);
    await keyManager.printAccount(fullAccount);

    // 1. Set fullAccount's weight to 2
    console.log("\n1. Set faucet's weight to 2\n");
    deploy = keyManager.keys.setKeyWeightDeploy(fullAccount, fullAccount, 2);
    await keyManager.sendDeploy(deploy, [fullAccount]);
    await keyManager.printAccount(fullAccount);
    
    // 2. Set Keys Management Threshold to 2.
    console.log("\n2. Set Keys Management Threshold to 2\n");
    deploy = keyManager.keys.setKeyManagementThresholdDeploy(fullAccount, 2);
    await keyManager.sendDeploy(deploy, [fullAccount]);
    await keyManager.printAccount(fullAccount);
    
    // 3. Set Deploy Threshold to 1.
    console.log("\n3. Set Deploy Threshold to 1.\n");
    deploy = keyManager.keys.setDeploymentThresholdDeploy(fullAccount, 1);
    await keyManager.sendDeploy(deploy, [fullAccount]);
    await keyManager.printAccount(fullAccount);
    
    // 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(fullAccount, deployAccount, 1);
    await keyManager.sendDeploy(deploy, [fullAccount]);
    await keyManager.printAccount(fullAccount);
    
})();

And add scripts in package.json.

start:scenario-concept": "node -r dotenv/config ./src/scenario-concept.js"
  • Then run command:
npm run start:scenario-concept

Screen Shot 2021-09-17 at 12 07 06

Screen Shot 2021-09-17 at 12 07 21

4. Learn to transfer tokens to an account on the Casper Testnet.

Screen Shot 2021-09-17 at 12 29 39

  • Then transfer CSPR to account

Screen Shot 2021-09-17 at 12 40 02

  • Check balance account again

Screen Shot 2021-09-17 at 12 44 56

My testnet account: https://testnet.cspr.live/account/018375a8c5a3e58d257c07119269e560a1df2755c519de6a5ba136ead73ac23d11

Screen Shot 2021-09-17 at 12 48 24

5. Learn to Delegate and Undelegate on the Casper Testnet.

Screen Shot 2021-09-17 at 12 48 24

Screen Shot 2021-09-17 at 13 33 24

Screen Shot 2021-09-17 at 13 37 01

Screen Shot 2021-09-17 at 13 37 11

Releases

No releases published

Packages

No packages published