Leçon 5

Interacting with the LearnCoin Contract

By the end of this lesson, you should be able to: 1.Understand the functions of the LearnCoin contract. 2.Know how to interact with the LearnCoin contract through the Remix Ethereum IDE.

Introduction

In the previous lessons, we discussed the structure of the LearnCoin contract, and its deployment on the Goerli Testnet. Now, we will guide you through the process of interacting with the contract using the Remix Ethereum IDE.

The LearnCoin contract comes with several functions that you can call to perform different operations, such as pausing token transfers, unpausing them, creating snapshots, and more. However, not all functions are accessible to all users. Some functions can only be called by accounts with specific roles (like the contract owner).

Let’s dive in and explore these functionalities. From the left panel of remix, click on Deploy & Run Transactions button and go below, you’ll find Deployd contract and you’ll able to see something like this:

This is the list of all the functions you can or can’t call.

Contract Functions Overview

The LearnCoin contract includes a set of public functions that you can call from Remix IDE:

  1. pause(): This function can be called to pause all token transfers. It is only callable by accounts with the PAUSER_ROLE.

  2. unpause(): This function can be called to unpause token transfers. It is also only callable by accounts with the PAUSER_ROLE.

  3. snapshot(): This function is used to take a snapshot of the current state of token balances. It is only callable by accounts with the SNAPSHOT_ROLE.

  4. decimals(): This function returns the number of decimals the token uses - typically 18. This is a read-only function and can be called by anyone.

  5. DEFAULT_ADMIN_ROLE(): This function returns the default admin role. It is a read-only function and can be called by anyone.

  6. DOMAIN_SEPARATOR(), EIP712DOMAIN(), name(), PAUSER_ROLE(), SNAPSHOT_ROLE(), symbol(), totalSupply(): These are all read-only functions that return various pieces of information about the contract. They can be called by anyone.

The following functions can be interacted with directly through the Remix IDE:

Pause and Unpause Token Transfers

To pause all token transfers, click on the pause() function. This function can only be called by the contract owner, and you will need to confirm the transaction through MetaMask.

Unpausing works in a similar way. Simply click on the unpause() function and confirm the transaction.

Create a Snapshot

To create a snapshot of token balances, click on the snapshot() function and confirm the transaction.

View Contract Information

You can view various pieces of information about the contract by calling the following functions:

  • decimals(): View the number of decimals the token uses.
  • DEFAULT_ADMIN_ROLE(): View the default admin role.
  • DOMAIN_SEPARATOR(), EIP712DOMAIN(), name(), PAUSER_ROLE(), SNAPSHOT_ROLE(), symbol(), totalSupply(): View various details about the contract.
    Remember, you can call these functions by clicking on their names in the Remix IDE.

For example, if you ask for the token supply by clicking totalSupply, the output is going to be:

Conclusion

Congratulations on reaching this far! Now, you should be familiar with how to interact with the LearnCoin contract through the Remix Ethereum IDE. Understanding these interactions is key to effectively managing your token on the Ethereum network.

Clause de non-responsabilité
* Les investissements en cryptomonnaies comportent des risques importants. Veuillez faire preuve de prudence. Le cours n'est pas destiné à fournir des conseils en investissement.
* Ce cours a été créé par l'auteur qui a rejoint Gate Learn. Toute opinion partagée par l'auteur ne représente pas Gate Learn.
Catalogue
Leçon 5

Interacting with the LearnCoin Contract

By the end of this lesson, you should be able to: 1.Understand the functions of the LearnCoin contract. 2.Know how to interact with the LearnCoin contract through the Remix Ethereum IDE.

Introduction

In the previous lessons, we discussed the structure of the LearnCoin contract, and its deployment on the Goerli Testnet. Now, we will guide you through the process of interacting with the contract using the Remix Ethereum IDE.

The LearnCoin contract comes with several functions that you can call to perform different operations, such as pausing token transfers, unpausing them, creating snapshots, and more. However, not all functions are accessible to all users. Some functions can only be called by accounts with specific roles (like the contract owner).

Let’s dive in and explore these functionalities. From the left panel of remix, click on Deploy & Run Transactions button and go below, you’ll find Deployd contract and you’ll able to see something like this:

This is the list of all the functions you can or can’t call.

Contract Functions Overview

The LearnCoin contract includes a set of public functions that you can call from Remix IDE:

  1. pause(): This function can be called to pause all token transfers. It is only callable by accounts with the PAUSER_ROLE.

  2. unpause(): This function can be called to unpause token transfers. It is also only callable by accounts with the PAUSER_ROLE.

  3. snapshot(): This function is used to take a snapshot of the current state of token balances. It is only callable by accounts with the SNAPSHOT_ROLE.

  4. decimals(): This function returns the number of decimals the token uses - typically 18. This is a read-only function and can be called by anyone.

  5. DEFAULT_ADMIN_ROLE(): This function returns the default admin role. It is a read-only function and can be called by anyone.

  6. DOMAIN_SEPARATOR(), EIP712DOMAIN(), name(), PAUSER_ROLE(), SNAPSHOT_ROLE(), symbol(), totalSupply(): These are all read-only functions that return various pieces of information about the contract. They can be called by anyone.

The following functions can be interacted with directly through the Remix IDE:

Pause and Unpause Token Transfers

To pause all token transfers, click on the pause() function. This function can only be called by the contract owner, and you will need to confirm the transaction through MetaMask.

Unpausing works in a similar way. Simply click on the unpause() function and confirm the transaction.

Create a Snapshot

To create a snapshot of token balances, click on the snapshot() function and confirm the transaction.

View Contract Information

You can view various pieces of information about the contract by calling the following functions:

  • decimals(): View the number of decimals the token uses.
  • DEFAULT_ADMIN_ROLE(): View the default admin role.
  • DOMAIN_SEPARATOR(), EIP712DOMAIN(), name(), PAUSER_ROLE(), SNAPSHOT_ROLE(), symbol(), totalSupply(): View various details about the contract.
    Remember, you can call these functions by clicking on their names in the Remix IDE.

For example, if you ask for the token supply by clicking totalSupply, the output is going to be:

Conclusion

Congratulations on reaching this far! Now, you should be familiar with how to interact with the LearnCoin contract through the Remix Ethereum IDE. Understanding these interactions is key to effectively managing your token on the Ethereum network.

Clause de non-responsabilité
* Les investissements en cryptomonnaies comportent des risques importants. Veuillez faire preuve de prudence. Le cours n'est pas destiné à fournir des conseils en investissement.
* Ce cours a été créé par l'auteur qui a rejoint Gate Learn. Toute opinion partagée par l'auteur ne représente pas Gate Learn.