diff --git a/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-truffle.md b/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-truffle.md index e2be4f63..24c23177 100644 --- a/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-truffle.md +++ b/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-truffle.md @@ -21,7 +21,7 @@ keywords: - [โš’ Starting a new Truffle Project](#-starting-a-new-truffle-project) - [โš’ Configuring XDC Mainnet and Apothem Testnet on Truffle](#-configuring-xdc-mainnet-and-apothem-testnet-on-truffle) - [โš’ Adding Testnet XDC to Development Wallet](#-adding-testnet-xdc-to-development-wallet) -- [๐Ÿ’ต Writing our first XRC20 Token](#-writing-our-first-xrc20-token) +- [๐Ÿ’ต Writing your first XRC20 Token](#-writing-our-first-xrc20-token) - [๐Ÿ’ต Constants](#-constants) - [๐Ÿ’ต Events](#-events) - [๐Ÿ’ต Methods](#-methods) @@ -30,10 +30,10 @@ keywords: - [๐Ÿ” Interacting with your contract on the Block Explorer](#-interacting-with-your-contract-on-the-block-explorer) # ๐Ÿ“ฐ Overview -[Truffle](https://trufflesuite.com/) is a blockchain development environment, which you can use to create and test smart contracts by levering an Ethereum Virtual Machine. +[Truffle](https://trufflesuite.com/) is a blockchain development environment that you can use to create and test smart contracts by levering an Ethereum Virtual Machine. ### What you will learn -In this tutorial, you will learn how to set up Truffle and use it to build, test and deploy a XRC20 Token on both the XDC Network mainnet and XDC Apothem testnet. +In this tutorial, you will learn how to set up Truffle and use it to build, test, and deploy a XRC20 Token on both the XDC Network mainnet and XDC Apothem testnet. ### What you will do - Install and setup Truffle @@ -45,7 +45,7 @@ In this tutorial, you will learn how to set up Truffle and use it to build, test ## ๐Ÿ“ฐ About XRC20 Tokens -XRC20 is a set of rules to standardize assets on the XinFin network. Every XRC20 Token must be able to execute the following methods: +XRC20 is a set of rules to standardize assets on the XDC network. Every XRC20 token must be able to execute the following methods: - `totalSupply()` - `balanceOf(address account)` @@ -54,31 +54,31 @@ XRC20 is a set of rules to standardize assets on the XinFin network. Every XRC20 - `approve(address spender, uint amount)` - `transferFrom(address sender, address recipient, uint amount)` -These are the minimum required methods that allow an asset on the XinFin network to be called an XRC20 token. Also, a XRC20 token must be able to emit the following `Events` on the blockchain: +These are the minimum required methods that allow an asset on the XDC Network to be called an XRC20 token. An XRC20 token must be able to emit the following `Events` on the blockchain: - `Approval(address indexed tokenOwner, address indexed spender, uint tokens)` - `Transfer(address indexed from, address indexed to, uint tokens)` -Events are helpers that come in handy in the exhaustive labor of indexing state changes, and they are essential to off-chain applications to find relevant data on the blockchain. By mapping all `Transfer` events, for example, we can fetch all the historic data on token transfers more easily. +Events are help with the process of indexing state changes, and they are essential to allowing off-chain applications to find relevant data on the blockchain. By mapping all `Transfer` events, for example, we can fetch all the historic data on token transfers more easily. -Last but not least, a few contract constants that are public that are also very important to have are: +Several contract constants are public and very important to have: - `name` - `symbol` - `decimals` -Without these public constants, it would be impossible to label tokens on block explorers, for example. In this tutorial we will deploy a XRC20 token that have all the `Methods`, `Events` and `Constants` mentioned above. +Without these public constants, it would be impossible to label tokens on block explorers, for example. In this tutorial, we will deploy a XRC20 token that have all the `Methods`, `Events` and `Constants` mentioned above. # ๐Ÿš€ Setting up the development environment -There are a few technical requirements before we start. Please install the following: +Here are several technical requirements before you get started. Please install the following: - [Node.js v8+ LTS and npm](https://nodejs.org/en/)ย (comes with Node) - [Git](https://git-scm.com/) -Once we have those installed, we only need one command to install Truffle: +Once you have installed those, you only need one command to install Truffle: ```bash npm install -g truffle @@ -98,13 +98,13 @@ If you see an error instead, make sure that your npm modules are added to your p ## โš’ Starting a new Truffle Project -Lets start by setting up our folder, we are creating a project called `XRC20`, create a new `XRC20` folder by running on terminal +Start by setting up our folder. As we are creating a project called `XRC20`, create a new `XRC20` folder by running on terminal: ```bash mkdir XRC20 && cd XRC20 ``` -And running `truffle init`. If truffle is correctly installed on your local environment, you should see the following message: +Next, run `truffle init`. If truffle is correctly installed on your local environment, you should see the following message: ```bash Starting init... @@ -114,14 +114,14 @@ Starting init... Init successful, sweet! -Try our scaffold commands to get started: +Try these scaffold commands to get started: $ truffle create contract YourContractName # scaffold a contract $ truffle create test YourTestName # scaffold a test http://trufflesuite.com/docs ``` -And your folder files will look like this: +Your folder files will look like this:

Step 01 @@ -130,9 +130,9 @@ And your folder files will look like this: ## โš’ Configuring XDC Mainnet and Apothem Testnet on Truffle -In order to get started deploying new contracts on XDC Mainnet and/or Apothem, we need to install two new dependencies that will be used in the `truffle-config.js` file. These dependencies are `@truffle/hdwallet-provider` and `dotenv`. First choose your preferred package manager. In this example we are using `yarn` but you can also use `npm`. +In order to get started deploying new contracts on the XDC Mainnet and/or Apothem, we need to install two new dependencies that will be used in the `truffle-config.js` file. These dependencies are `@truffle/hdwallet-provider` and `dotenv`. First choose your preferred package manager. In this example we are using `yarn` but you can also use `npm`. - If you never used `yarn` before, you might need to install it first.
โ€ผ๏ธYou can skip this step if you already have yarn installedโ€ผ๏ธ +If you never used `yarn` before, you will likely need to install it first.
โ€ผ๏ธYou can skip this step if you already have yarn installedโ€ผ๏ธ ```sh npm install --global yarn @@ -161,7 +161,7 @@ MNEMONIC=arm derive cupboard decade course garlic journey blast tribe describe c ๐Ÿšจ **Do not use the mnemonic in the example above in production or you can risk losing your assets and/or the ownership of your smart contracts!** ๐Ÿšจ -And finally, we can configure the `truffle-config.js` file for both Apothem and XinFin Networks by writting: +Finally, you can configure the `truffle-config.js` file for both Apothem and XinFin Networks by writting: ```jsx require('dotenv').config(); @@ -235,7 +235,7 @@ And the console should log all accounts bound to your mnemonic phrase as follow: These accounts are on the Ethereum standard format starting with `0x`, but we can simply switch `0x` for `xdc`. By default, the deployment account is the first account from the list above: `xdcA4e66f4Cc17752f331eaC6A20C00756156719519`. -With this account in hand, we can head to the [Apothem Faucet](https://faucet.apothem.network/) and claim some TXDC for development purposes: +With this account, you can head to the [Apothem Faucet](https://faucet.apothem.network/) and claim some TXDC for development purposes:

Step 02 @@ -245,13 +245,13 @@ With this account in hand, we can head to the [Apothem Faucet](https://faucet.ap The source code for the XRC20 Token used in this tutorial is available here: [XRC20 Contract Folder](./../../how-to/XRC20/Truffle/XRC20/contracts/MyToken.sol). But we will address all `Events`, `Methods` and `Constants` mentioned in the section [๐Ÿ“ฐ About XRC20 Tokens](#-about-xrc20-tokens). -Lets start by creating the `XRC20.sol` file: +You can start by creating the `XRC20.sol` file: ```sh touch ./contracts/XRC20.sol ``` -And write the shell of our smart contract by writing: +Next, write the shell of our smart contract by writing: ```solidity // SPDX-License-Identifier: MIT @@ -269,7 +269,7 @@ contract XRC20Token { ## ๐Ÿ’ต Constants -Inside our `contract XRC20Token` We will instantiate `name`, `symbol` and `decimals` as public variables, a private `_totalSupply` that will be used on our `totalSupply()` method later on and two mapping variables `balances` and `allowances`, that are key/value variables that maps user balances and approved spending allowances to other users: +Inside your `contract XRC20Token`, you will need to instantiate `name`, `symbol` and `decimals` as public variables as well as a private `_totalSupply` that will be used on our `totalSupply()` method later on. You'll also have two mapping variables, `balances` and `allowances`, that are key/value variables that maps user balances and approved spending allowances to other users: ```solidity // SPDX-License-Identifier: MIT @@ -298,7 +298,7 @@ contract XRC20Token { ## ๐Ÿ’ต Events -As mentioned in [๐Ÿ“ฐ About XRC20 Tokens](#-about-xrc20-tokens). Events are very important part of a Smart Contract logic. Events have `indexed` variables that are variables that can be filtered by off-chain interfaces. We might be tempted to index all the variables that are tied to an on-chain event, however we can't go crazy about it since Solidity has a _maximum of 3 indexed variable_ limitation for Events. Lets write both `Approval` and `Transfer` events: +As mentioned in [๐Ÿ“ฐ About XRC20 Tokens](#-about-xrc20-tokens), events are very important part of a smart contract logic. Events have `indexed` variables that are variables that can be filtered by off-chain interfaces. You might be tempted to index all the variables tied to an on-chain event, however Solidity has a _maximum of 3 indexed variable_ limitation for events. You should write both `Approval` and `Transfer` events: ```solidity // SPDX-License-Identifier: MIT @@ -333,7 +333,7 @@ contract XRC20Token { ## ๐Ÿ’ต Methods -We need to create the six methods mentioned in [๐Ÿ“ฐ About XRC20 Tokens](#-about-xrc20-tokens) (`totalSupply`, `balanceOf`, `allowance`, `transfer`, `approve` and `transferFrom`) and a `constructor` that is a function called only once when the contract is deployed, where we can parse as arguments information such as the token name, decimals and/or initial token supply: +We need to create the six methods mentioned in [๐Ÿ“ฐ About XRC20 Tokens](#-about-xrc20-tokens) (`totalSupply`, `balanceOf`, `allowance`, `transfer`, `approve` and `transferFrom`), as well as a `constructor` that is a function called only once when the contract is deployed. In the latter, we can attatch information such as the token name, decimals and/or initial token supply: ```solidity // SPDX-License-Identifier: MIT @@ -408,7 +408,7 @@ contract XRC20Token { } ``` -And here we have implemented everything we needed to make our token compliant with the XRC20 Standard. Of course there are more features we can implement to this contract, such as the [SafeMath](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeMath.sol) library that replace naive mathematical operations for methods that will avoid `underflows` and `overflows`, and supply management methods such as `mint` and `burn`. +Now you have implemented everything we needed to make our token compliant with the XRC20 standard. Of course there are more features we can implement to this contract, such as the [SafeMath](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeMath.sol) library that replace naive mathematical operations for methods that will avoid `underflows` and `overflows`, and supply management methods such as `mint` and `burn`. ## ๐Ÿ’ต Compiling and Deploying @@ -418,7 +418,7 @@ We can compile our `MyToken.sol` by running: truffle compile ``` -If everything is correctly configured and there is no errors, you should see the following message on your console: +If everything is correctly configured and there are no errors, you will see the following message on your console: ```sh Compiling your contracts... @@ -429,19 +429,19 @@ Compiling your contracts... - solc: 0.8.16+commit.07a7930e.Emscripten.clang ``` -And your folder should look like this: +Your folder should look like this:

Step 03

-In order to deploy our newly compiled contract artifacts to the blockchain, we need to create a deployment script into the migrations folder: +In order to deploy our newly compiled contract artifacts to the blockchain, you'll need to create a deployment script into the migrations folder: ```sh touch ./migrations/1_token_migration.js ``` -And write the following migration script to the `1_token_migration.js` file: +Next, write the following migration script to the `1_token_migration.js` file: ```jsx const XRC20Token = artifacts.require("XRC20Token"); @@ -456,21 +456,21 @@ module.exports = function (deployer) { } ``` -If the migration script have no errors, we can go ahead and run the command: +If the migration script have no errors, you can run the following command for deployment on the XDC mainnet: ```sh truffle migrate --network xinfin ``` -For deployment on XDC mainet, or: +Or the following commard for deployment on the XDC Apothem Testnet: ```sh truffle migrate --network apothem ``` -For deployment on the XDC Apothem Testnet. In either case, you need to have enough funds to pay for gas fees on the address that is being used for development. +In either case, you'll need to have enough funds to pay for gas fees on the address that is being used for development. -If the deployment is sucessful, the console should log the following message after migrations complete processing: +If the deployment is sucessful, the console will log the following message after migrations complete processing: ```sh 1_token_migration.js @@ -502,15 +502,15 @@ Summary # ๐Ÿ” Veryfing Contracts on the Block Explorer -Once you have successfully deployed your smart contract to the blockchain, it might be interesting to verify you contract on [XinFin Block Explorer](https://explorer.xinfin.network/). +Once you have successfully deployed your smart contract to the blockchain, it might be interesting to verify yout contract on [XinFin Block Explorer](https://explorer.xinfin.network/). -First lets check the address our contract is deployed to by running: +You can check the address that your contract is deployed to by running: ```sh truffle networks ``` -If you have a contract already deployed, the console should log something like this: +If you have a contract deployed, the console should log something like this: ```sh Network: apothem (id: 51) @@ -520,7 +520,7 @@ Network: xinfin (id: 50) XRC20Token: 0x53bA8Cb12EaF09E6B0b671F39ac4798A6DA7d660 ``` -Here we have a `XRC20Token` contract deployed on XDC Mainnet at the `0x53bA8Cb12EaF09E6B0b671F39ac4798A6DA7d660`. This address is in the Ethereum standard but we can simply swap the `0x` prefix for `xdc` and search for our newly deployed contract on [XinFin Block Explorer](https://explorer.xinfin.network/): +In this example, we have a `XRC20Token` contract deployed on XDC Mainnet at the `0x53bA8Cb12EaF09E6B0b671F39ac4798A6DA7d660`. This address is in the Ethereum standard but we can simply swap the `0x` prefix for `xdc` and search for our newly deployed contract on [XinFin Block Explorer](https://explorer.xinfin.network/):

Verify 01 @@ -528,7 +528,7 @@ Here we have a `XRC20Token` contract deployed on XDC Mainnet at the `0x53bA8Cb12 And click in the `Verify And Publish` Option. -We will be redirected to the Contract verification page where we need to fill out: +You will be redirected to the contract verification page where you have to fill out: - Contract Name: XRC20Token - Compiler: Check your `truffle-config.js` file for Compiler Version @@ -540,7 +540,7 @@ Once everything is filled out, press Submit! Verify 02

-If everything is correctly filled out, your contract page on the block explorer should display a new tab called `Contract`: +If everything is correctly filled out, your contract page on the block explorer will display a new tab called `Contract`:

Verify 03 @@ -548,27 +548,27 @@ If everything is correctly filled out, your contract page on the block explorer ## ๐Ÿ” Interacting with your contract on the Block Explorer -With your XDCPay wallet, it is possible to interact with verified Smart Contracts on the [XinFin Network Block Explorer](https://explorer.xinfin.network/). You can read from, write to, or simply read the information tied to your Smart Contract on the blockchain. +With your XDCPay wallet, it is possible to interact with verified smart sontracts on the [XinFin Network Block Explorer](https://explorer.xinfin.network/). You can read from, write to, or simply read the information tied to your smart contract on the blockchain. -Lets head to the `Contract` tab on the explorer, choose `Write Contract` and click in `Connect to Web3` to connect your XDCPay wallet. +Lets head to the `Contract` tab on the explorer. Choose `Write Contract` and click in `Connect to Web3` to connect your XDCPay wallet.

Verify 04

-Lets try transfering `500 MTK` tokens that we have just created to a new wallet `xdc0431d52fe37f3839895018272dfa3ba189fce07e`. Lets fill out the `recipient` field with the new wallet address, and fill out the `amout` field with `500 * 10^18`. Remember that our token have 18 decimals, and when we write numbers with decimals to the blockchain we have to account for the decimals because the Virtual Machine do not understand floating numbers like we humans do: +You can try transfering `500 MTK` tokens that we have just created to a new wallet `xdc0431d52fe37f3839895018272dfa3ba189fce07e`. Lets fill out the `recipient` field with the new wallet address, and fill out the `amout` field with `500 * 10^18`. Remember that our token has 18 decimals, and when you write numbers with decimals to the blockchain you must to account for the decimals as the virtual machine does not understand floating numbers like we humans do:

Verify 05

-After clicking in `Write`, we need to confirm the transaction on the XDCPay wallet: +After clicking `Write`, you need to confirm the transaction on the XDCPay wallet:

Verify 05

-And we can check our successful transaction on the [Block Explorer!](https://explorer.xinfin.network/txs/0xa365a7edea3af9ed22c6dffb2f24987f1941f21dbd4d9bbb13b11022439de96a#overview) +You can check your successful transaction on the [Block Explorer!](https://explorer.xinfin.network/txs/0xa365a7edea3af9ed22c6dffb2f24987f1941f21dbd4d9bbb13b11022439de96a#overview) ---