Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Current »

Recording on Youtube:

Dial in Information is at: https://casperlabs.atlassian.net/wiki/spaces/REL/pages/136544674/Weekly%2BWorkshops%2BHome

Participants

During this workshop, we will demonstrate the use of the example ERC20 Token contract. We will deploy the contract to DevNet, and then we will use scripts to interact with the contract on the CL Blockchain.

Goals

  • Learn how to work with the ERC20 example contract.

  • Install the client - version 0.11

  • Build the contracts

  • Deploy to DevNet

  • Check account balances in Clarity

  • We will record the session.

Step by Step Plan

  1. Clone the repository on your machine - the code is presently in a branch.

git clone -b dev https://github.com/CasperLabs/CasperLabs.git 

2. Install the CasperLabs client using brew, apt, docker or tarball ….

3. Compile contracts

cd CasperLabs
cd execution-engine
make setup
make build-contract-rs/erc20-smart-contract

4. Fund accounts on DevNet - you can also create new accounts for the test as well. Make sure that all the keys you plan on using have been funded.

Create 3 keys - Key1, Key2, Key3 - and fund Key1 and Key2 by using https://clarity.casperlabs.io.

5. Export your public and private keys to make the commands easier. Export the information for Key1

export PRIV="path_to_private_key_for_Key1
export PUB="public_key_string_from_clarity"

If you are using the Python client, you can skip this step. Otherwise, export the location of the client.

export CL_CLIENT=casperlabs-client

Navigate to the scripts directory - there are shell scripts here that make things easier.

cd ..
cd hack/docker/scripts

There is a script called erc20.sh in the scripts directory. To see all the commands it supports run

./erc20.sh

Now deploy the ERC20 smart contract & specify the token supply

./erc20.sh deploy $PRIV [supply amount]

This step creates your initial token supply & the token contract in your account.

Now let’s take a look at GraphQL and confirm that we can see the token contract in our account. From https://clarity.casperlabs.io, Log in and select the GraphQL console from the home page. Create a new tab. Have the hash of the block containing your deployment (or the latest block hash) and the Base16 public key of key1. Enter this query:

query {
  globalState(
    blockHashBase16Prefix: "LATEST BLOCK HASH"
    StateQueries: [
      {
        keyType: Address
        keyBase16: "PUBLIC KEY FOR KEY1"
        pathSegments: []
      }
    ]
  ) {
    value {
      __typename
      ... on Account {
        pubKey
        associatedKeys {
          pubKey
          weight
        }
        actionThreshold {
          deploymentThreshold
          keyManagementThreshold
        }
        namedKeys{
          name
        }
      }
    }
  }
}

Under ‘namedKeys’ you should see 2 names - ‘erc20_proxy’ and ‘test-token’

{
  "data": {
    "globalState": [
      {
        "value": {
          "__typename": "Account",
          "pubKey": "877c399eab63c7d439d04e176811894c9f4ed3f43376ad8aa8b49c3b373749a7",
          "associatedKeys": [
            {
              "pubKey": "877c399eab63c7d439d04e176811894c9f4ed3f43376ad8aa8b49c3b373749a7",
              "weight": 1
            }
          ],
          "actionThreshold": {
            "deploymentThreshold": 1,
            "keyManagementThreshold": 1
          },
          "namedKeys": [
            {
              "name": "erc20_proxy"
            },
            {
              "name": "mint"
            },
            {
              "name": "pos"
            },
            {
              "name": "test_token"
            }
          ]
        }
      }
    ]
  }
}

Next we can check the balance in the token contract.

./erc20.sh balance $PUB $PUB

This will return the same number as the supply amount provided during the deploy command.

Next we can perform a token transfer to key2

export KEY2=[public-hex-for-key2]
./erc20.sh transfer $PRIV $PUB $KEY2 [amount]

Now we will check the balance at Key2

./erc20.sh balance $PUB $KEY2

You should see the balance of Key2 as the amount you transferred.

Next we will authorize Key2 to transfer some amount of token

./erc20.sh approve $PRIV $PUB $KEY2 [amount authorized]

This will set the amount that Key2 is authorized to transfer.

Next we will use Key2 to transfer token to Key3. Make sure that Key2 is funded with tokens from the faucet.

export KEY3=[hex of public key for key3]
export PRIV2=[path to private key for key2]
./erc20.sh transferFrom $PRIV2 $PUB $PUB $KEY3 [some amount less than authorized amount]

Then verify the balance at Key3

./erc20.sh balance $PUB $KEY3

It is also possible to purchase more token using the native CLX token

./erc20.sh buy $PRIV $PUB [amount to purchase]

Now check the balance, and do the math!

./erc20.sh balance $PUB $PUB

Software Version (GitHash)

Docker tag: dev

CasperLabs Client 0.11.0 (5777274434bf8cb676c43b0a0ca28f4e015c683e)

What you need to know:

  • The token contract has a default name ‘test-token’ - it’s possible to name the token something different if you want to do so.

Notes:

Title

Description

Notes

Verify pre-requisites

Check that everyone has managed to get through the setup.

Does everyone have keys in Clarity?

Has everyone cloned the repository and built the contracts?

Does everyone have the client installed? What is the version number for the Client?

Outcome:

  • Folks need to make sure they are running the latest version of Ubuntu.

Action items

For Help - go to Discord: https://discord.gg/mpZ9AYD

Decisions

  • No labels