From 5de7e7bc01e3d2e9c9e98b1a49c673d7cd0976a3 Mon Sep 17 00:00:00 2001
From: Salomon Morales
Date: Wed, 16 Nov 2022 15:16:38 +0000
Subject: [PATCH 001/115] GitBook: [#135] No subject
---
run-a-node/masternode/full-node.md | 32 +++++++++++++++---------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/run-a-node/masternode/full-node.md b/run-a-node/masternode/full-node.md
index f7b6124e..8a254779 100644
--- a/run-a-node/masternode/full-node.md
+++ b/run-a-node/masternode/full-node.md
@@ -17,7 +17,7 @@ Follow the written steps starting from step 1, or you can watch the video tutori
Clone repository
```
-// git clone https://github.com/XinFinOrg/XinFin-Node.git
+git clone https://github.com/XinFinOrg/XinFin-Node.git
```
## Step 2
@@ -25,7 +25,7 @@ Clone repository
Then we change the directory to XinFin-Node
```
-// cd XinFin-Node
+cd XinFin-Node
```
@@ -35,7 +35,7 @@ Then we change the directory to XinFin-Node
We need to install Docker and Docker-Compose by running the following command:
```
-// sudo ./setup/install_docker.sh
+sudo ./setup/install_docker.sh
```
## Step 4
@@ -43,7 +43,7 @@ We need to install Docker and Docker-Compose by running the following command:
Create a new .env file and copy the env.example file that exist in the mainnet directory. We will ensure we are in the "mainnet" directory by typing these commands. Once in edit mode for the .env file, name your masternode and use an email address in the respective fields
```
-// cd mainnet
+cd mainnet
cp env.example .env
nano .env
```
@@ -51,7 +51,7 @@ nano .env
### For Testnet
```
-// // cd testnet
+cd testnet
cp env.example .env
nano .env
```
@@ -63,7 +63,7 @@ nano .env
#### For Mainnet run the following commands:
```
-// cd mainnet
+cd mainnet
sudo docker-compose -f docker-compose.yml up -d
```
@@ -74,7 +74,7 @@ At this point you should be able to see your masternode on the list of nodes [he
For Testnet run the following commands:
```
-// cd testnet
+cd testnet
sudo docker-compose -f apothem-network.yml up -d
```
@@ -85,7 +85,7 @@ Your coinbase address can be found in xdcchain/coinbase.txt file.
For troubleshooting purposes, you can stop the node by using the following command on either Mainnet or Testnet:
```
-// sudo docker-compose -f apothem-network.yml down
+sudo docker-compose -f apothem-network.yml down
```
## Downloading a Network Snapshot
@@ -97,25 +97,25 @@ The following steps are to expedite the syncing process of your node with the XD
### First safely bring down your node:
```
-// sudo docker-compose -f docker-compose.yml down
+sudo docker-compose -f docker-compose.yml down
```
### Then remove the old xdchain file from the server
```
-// rm -rf xdcchain.tar
+rm -rf xdcchain.tar
```
### Download the snapshot
```
-// wget https://download.xinfin.network/xdcchain.tar
+wget https://download.xinfin.network/xdcchain.tar
```
### Unpack the xdcchain.tar file
```
-// tar -xvzf xdcchain.tar
+tar -xvzf xdcchain.tar
```
### The unpacking will take some time, and it will look like this:
@@ -125,23 +125,23 @@ The following steps are to expedite the syncing process of your node with the XD
### The following command will move the xdcchain/XDC to xdcchain/XDC\_backup
```
-// mv xdcchain/XDC xdcchain/XDC_backup
+mv xdcchain/XDC xdcchain/XDC_backup
```
```
-// mv XDC xdcchain
+mv XDC xdcchain
```
### Then we are going to remove the old "nodekey" file
```
-// rm -rf xdcchain/XDC/nodekey
+rm -rf xdcchain/XDC/nodekey
```
### The last step is to run the bash upgrade.sh command
```
-// bash upgrade.sh
+bash upgrade.sh
```
This command will bring your node up and it will start syncing to the network. Once up and running, your node will be synced to the network in just a few minutes.
From a6fbd49d7a8901ad723952c21877be34ca5906fe Mon Sep 17 00:00:00 2001
From: mogithehurt <114102465+mogithehurt@users.noreply.github.com>
Date: Mon, 21 Nov 2022 23:46:02 +0530
Subject: [PATCH 002/115] Create Readme.md
---
how-to/XRC20/Foundry/Readme.md | 1 +
1 file changed, 1 insertion(+)
create mode 100644 how-to/XRC20/Foundry/Readme.md
diff --git a/how-to/XRC20/Foundry/Readme.md b/how-to/XRC20/Foundry/Readme.md
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/how-to/XRC20/Foundry/Readme.md
@@ -0,0 +1 @@
+
From 0ebb19db6c7e57131c747df9088020ec6aaef12c Mon Sep 17 00:00:00 2001
From: mogithehurt <114102465+mogithehurt@users.noreply.github.com>
Date: Mon, 21 Nov 2022 23:46:54 +0530
Subject: [PATCH 003/115] Add files via upload
---
how-to/XRC20/Foundry/readme.md | 595 ++++++++++++++++++++++++++++
how-to/XRC20/Foundry/remappings.txt | 2 +
2 files changed, 597 insertions(+)
create mode 100644 how-to/XRC20/Foundry/readme.md
create mode 100644 how-to/XRC20/Foundry/remappings.txt
diff --git a/how-to/XRC20/Foundry/readme.md b/how-to/XRC20/Foundry/readme.md
new file mode 100644
index 00000000..831a5415
--- /dev/null
+++ b/how-to/XRC20/Foundry/readme.md
@@ -0,0 +1,595 @@
+# How to make a XRC-20 Royalty Token with Foundry.
+This tutorial’s purpose is to create an XRC-20 token with foundry that will return a royalty amount (of that XRC-20 token) to the original creator of the contract.
+
+# 🧭 Table of contents
+
+- [🧭 Table of contents](#-table-of-contents)
+- [📰 Overview](#-overview)
+ - [What you will learn](#what-you-will-learn)
+ - [What you will do](#what-you-will-do)
+- [The Tools We're Using](#the-tools-were-using)
+- [Set up Foundry](#set-up-foundry)
+- [environment SetUp](#environment-setup)
+- [Smart Contract Development](#smart-contract-development)
+- [Testing Our Smart Contract](#testing-our-smart-contract)
+- [Deploying Our Smart Contract To The Blockchain](#deploying-our-smart-contract-to-the-blockchain)
+- [Veryfing Contracts on the Block Explorer](#veryfing-contracts-on-the-block-explorer)
+
+
+# 📰 Overview
+
+
+
+
+[Foundry](https://book.getfoundry.sh/) is a smart contract development toolchain.
+
+Foundry manages your dependencies, compiles your project, runs tests, deploys, and lets you interact with the chain from the command-line and via Solidity scripts.
+
+### What you will learn
+In this tutorial, you will learn how to set up Foundry and use it to build, test and deploy a XRC20 Royalty Token on both the XDC Network mainnet and XDC Apothem testnet.
+
+### What you will do
+- Install and setup Foundry
+- Create an XRC20 Royalty token
+- Compile the Contract
+- Deploy the Contract
+- Interact with the XRC20 Royalty token
+- Check the deployment status on [XDC Mainnet](https://explorer.xinfin.network/) and [XDC Testnet](https://apothem.blocksscan.io/)
+
+# The Tools We're Using
+- [Foundry](https://book.getfoundry.sh/) : a fast Solidity development toolkit that enables developers to write their tests in Solidity.
+- [Solmate](https://github.com/Rari-Capital/solmate) : a library that contains gas-optimized contracts such as ERC20, ERC721, and more.
+- [Visual Studio Code](https://code.visualstudio.com/) : a source-code editor made by Microsoft with the Electron Framework, for Windows, Linux and macOS.
+- [XDC Testnet explorer](https://explorer.xinfin.network/)
+- [Testnet XDC Faucet](https://faucet.apothem.network/) : a faucet that gives 1000 XDC for test.
+- [XDCPay](https://chrome.google.com/webstore/detail/xdcpay/bocpokimicclpaiekenaeelehdjllofo) : is an extension for accessing XDC's XDPoS enabled distributed applications, or "Dapps" in your browser.
+
+# Set up Foundry
+Before we can start writing some code, we need to set up our environment. We're going to be writing our contracts and testing them in Foundry.
+
+### Installing Foundry For MacOS / Linux:
+
+Open-up terminal and type in the command:
+
+```bash
+curl -L https://foundry.paradigm.xyz | bash
+```
+
+Afterward type:
+```bash
+foundryup
+```
+Foundry should now be installed and ready to go!
+
+### Installing Foundry For Windows:
+
+If using Windows, you need to install Foundry from the source. First, install [Rust](https://rustup.rs/) with the [official documentation](https://book.getfoundry.sh/getting-started/installation).
+
+Then, open the command prompt and type in the command:
+```bash
+cargo install --git https://github.com/foundry-rs/foundry foundry-cli anvil --bins --locked
+```
+To update from source, run the same command again.
+
+# environment SetUp
+
+Now that we've installed Foundry, it's time to set up our folder where we will write our smart contract. From the same terminal window that you installed Foundry, type the following commands:
+
+1. Make our folder where will we initialize our project. Then navigate into that folder with the following commands:
+```bash
+mkdir XRC20_Royalty && cd XRC20_Royalty
+```
+2. Initialize our Foundry project within our XRC20_Royalty folder:
+```bash
+forge init
+```
+3. Install Solmate into our Foundry project:
+```bash
+forge install rari-capital/solmate
+```
+4. Create a remappings.txt file for the Solmate library we just added:
+```bash
+touch remappings.txt
+```
+5. Open up your project in your IDE. For this tutorial, we’ll be using VSCode with this Solidity plugin:
+```bash
+code .
+```
+Here’s what our IDE looks like.
+
+
+
+
+6. Add these lines to remappings.txt so we can easily call the Solmate library in our contract:
+```bash
+solmate/=lib/solmate/src/
+forge-std=lib/forge-std/src/
+```
+Now that our environment and libraries are set up, we'll move into developing our smart contract!
+
+# Smart Contract Development
+
+We will make a contract that passes tokens to the original contract creator whenever a token is transferred between wallets!
+
+1. In your IDE, navigate to `src/Counter.sol` and rename the file to `RoyaltyToken.sol`.
+
+2. Import the Solmate ERC20 library in `RoyaltyToken.sol` and change the name of the contract. Under `pragma solidity ^0.8.14;`, add the following lines of code:
+```bash
+import { ERC20 } from "solmate/tokens/ERC20.sol";
+
+contract RoyaltyToken is ERC20 {}
+```
+3. Add in our state variables for the royalties. In the contract, add an address `royaltyAddress` variable and uint256 `royaltyFeePercentage` variable:
+```bash
+contract RoyaltyToken is ERC20 {
+ address public royaltyAddress;
+ uint256 public royaltyFeePercentage;
+}
+```
+4. Make a constructor for the token. A constructor is what creates our token from the imported Solmate template.
+
+Add the following variables to the constructor:
+
+1. `string memory _name`
+2. `string memory _token`
+3. `uint8 _decimals`
+4. `uint256 _royaltyFeePercentage`
+5. `uint256 _initialSupply`
+Directly after we’ve added these variables and closed the `()`, add `ERC20(_name, _symbol, _decimals)`.
+
+After that add brackets `{}` and inside the brackets set the following variables:
+
+Set `royaltyAddress` variable as the wallet address of the creator of the contract: `royaltyAddress = msg.sender;`
+The `RoyaltyFeePercentage` as the constructor variable: `royaltyFeePercentage = _royaltyFeePercentage;`
+Mint the tokens to the creator of the contract and pass in the `_initialSupply` variable: `_mint(msg.sender, _initialSupply);`
+Our constructor should now look like the following:
+```bash
+contract RoyaltyToken is ERC20 {
+ address public royaltyAddress;
+ uint256 public royaltyFeePercentage;
+
+ constructor(
+ string memory _name,
+ string memory _symbol,
+ uint8 _decimals,
+ uint256 _royaltyFeePercentage,
+ uint256 _initialSupply
+ ) ERC20(_name, _symbol, _decimals) {
+ royaltyAddress = msg.sender;
+ royaltyFeePercentage = _royaltyFeePercentage;
+ _mint(msg.sender, _initialSupply);
+ }
+}
+```
+5. Next, override the transfer function.
+```bash
+function transfer(address to, uint256 amount) public virtual returns (bool) {
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ balanceOf[to] += amount;
+ }
+
+ emit Transfer(msg.sender, to, amount);
+
+ return true;
+ }
+```
+
+Our contract now looks like this:
+
+```bash
+pragma solidity ^0.8.14;
+
+import { ERC20 } from "solmate/tokens/ERC20.sol";
+
+contract RoyaltyToken is ERC20 {
+ address public royaltyAddress;
+ uint256 public royaltyFeePercentage;
+
+ constructor(
+ string memory _name,
+ string memory _symbol,
+ uint8 _decimals,
+ uint256 _royaltyFeePercentage,
+ uint256 _initialSupply
+ ) ERC20(_name, _symbol, _decimals) {
+ royaltyAddress = msg.sender;
+ royaltyFeePercentage = _royaltyFeePercentage;
+ _mint(msg.sender, _initialSupply);
+ }
+
+ function transfer(address to, uint256 amount) public virtual returns (bool) {
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ balanceOf[to] += amount;
+ }
+
+ emit Transfer(msg.sender, to, amount);
+
+ return true;
+ }
+}
+```
+Add override after virtual in the function declaration:
+
+
+`function transfer(address to, uint256 amount) public virtual override returns (bool) {
+...
+} `
+Inside of the `transfer` function, create a uint256 called `royaltyAmount` and set it equal to the amount in the function parameters multiplied by the `royaltyFeePercentage` divided by `100`. This calculates the royalty amount that we will be sending to our `royaltyAddress`.
+```bash
+uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+```
+```bash
+function transfer(address to, uint256 amount) public virtual returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ balanceOf[to] += amount;
+ }
+
+ emit Transfer(msg.sender, to, amount);
+
+ return true;
+ }
+```
+In the `unchecked {}` for the `balanceOf[to]`, subtract the amount by the `royaltyAmount` and add an additional `balanceOf[royaltyAddress]` where we add the `royaltyAmount`:
+
+```bash
+function transfer(address to, uint256 amount) public virtual returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ //subtract the amount by the royalty amount
+ balanceOf[to] += amount - royaltyAmount;
+ //add to the royaltyAddress wallet the royaltyAmount
+ balanceOf[royaltyAddress] += royaltyAmount;
+ }
+
+ emit Transfer(msg.sender, to, amount);
+
+ return true;
+ }
+```
+Add an additional emit Transfer where we send the royaltyAddress the royaltyAmount. Additionally, subtract the original emit Transfer amount by the royaltyAmount:
+
+```bash
+function transfer(address to, uint256 amount) public virtual override returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+
+ unchecked {
+ //subtract the amount by the royalty amount
+ balanceOf[to] += amount - royaltyAmount;
+ //add to the royaltyAddress wallet the royaltyAmount
+ balanceOf[royaltyAddress] += royaltyAmount;
+ }
+ //transfer to the royalty address
+ emit Transfer(msg.sender, royaltyAddress, royaltyAmount);
+ //transfer to the original address
+ emit Transfer(msg.sender, to, amount - royaltyAmount);
+
+ return true;
+ }
+```
+6. Our contract is now finished! In total it should look like this:
+
+```bash
+// SPDX-License-Identifier: UNLICENSED
+pragma solidity ^0.8.14;
+
+import { ERC20 } from "solmate/tokens/ERC20.sol";
+
+contract RoyaltyToken is ERC20 {
+
+ address public royaltyAddress;
+ uint256 public royaltyFeePercentage;
+
+ constructor(
+ string memory _name,
+ string memory _symbol,
+ uint8 _decimals,
+ uint256 _royaltyFeePercentage,
+ uint256 _initialSupply
+ ) ERC20(_name, _symbol, _decimals) {
+ royaltyAddress = msg.sender;
+ royaltyFeePercentage = _royaltyFeePercentage;
+ _mint(msg.sender, _initialSupply);
+ }
+
+ function transferWithRoyalty (address to, uint256 amount) public returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+
+ transfer(royaltyAddress, royaltyAmount);
+
+ transfer(to, amount - royaltyAmount);
+
+ return true;
+ }
+
+ function transfer(address to, uint256 amount) public virtual override returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ balanceOf[to] += amount - royaltyAmount;
+ balanceOf[royaltyAddress] += royaltyAmount;
+ }
+ //transfer to the royalty address
+ emit Transfer(msg.sender, royaltyAddress, royaltyAmount);
+ //transfer to the original address
+ emit Transfer(msg.sender, to, amount - royaltyAmount);
+
+ return true;
+ }
+}
+```
+
+# Testing Our Smart Contract
+Thanks to Foundry, we can test our new `RoyaltyToken.sol` contract in Solidity!
+
+Set up your test contract
+
+1. In your IDE, head to `test/Counter.t.sol` and rename the file to `RoyaltyToken.t.sol`.
+
+2. Delete everything in the original body of `RoyaltyToken.t.sol`.
+
+3. Add our solidity version to the top: `pragma solidity ^0.8.14;`.
+
+4. Import the RoyaltyToken from `royaltyToken.sol`. Add `import {RoyaltyToken} from "src//RoyaltyToken.sol";` to the top of your contract.
+
+5. Import forge testing tools: `import "forge-std/Test.sol";`.
+
+6. Make a new contract called `RoyaltyTokenTest` and set it to a `Test`. Our contract should look like this.
+
+```bash
+pragma solidity ^0.8.14;
+
+import {RoyaltyToken} from "src//RoyaltyToken.sol";
+
+import "forge-std/Test.sol";
+
+contract RoyaltyTokenTest is Test {}
+```
+### Create your test contract
+1. Create your `RoyaltyToken`, `RoyaltyFeePercentage`, and `InitialSupply` arguments. For this test, we will be using `2%` for the fee and `10,000` initial tokens:
+
+```bash
+pragma solidity ^0.8.14;
+
+import {RoyaltyToken} from "src//RoyaltyToken.sol";
+
+import "forge-std/Test.sol";
+
+contract RoyaltyTokenTest is Test {
+ RoyaltyToken public token;
+ uint256 public royaltyFeePercentage = 2;
+ uint256 public initialSupply = 10 ** 4;
+}
+```
+2. Create a `setUp()` function that constructs our `RoyaltyToken`.
+```bash
+pragma solidity ^0.8.14;
+
+import {RoyaltyToken} from "src//RoyaltyToken.sol";
+
+import "forge-std/Test.sol";
+
+contract RoyaltyTokenTest is Test {
+ RoyaltyToken public token;
+ uint256 public royaltyFeePercentage = 2;
+ uint256 public initialSupply = 10 ** 4;
+
+ function setUp() public {
+ token = new RoyaltyToken("RoyaltyToken", "ROYT", 18, royaltyFeePercentage, initialSupply);
+ }
+
+}
+```
+3. Create a `testTransfer()` function that makes two dummy addresses and transfers funds between them. We will transfer 1,000 of the 10,000 tokens we created to an address. We're then going to check whether the address received 980 of those 1,000 tokens and whether our original contract address received the other 20. Afterward, we will initiate a transfer of 100 tokens between the newly created address and another wallet. We'll then check whether all 3 of the wallets have the correct amounts.
+```bash
+function testTransfer() public {
+ address alice = address(1);
+ address bob = address(2);
+
+ token.transfer(alice, 1000);
+
+ assertEq(token.balanceOf(alice), 980);
+ assertEq(token.balanceOf(address(this)), 9020);
+
+ hoax(alice);
+ token.transfer(bob, 100);
+
+ assertEq(token.balanceOf(alice), 880);
+ assertEq(token.balanceOf(bob), 98);
+ assertEq(token.balanceOf(address(this)), 9022);
+ }
+```
+4. Our entire contract should look like this:
+```bash
+// SPDX-License-Identifier: UNLICENSED
+pragma solidity ^0.8.14;
+
+import {RoyaltyToken} from "src//RoyaltyToken.sol";
+
+import "forge-std/Test.sol";
+
+contract RoyaltyTokenTest is Test {
+ RoyaltyToken public token;
+ uint256 public royaltyFeePercentage = 2;
+ uint256 public initialSupply = 10 ** 4;
+
+
+ function setUp() public {
+ token = new RoyaltyToken("RoyaltyToken", "ROYT", 18, royaltyFeePercentage, initialSupply);
+ }
+
+ function testTransfer() public {
+ address alice = address(1);
+ address bob = address(2);
+
+ token.transfer(alice, 1000);
+
+ assertEq(token.balanceOf(alice), 980);
+ assertEq(token.balanceOf(address(this)), 9020);
+
+ hoax(alice);
+ token.transfer(bob, 100);
+
+ assertEq(token.balanceOf(alice), 880);
+ assertEq(token.balanceOf(bob), 98);
+ assertEq(token.balanceOf(address(this)), 9022);
+ }
+}
+```
+5. Now, let’s compile our contract. Open up that terminal window we used earlier and type the command `forge build` .
+```bash
+forge build
+```
+
+`Compiling...
+[⠰] Compiling 19 files with 0.8.14
+[⠒] Solc 0.8.14 finished in 2.00s
+Compiler run successful`
+
+Our smart contract is finished and is correctly compiling! Now let's test our smart contract to make sure it's actually doing what we want it to do.
+
+6. Open up terminal and run `forge test`. This runs our tests and helps us understand whether or not they passed.
+```bash
+forge test
+```
+
+`Compiling...
+No files changed, compilation skipped
+
+Running 1 test for test/RoyaltyToken.t.sol:RoyaltyTokenTest
+[PASS] testTransfer() (gas: 78242)
+Test result: ok. 1 passed; 0 failed; finished in 1.45ms`
+
+If all goes well, you've just successfully made a smart contract in foundry, overrode the original transfer function, and ran some successful tests! Now, it's time to deploy the contract.
+
+# Deploying Our Smart Contract To The Blockchain
+It's time for us to deploy our smart contract to the blockchain.
+
+1. Open up terminal and run `cast wallet new` - Create a new random keypair.
+```bash
+cast wallet new
+```
+
+`Successfully created new keypair.
+Address: 0x80B75825D86a005453A08cD1a6Bd44C24d73A41d
+Private Key: 0x4159ae5d34bb48367f9773c48de0e0effb2082681a69cd95f4e613246720af24`
+
+2. Now Copy the address and go to XDC faucet for [test XDC](https://faucet.apothem.network/), And replace `0x` by xdc.Click on request 1000 XDC.
+
+
+
+We've got everything we need to deploy our contract to the blockchain now.
+
+### Deploying Our Contract
+Head back to your terminal window to complete deployment.
+
+1. Open up the terminal and type the following command, replacing [PASTE YOUR PRIVATE KEY HERE]
+```bash
+forge create --rpc-url https://erpc.apothem.network --private-key [PASTE YOUR PRIVATE KEY HERE] src/RoyaltyToken.sol:RoyaltyToken --constructor-args "RoyaltyToken" "ROYT" 18 2 10000000000000000000000 --legacy
+```
+
+`Compiling...
+No files changed, compilation skipped
+Deployer: 0x80B75825D86a005453A08cD1a6Bd44C24d73A41d
+Deployed to: 0x27f4D21150640df0856fF6CB5d57eB4447CC59AD
+Transaction hash: 0x89f0edbf4755e93b8d25857e5a0fa0f7cae414cefac42e6ec9cb02930a932d41`
+
+
+We can now see that our contract is deployed to the blockchain. If I copy the address in Deployed to, we can view the contract on [explorer](https://apothem.blocksscan.io/address/xdc27f4D21150640df0856fF6CB5d57eB4447CC59AD#transactions).
+
+
+
+# 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 [Apothem Block Explorer](https://apothem.blocksscan.io/address/xdc27f4D21150640df0856fF6CB5d57eB4447CC59AD#transactions).
+1. Flatten our smart contract, Open up the terminal and type the following command
+```bash
+forge flatten --output src/Contract.flattened.sol src/RoyaltyToken.sol
+```
+`Flattened file written at src/Contract.flattened.sol`
+Now open the `Contract.flattened.sol` file and copy all source code, go to the [block explorer](https://apothem.blocksscan.io/address/xdc27f4D21150640df0856fF6CB5d57eB4447CC59AD#transactions) and click on Verify and Publish.
+
+
+
+
+
+
+
+
+If everything is correctly filled out, your contract page on the block explorer should display a new tab called Contract.
+
+---
+For more information about XDC Network, Please Visit [XDC Network Documention](https://docs.xdc.org/).
+For more information about Foundry, Please Visit [Foundry Book](https://book.getfoundry.sh/).
+XDC Network [Disocrd](https://discord.gg/RBRx2HvbMr).
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/how-to/XRC20/Foundry/remappings.txt b/how-to/XRC20/Foundry/remappings.txt
new file mode 100644
index 00000000..5c732d87
--- /dev/null
+++ b/how-to/XRC20/Foundry/remappings.txt
@@ -0,0 +1,2 @@
+solmate/=lib/solmate/src/
+forge-std=lib/forge-std/src/
\ No newline at end of file
From 539ffcb40ad05af15d0d893bccfa35b8404b5c9c Mon Sep 17 00:00:00 2001
From: mogithehurt <114102465+mogithehurt@users.noreply.github.com>
Date: Mon, 21 Nov 2022 23:47:19 +0530
Subject: [PATCH 004/115] Delete Readme.md
---
how-to/XRC20/Foundry/Readme.md | 1 -
1 file changed, 1 deletion(-)
delete mode 100644 how-to/XRC20/Foundry/Readme.md
diff --git a/how-to/XRC20/Foundry/Readme.md b/how-to/XRC20/Foundry/Readme.md
deleted file mode 100644
index 8b137891..00000000
--- a/how-to/XRC20/Foundry/Readme.md
+++ /dev/null
@@ -1 +0,0 @@
-
From 4a874120531b94ed5b2ea6303454253eccc2f25c Mon Sep 17 00:00:00 2001
From: mogithehurt <114102465+mogithehurt@users.noreply.github.com>
Date: Mon, 21 Nov 2022 23:47:52 +0530
Subject: [PATCH 005/115] Add files via upload
---
how-to/XRC20/Foundry/Contract.flattened.sol | 253 ++++++++++++++++++++
how-to/XRC20/Foundry/RoyaltyToken.sol | 51 ++++
how-to/XRC20/Foundry/RoyaltyToken.t.sol | 34 +++
3 files changed, 338 insertions(+)
create mode 100644 how-to/XRC20/Foundry/Contract.flattened.sol
create mode 100644 how-to/XRC20/Foundry/RoyaltyToken.sol
create mode 100644 how-to/XRC20/Foundry/RoyaltyToken.t.sol
diff --git a/how-to/XRC20/Foundry/Contract.flattened.sol b/how-to/XRC20/Foundry/Contract.flattened.sol
new file mode 100644
index 00000000..d7caf689
--- /dev/null
+++ b/how-to/XRC20/Foundry/Contract.flattened.sol
@@ -0,0 +1,253 @@
+// SPDX-License-Identifier: UNLICENSED
+pragma solidity ^0.8.14;
+
+/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
+/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
+/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
+/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
+abstract contract ERC20 {
+ /*//////////////////////////////////////////////////////////////
+ EVENTS
+ //////////////////////////////////////////////////////////////*/
+
+ event Transfer(address indexed from, address indexed to, uint256 amount);
+
+ event Approval(address indexed owner, address indexed spender, uint256 amount);
+
+ /*//////////////////////////////////////////////////////////////
+ METADATA STORAGE
+ //////////////////////////////////////////////////////////////*/
+
+ string public name;
+
+ string public symbol;
+
+ uint8 public immutable decimals;
+
+ /*//////////////////////////////////////////////////////////////
+ ERC20 STORAGE
+ //////////////////////////////////////////////////////////////*/
+
+ uint256 public totalSupply;
+
+ mapping(address => uint256) public balanceOf;
+
+ mapping(address => mapping(address => uint256)) public allowance;
+
+ /*//////////////////////////////////////////////////////////////
+ EIP-2612 STORAGE
+ //////////////////////////////////////////////////////////////*/
+
+ uint256 internal immutable INITIAL_CHAIN_ID;
+
+ bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
+
+ mapping(address => uint256) public nonces;
+
+ /*//////////////////////////////////////////////////////////////
+ CONSTRUCTOR
+ //////////////////////////////////////////////////////////////*/
+
+ constructor(
+ string memory _name,
+ string memory _symbol,
+ uint8 _decimals
+ ) {
+ name = _name;
+ symbol = _symbol;
+ decimals = _decimals;
+
+ INITIAL_CHAIN_ID = block.chainid;
+ INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
+ }
+
+ /*//////////////////////////////////////////////////////////////
+ ERC20 LOGIC
+ //////////////////////////////////////////////////////////////*/
+
+ function approve(address spender, uint256 amount) public virtual returns (bool) {
+ allowance[msg.sender][spender] = amount;
+
+ emit Approval(msg.sender, spender, amount);
+
+ return true;
+ }
+
+ function transfer(address to, uint256 amount) public virtual returns (bool) {
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ balanceOf[to] += amount;
+ }
+
+ emit Transfer(msg.sender, to, amount);
+
+ return true;
+ }
+
+ function transferFrom(
+ address from,
+ address to,
+ uint256 amount
+ ) public virtual returns (bool) {
+ uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.
+
+ if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;
+
+ balanceOf[from] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ balanceOf[to] += amount;
+ }
+
+ emit Transfer(from, to, amount);
+
+ return true;
+ }
+
+ /*//////////////////////////////////////////////////////////////
+ EIP-2612 LOGIC
+ //////////////////////////////////////////////////////////////*/
+
+ function permit(
+ address owner,
+ address spender,
+ uint256 value,
+ uint256 deadline,
+ uint8 v,
+ bytes32 r,
+ bytes32 s
+ ) public virtual {
+ require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");
+
+ // Unchecked because the only math done is incrementing
+ // the owner's nonce which cannot realistically overflow.
+ unchecked {
+ address recoveredAddress = ecrecover(
+ keccak256(
+ abi.encodePacked(
+ "\x19\x01",
+ DOMAIN_SEPARATOR(),
+ keccak256(
+ abi.encode(
+ keccak256(
+ "Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
+ ),
+ owner,
+ spender,
+ value,
+ nonces[owner]++,
+ deadline
+ )
+ )
+ )
+ ),
+ v,
+ r,
+ s
+ );
+
+ require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");
+
+ allowance[recoveredAddress][spender] = value;
+ }
+
+ emit Approval(owner, spender, value);
+ }
+
+ function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
+ return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
+ }
+
+ function computeDomainSeparator() internal view virtual returns (bytes32) {
+ return
+ keccak256(
+ abi.encode(
+ keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
+ keccak256(bytes(name)),
+ keccak256("1"),
+ block.chainid,
+ address(this)
+ )
+ );
+ }
+
+ /*//////////////////////////////////////////////////////////////
+ INTERNAL MINT/BURN LOGIC
+ //////////////////////////////////////////////////////////////*/
+
+ function _mint(address to, uint256 amount) internal virtual {
+ totalSupply += amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ balanceOf[to] += amount;
+ }
+
+ emit Transfer(address(0), to, amount);
+ }
+
+ function _burn(address from, uint256 amount) internal virtual {
+ balanceOf[from] -= amount;
+
+ // Cannot underflow because a user's balance
+ // will never be larger than the total supply.
+ unchecked {
+ totalSupply -= amount;
+ }
+
+ emit Transfer(from, address(0), amount);
+ }
+}
+
+contract RoyaltyToken is ERC20 {
+
+ address public royaltyAddress;
+ uint256 public royaltyFeePercentage;
+
+ constructor(
+ string memory _name,
+ string memory _symbol,
+ uint8 _decimals,
+ uint256 _royaltyFeePercentage,
+ uint256 _initialSupply
+ ) ERC20(_name, _symbol, _decimals) {
+ royaltyAddress = msg.sender;
+ royaltyFeePercentage = _royaltyFeePercentage;
+ _mint(msg.sender, _initialSupply);
+ }
+
+ function transferWithRoyalty (address to, uint256 amount) public returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+
+ transfer(royaltyAddress, royaltyAmount);
+
+ transfer(to, amount - royaltyAmount);
+
+ return true;
+ }
+
+ function transfer(address to, uint256 amount) public virtual override returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ balanceOf[to] += amount - royaltyAmount;
+ balanceOf[royaltyAddress] += royaltyAmount;
+ }
+ //transfer to the royalty address
+ emit Transfer(msg.sender, royaltyAddress, royaltyAmount);
+ //transfer to the original address
+ emit Transfer(msg.sender, to, amount - royaltyAmount);
+
+ return true;
+ }
+}
diff --git a/how-to/XRC20/Foundry/RoyaltyToken.sol b/how-to/XRC20/Foundry/RoyaltyToken.sol
new file mode 100644
index 00000000..2528c8a6
--- /dev/null
+++ b/how-to/XRC20/Foundry/RoyaltyToken.sol
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: UNLICENSED
+pragma solidity ^0.8.14;
+
+import { ERC20 } from "solmate/tokens/ERC20.sol";
+
+contract RoyaltyToken is ERC20 {
+
+ address public royaltyAddress;
+ uint256 public royaltyFeePercentage;
+
+ constructor(
+ string memory _name,
+ string memory _symbol,
+ uint8 _decimals,
+ uint256 _royaltyFeePercentage,
+ uint256 _initialSupply
+ ) ERC20(_name, _symbol, _decimals) {
+ royaltyAddress = msg.sender;
+ royaltyFeePercentage = _royaltyFeePercentage;
+ _mint(msg.sender, _initialSupply);
+ }
+
+ function transferWithRoyalty (address to, uint256 amount) public returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+
+ transfer(royaltyAddress, royaltyAmount);
+
+ transfer(to, amount - royaltyAmount);
+
+ return true;
+ }
+
+ function transfer(address to, uint256 amount) public virtual override returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ balanceOf[to] += amount - royaltyAmount;
+ balanceOf[royaltyAddress] += royaltyAmount;
+ }
+ //transfer to the royalty address
+ emit Transfer(msg.sender, royaltyAddress, royaltyAmount);
+ //transfer to the original address
+ emit Transfer(msg.sender, to, amount - royaltyAmount);
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/how-to/XRC20/Foundry/RoyaltyToken.t.sol b/how-to/XRC20/Foundry/RoyaltyToken.t.sol
new file mode 100644
index 00000000..8e602481
--- /dev/null
+++ b/how-to/XRC20/Foundry/RoyaltyToken.t.sol
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: UNLICENSED
+pragma solidity ^0.8.14;
+
+import {RoyaltyToken} from "src//RoyaltyToken.sol";
+
+import "forge-std/Test.sol";
+
+contract RoyaltyTokenTest is Test {
+ RoyaltyToken public token;
+ uint256 public royaltyFeePercentage = 2;
+ uint256 public initialSupply = 10 ** 4;
+
+
+ function setUp() public {
+ token = new RoyaltyToken("RoyaltyToken", "ROYT", 18, royaltyFeePercentage, initialSupply);
+ }
+
+ function testTransfer() public {
+ address alice = address(1);
+ address bob = address(2);
+
+ token.transfer(alice, 1000);
+
+ assertEq(token.balanceOf(alice), 980);
+ assertEq(token.balanceOf(address(this)), 9020);
+
+ hoax(alice);
+ token.transfer(bob, 100);
+
+ assertEq(token.balanceOf(alice), 880);
+ assertEq(token.balanceOf(bob), 98);
+ assertEq(token.balanceOf(address(this)), 9022);
+ }
+}
\ No newline at end of file
From 0a11493100021995b8e2dba56e597df58c805e4d Mon Sep 17 00:00:00 2001
From: Jon McBee
Date: Tue, 22 Nov 2022 13:54:37 +0000
Subject: [PATCH 006/115] GitBook: [#136] Stubbing out how-to xrc20 with
Foundry
---
SUMMARY.md | 1 +
.../how-to-create-an-xrc20-token-using-foundry.md | 3 +++
2 files changed, 4 insertions(+)
create mode 100644 learn/how-to-articles/how-to-create-an-xrc20-token-using-foundry.md
diff --git a/SUMMARY.md b/SUMMARY.md
index d8d22ef8..9e9f7c76 100644
--- a/SUMMARY.md
+++ b/SUMMARY.md
@@ -102,6 +102,7 @@
* [How To Use Truffle and Ganache to Create DeFi App](learn/how-to-articles/how-to-use-truffle-and-ganache-to-create-defi-app.md)
* [How to Migrate a dApp from Ethereum to the XDC Network Using Truffle](learn/how-to-articles/how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md)
* [How to Migrate from Solana to the XDC Network using Solang](learn/how-to-articles/how-to-migrate-from-solana-to-the-xdc-network-using-solang.md)
+ * [How to Create an XRC20 Token Using Foundry](learn/how-to-articles/how-to-create-an-xrc20-token-using-foundry.md)
* [Community Support](learn/community-support.md)
* [How to Report an Issue](learn/community-support/how-to-report-an-issue.md)
* [Contributing and Feedback Guide](gitbook.md)
diff --git a/learn/how-to-articles/how-to-create-an-xrc20-token-using-foundry.md b/learn/how-to-articles/how-to-create-an-xrc20-token-using-foundry.md
new file mode 100644
index 00000000..c4f7e4ab
--- /dev/null
+++ b/learn/how-to-articles/how-to-create-an-xrc20-token-using-foundry.md
@@ -0,0 +1,3 @@
+# How to Create an XRC20 Token Using Foundry
+
+Hello World
From 5599f6a94594c6dff4ce536284e14a3342be88c4 Mon Sep 17 00:00:00 2001
From: Jon McBee
Date: Tue, 22 Nov 2022 08:58:49 -0500
Subject: [PATCH 007/115] Promoting XRC20 with Foundry
Renamed the doc
Promoted the content
---
...-to-create-an-xrc20-token-using-foundry.md | 3 -
...and-deploy-an-xrc20-token-using-foundry.md | 600 ++++++++++++++++++
2 files changed, 600 insertions(+), 3 deletions(-)
delete mode 100644 learn/how-to-articles/how-to-create-an-xrc20-token-using-foundry.md
create mode 100644 learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-foundry.md
diff --git a/learn/how-to-articles/how-to-create-an-xrc20-token-using-foundry.md b/learn/how-to-articles/how-to-create-an-xrc20-token-using-foundry.md
deleted file mode 100644
index c4f7e4ab..00000000
--- a/learn/how-to-articles/how-to-create-an-xrc20-token-using-foundry.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# How to Create an XRC20 Token Using Foundry
-
-Hello World
diff --git a/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-foundry.md b/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-foundry.md
new file mode 100644
index 00000000..ef24a029
--- /dev/null
+++ b/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-foundry.md
@@ -0,0 +1,600 @@
+# How to make a XRC-20 Royalty Token with Foundry.
+This tutorial’s purpose is to create an XRC-20 token with foundry that will return a royalty amount (of that XRC-20 token) to the original creator of the contract.
+
+# 🧭 Table of contents
+
+- [How to make a XRC-20 Royalty Token with Foundry.](#how-to-make-a-xrc-20-royalty-token-with-foundry)
+- [🧭 Table of contents](#-table-of-contents)
+- [📰 Overview](#-overview)
+ - [What you will learn](#what-you-will-learn)
+ - [What you will do](#what-you-will-do)
+- [The Tools We're Using](#the-tools-were-using)
+- [Set up Foundry](#set-up-foundry)
+ - [Installing Foundry For MacOS / Linux:](#installing-foundry-for-macos--linux)
+ - [Installing Foundry For Windows:](#installing-foundry-for-windows)
+- [environment SetUp](#environment-setup)
+- [Smart Contract Development](#smart-contract-development)
+- [Testing Our Smart Contract](#testing-our-smart-contract)
+ - [Create your test contract](#create-your-test-contract)
+- [Deploying Our Smart Contract To The Blockchain](#deploying-our-smart-contract-to-the-blockchain)
+ - [Deploying Our Contract](#deploying-our-contract)
+- [Veryfing Contracts on the Block Explorer](#veryfing-contracts-on-the-block-explorer)
+
+
+# 📰 Overview
+
+
+
+
+[Foundry](https://book.getfoundry.sh/) is a smart contract development toolchain.
+
+Foundry manages your dependencies, compiles your project, runs tests, deploys, and lets you interact with the chain from the command-line and via Solidity scripts.
+
+### What you will learn
+In this tutorial, you will learn how to set up Foundry and use it to build, test and deploy a XRC20 Royalty Token on both the XDC Network mainnet and XDC Apothem testnet.
+
+### What you will do
+- Install and setup Foundry
+- Create an XRC20 Royalty token
+- Compile the Contract
+- Deploy the Contract
+- Interact with the XRC20 Royalty token
+- Check the deployment status on [XDC Mainnet](https://explorer.xinfin.network/) and [XDC Testnet](https://apothem.blocksscan.io/)
+
+# The Tools We're Using
+- [Foundry](https://book.getfoundry.sh/) : a fast Solidity development toolkit that enables developers to write their tests in Solidity.
+- [Solmate](https://github.com/Rari-Capital/solmate) : a library that contains gas-optimized contracts such as ERC20, ERC721, and more.
+- [Visual Studio Code](https://code.visualstudio.com/) : a source-code editor made by Microsoft with the Electron Framework, for Windows, Linux and macOS.
+- [XDC Testnet explorer](https://explorer.xinfin.network/)
+- [Testnet XDC Faucet](https://faucet.apothem.network/) : a faucet that gives 1000 XDC for test.
+- [XDCPay](https://chrome.google.com/webstore/detail/xdcpay/bocpokimicclpaiekenaeelehdjllofo) : is an extension for accessing XDC's XDPoS enabled distributed applications, or "Dapps" in your browser.
+
+# Set up Foundry
+Before we can start writing some code, we need to set up our environment. We're going to be writing our contracts and testing them in Foundry.
+
+### Installing Foundry For MacOS / Linux:
+
+Open-up terminal and type in the command:
+
+```bash
+curl -L https://foundry.paradigm.xyz | bash
+```
+
+Afterward type:
+```bash
+foundryup
+```
+Foundry should now be installed and ready to go!
+
+### Installing Foundry For Windows:
+
+If using Windows, you need to install Foundry from the source. First, install [Rust](https://rustup.rs/) with the [official documentation](https://book.getfoundry.sh/getting-started/installation).
+
+Then, open the command prompt and type in the command:
+```bash
+cargo install --git https://github.com/foundry-rs/foundry foundry-cli anvil --bins --locked
+```
+To update from source, run the same command again.
+
+# environment SetUp
+
+Now that we've installed Foundry, it's time to set up our folder where we will write our smart contract. From the same terminal window that you installed Foundry, type the following commands:
+
+1. Make our folder where will we initialize our project. Then navigate into that folder with the following commands:
+```bash
+mkdir XRC20_Royalty && cd XRC20_Royalty
+```
+2. Initialize our Foundry project within our XRC20_Royalty folder:
+```bash
+forge init
+```
+3. Install Solmate into our Foundry project:
+```bash
+forge install rari-capital/solmate
+```
+4. Create a remappings.txt file for the Solmate library we just added:
+```bash
+touch remappings.txt
+```
+5. Open up your project in your IDE. For this tutorial, we’ll be using VSCode with this Solidity plugin:
+```bash
+code .
+```
+Here’s what our IDE looks like.
+
+
+
+
+6. Add these lines to remappings.txt so we can easily call the Solmate library in our contract:
+```bash
+solmate/=lib/solmate/src/
+forge-std=lib/forge-std/src/
+```
+Now that our environment and libraries are set up, we'll move into developing our smart contract!
+
+# Smart Contract Development
+
+We will make a contract that passes tokens to the original contract creator whenever a token is transferred between wallets!
+
+1. In your IDE, navigate to `src/Counter.sol` and rename the file to `RoyaltyToken.sol`.
+
+2. Import the Solmate ERC20 library in `RoyaltyToken.sol` and change the name of the contract. Under `pragma solidity ^0.8.14;`, add the following lines of code:
+```bash
+import { ERC20 } from "solmate/tokens/ERC20.sol";
+
+contract RoyaltyToken is ERC20 {}
+```
+3. Add in our state variables for the royalties. In the contract, add an address `royaltyAddress` variable and uint256 `royaltyFeePercentage` variable:
+```bash
+contract RoyaltyToken is ERC20 {
+ address public royaltyAddress;
+ uint256 public royaltyFeePercentage;
+}
+```
+4. Make a constructor for the token. A constructor is what creates our token from the imported Solmate template.
+
+Add the following variables to the constructor:
+
+1. `string memory _name`
+2. `string memory _token`
+3. `uint8 _decimals`
+4. `uint256 _royaltyFeePercentage`
+5. `uint256 _initialSupply`
+Directly after we’ve added these variables and closed the `()`, add `ERC20(_name, _symbol, _decimals)`.
+
+After that add brackets `{}` and inside the brackets set the following variables:
+
+Set `royaltyAddress` variable as the wallet address of the creator of the contract: `royaltyAddress = msg.sender;`
+The `RoyaltyFeePercentage` as the constructor variable: `royaltyFeePercentage = _royaltyFeePercentage;`
+Mint the tokens to the creator of the contract and pass in the `_initialSupply` variable: `_mint(msg.sender, _initialSupply);`
+Our constructor should now look like the following:
+```bash
+contract RoyaltyToken is ERC20 {
+ address public royaltyAddress;
+ uint256 public royaltyFeePercentage;
+
+ constructor(
+ string memory _name,
+ string memory _symbol,
+ uint8 _decimals,
+ uint256 _royaltyFeePercentage,
+ uint256 _initialSupply
+ ) ERC20(_name, _symbol, _decimals) {
+ royaltyAddress = msg.sender;
+ royaltyFeePercentage = _royaltyFeePercentage;
+ _mint(msg.sender, _initialSupply);
+ }
+}
+```
+5. Next, override the transfer function.
+```bash
+function transfer(address to, uint256 amount) public virtual returns (bool) {
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ balanceOf[to] += amount;
+ }
+
+ emit Transfer(msg.sender, to, amount);
+
+ return true;
+ }
+```
+
+Our contract now looks like this:
+
+```bash
+pragma solidity ^0.8.14;
+
+import { ERC20 } from "solmate/tokens/ERC20.sol";
+
+contract RoyaltyToken is ERC20 {
+ address public royaltyAddress;
+ uint256 public royaltyFeePercentage;
+
+ constructor(
+ string memory _name,
+ string memory _symbol,
+ uint8 _decimals,
+ uint256 _royaltyFeePercentage,
+ uint256 _initialSupply
+ ) ERC20(_name, _symbol, _decimals) {
+ royaltyAddress = msg.sender;
+ royaltyFeePercentage = _royaltyFeePercentage;
+ _mint(msg.sender, _initialSupply);
+ }
+
+ function transfer(address to, uint256 amount) public virtual returns (bool) {
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ balanceOf[to] += amount;
+ }
+
+ emit Transfer(msg.sender, to, amount);
+
+ return true;
+ }
+}
+```
+Add override after virtual in the function declaration:
+
+
+`function transfer(address to, uint256 amount) public virtual override returns (bool) {
+...
+} `
+Inside of the `transfer` function, create a uint256 called `royaltyAmount` and set it equal to the amount in the function parameters multiplied by the `royaltyFeePercentage` divided by `100`. This calculates the royalty amount that we will be sending to our `royaltyAddress`.
+```bash
+uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+```
+```bash
+function transfer(address to, uint256 amount) public virtual returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ balanceOf[to] += amount;
+ }
+
+ emit Transfer(msg.sender, to, amount);
+
+ return true;
+ }
+```
+In the `unchecked {}` for the `balanceOf[to]`, subtract the amount by the `royaltyAmount` and add an additional `balanceOf[royaltyAddress]` where we add the `royaltyAmount`:
+
+```bash
+function transfer(address to, uint256 amount) public virtual returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ //subtract the amount by the royalty amount
+ balanceOf[to] += amount - royaltyAmount;
+ //add to the royaltyAddress wallet the royaltyAmount
+ balanceOf[royaltyAddress] += royaltyAmount;
+ }
+
+ emit Transfer(msg.sender, to, amount);
+
+ return true;
+ }
+```
+Add an additional emit Transfer where we send the royaltyAddress the royaltyAmount. Additionally, subtract the original emit Transfer amount by the royaltyAmount:
+
+```bash
+function transfer(address to, uint256 amount) public virtual override returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+
+ unchecked {
+ //subtract the amount by the royalty amount
+ balanceOf[to] += amount - royaltyAmount;
+ //add to the royaltyAddress wallet the royaltyAmount
+ balanceOf[royaltyAddress] += royaltyAmount;
+ }
+ //transfer to the royalty address
+ emit Transfer(msg.sender, royaltyAddress, royaltyAmount);
+ //transfer to the original address
+ emit Transfer(msg.sender, to, amount - royaltyAmount);
+
+ return true;
+ }
+```
+6. Our contract is now finished! In total it should look like this:
+
+```bash
+// SPDX-License-Identifier: UNLICENSED
+pragma solidity ^0.8.14;
+
+import { ERC20 } from "solmate/tokens/ERC20.sol";
+
+contract RoyaltyToken is ERC20 {
+
+ address public royaltyAddress;
+ uint256 public royaltyFeePercentage;
+
+ constructor(
+ string memory _name,
+ string memory _symbol,
+ uint8 _decimals,
+ uint256 _royaltyFeePercentage,
+ uint256 _initialSupply
+ ) ERC20(_name, _symbol, _decimals) {
+ royaltyAddress = msg.sender;
+ royaltyFeePercentage = _royaltyFeePercentage;
+ _mint(msg.sender, _initialSupply);
+ }
+
+ function transferWithRoyalty (address to, uint256 amount) public returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+
+ transfer(royaltyAddress, royaltyAmount);
+
+ transfer(to, amount - royaltyAmount);
+
+ return true;
+ }
+
+ function transfer(address to, uint256 amount) public virtual override returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ balanceOf[to] += amount - royaltyAmount;
+ balanceOf[royaltyAddress] += royaltyAmount;
+ }
+ //transfer to the royalty address
+ emit Transfer(msg.sender, royaltyAddress, royaltyAmount);
+ //transfer to the original address
+ emit Transfer(msg.sender, to, amount - royaltyAmount);
+
+ return true;
+ }
+}
+```
+
+# Testing Our Smart Contract
+Thanks to Foundry, we can test our new `RoyaltyToken.sol` contract in Solidity!
+
+Set up your test contract
+
+1. In your IDE, head to `test/Counter.t.sol` and rename the file to `RoyaltyToken.t.sol`.
+
+2. Delete everything in the original body of `RoyaltyToken.t.sol`.
+
+3. Add our solidity version to the top: `pragma solidity ^0.8.14;`.
+
+4. Import the RoyaltyToken from `royaltyToken.sol`. Add `import {RoyaltyToken} from "src//RoyaltyToken.sol";` to the top of your contract.
+
+5. Import forge testing tools: `import "forge-std/Test.sol";`.
+
+6. Make a new contract called `RoyaltyTokenTest` and set it to a `Test`. Our contract should look like this.
+
+```bash
+pragma solidity ^0.8.14;
+
+import {RoyaltyToken} from "src//RoyaltyToken.sol";
+
+import "forge-std/Test.sol";
+
+contract RoyaltyTokenTest is Test {}
+```
+### Create your test contract
+1. Create your `RoyaltyToken`, `RoyaltyFeePercentage`, and `InitialSupply` arguments. For this test, we will be using `2%` for the fee and `10,000` initial tokens:
+
+```bash
+pragma solidity ^0.8.14;
+
+import {RoyaltyToken} from "src//RoyaltyToken.sol";
+
+import "forge-std/Test.sol";
+
+contract RoyaltyTokenTest is Test {
+ RoyaltyToken public token;
+ uint256 public royaltyFeePercentage = 2;
+ uint256 public initialSupply = 10 ** 4;
+}
+```
+2. Create a `setUp()` function that constructs our `RoyaltyToken`.
+```bash
+pragma solidity ^0.8.14;
+
+import {RoyaltyToken} from "src//RoyaltyToken.sol";
+
+import "forge-std/Test.sol";
+
+contract RoyaltyTokenTest is Test {
+ RoyaltyToken public token;
+ uint256 public royaltyFeePercentage = 2;
+ uint256 public initialSupply = 10 ** 4;
+
+ function setUp() public {
+ token = new RoyaltyToken("RoyaltyToken", "ROYT", 18, royaltyFeePercentage, initialSupply);
+ }
+
+}
+```
+3. Create a `testTransfer()` function that makes two dummy addresses and transfers funds between them. We will transfer 1,000 of the 10,000 tokens we created to an address. We're then going to check whether the address received 980 of those 1,000 tokens and whether our original contract address received the other 20. Afterward, we will initiate a transfer of 100 tokens between the newly created address and another wallet. We'll then check whether all 3 of the wallets have the correct amounts.
+```bash
+function testTransfer() public {
+ address alice = address(1);
+ address bob = address(2);
+
+ token.transfer(alice, 1000);
+
+ assertEq(token.balanceOf(alice), 980);
+ assertEq(token.balanceOf(address(this)), 9020);
+
+ hoax(alice);
+ token.transfer(bob, 100);
+
+ assertEq(token.balanceOf(alice), 880);
+ assertEq(token.balanceOf(bob), 98);
+ assertEq(token.balanceOf(address(this)), 9022);
+ }
+```
+4. Our entire contract should look like this:
+```bash
+// SPDX-License-Identifier: UNLICENSED
+pragma solidity ^0.8.14;
+
+import {RoyaltyToken} from "src//RoyaltyToken.sol";
+
+import "forge-std/Test.sol";
+
+contract RoyaltyTokenTest is Test {
+ RoyaltyToken public token;
+ uint256 public royaltyFeePercentage = 2;
+ uint256 public initialSupply = 10 ** 4;
+
+
+ function setUp() public {
+ token = new RoyaltyToken("RoyaltyToken", "ROYT", 18, royaltyFeePercentage, initialSupply);
+ }
+
+ function testTransfer() public {
+ address alice = address(1);
+ address bob = address(2);
+
+ token.transfer(alice, 1000);
+
+ assertEq(token.balanceOf(alice), 980);
+ assertEq(token.balanceOf(address(this)), 9020);
+
+ hoax(alice);
+ token.transfer(bob, 100);
+
+ assertEq(token.balanceOf(alice), 880);
+ assertEq(token.balanceOf(bob), 98);
+ assertEq(token.balanceOf(address(this)), 9022);
+ }
+}
+```
+5. Now, let’s compile our contract. Open up that terminal window we used earlier and type the command `forge build` .
+```bash
+forge build
+```
+
+`Compiling...
+[⠰] Compiling 19 files with 0.8.14
+[⠒] Solc 0.8.14 finished in 2.00s
+Compiler run successful`
+
+Our smart contract is finished and is correctly compiling! Now let's test our smart contract to make sure it's actually doing what we want it to do.
+
+6. Open up terminal and run `forge test`. This runs our tests and helps us understand whether or not they passed.
+```bash
+forge test
+```
+
+`Compiling...
+No files changed, compilation skipped
+
+Running 1 test for test/RoyaltyToken.t.sol:RoyaltyTokenTest
+[PASS] testTransfer() (gas: 78242)
+Test result: ok. 1 passed; 0 failed; finished in 1.45ms`
+
+If all goes well, you've just successfully made a smart contract in foundry, overrode the original transfer function, and ran some successful tests! Now, it's time to deploy the contract.
+
+# Deploying Our Smart Contract To The Blockchain
+It's time for us to deploy our smart contract to the blockchain.
+
+1. Open up terminal and run `cast wallet new` - Create a new random keypair.
+```bash
+cast wallet new
+```
+
+`Successfully created new keypair.
+Address: 0x80B75825D86a005453A08cD1a6Bd44C24d73A41d
+Private Key: 0x4159ae5d34bb48367f9773c48de0e0effb2082681a69cd95f4e613246720af24`
+
+2. Now Copy the address and go to XDC faucet for [test XDC](https://faucet.apothem.network/), And replace `0x` by xdc.Click on request 1000 XDC.
+
+
+
+We've got everything we need to deploy our contract to the blockchain now.
+
+### Deploying Our Contract
+Head back to your terminal window to complete deployment.
+
+1. Open up the terminal and type the following command, replacing [PASTE YOUR PRIVATE KEY HERE]
+```bash
+forge create --rpc-url https://erpc.apothem.network --private-key [PASTE YOUR PRIVATE KEY HERE] src/RoyaltyToken.sol:RoyaltyToken --constructor-args "RoyaltyToken" "ROYT" 18 2 10000000000000000000000 --legacy
+```
+
+`Compiling...
+No files changed, compilation skipped
+Deployer: 0x80B75825D86a005453A08cD1a6Bd44C24d73A41d
+Deployed to: 0x27f4D21150640df0856fF6CB5d57eB4447CC59AD
+Transaction hash: 0x89f0edbf4755e93b8d25857e5a0fa0f7cae414cefac42e6ec9cb02930a932d41`
+
+
+We can now see that our contract is deployed to the blockchain. If I copy the address in Deployed to, we can view the contract on [explorer](https://apothem.blocksscan.io/address/xdc27f4D21150640df0856fF6CB5d57eB4447CC59AD#transactions).
+
+
+
+# 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 [Apothem Block Explorer](https://apothem.blocksscan.io/address/xdc27f4D21150640df0856fF6CB5d57eB4447CC59AD#transactions).
+1. Flatten our smart contract, Open up the terminal and type the following command
+```bash
+forge flatten --output src/Contract.flattened.sol src/RoyaltyToken.sol
+```
+`Flattened file written at src/Contract.flattened.sol`
+Now open the `Contract.flattened.sol` file and copy all source code, go to the [block explorer](https://apothem.blocksscan.io/address/xdc27f4D21150640df0856fF6CB5d57eB4447CC59AD#transactions) and click on Verify and Publish.
+
+
+
+
+
+
+
+
+If everything is correctly filled out, your contract page on the block explorer should display a new tab called Contract.
+
+---
+For more information about XDC Network, Please Visit [XDC Network Documention](https://docs.xdc.community/).
+For more information about Foundry, Please Visit [Foundry Book](https://book.getfoundry.sh/).
+XDC Network [Disocrd](https://discord.gg/RBRx2HvbMr).
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
From 61067201a391c4267614b78cfe784b1185a79e67 Mon Sep 17 00:00:00 2001
From: Jon McBee
Date: Tue, 22 Nov 2022 14:02:19 +0000
Subject: [PATCH 008/115] GitBook: [#137] Updating name
---
SUMMARY.md | 2 +-
goplugin/about.md | 13 +-
...and-deploy-an-xrc20-token-using-foundry.md | 601 +-----------------
3 files changed, 9 insertions(+), 607 deletions(-)
diff --git a/SUMMARY.md b/SUMMARY.md
index 9e9f7c76..cd63579a 100644
--- a/SUMMARY.md
+++ b/SUMMARY.md
@@ -102,7 +102,7 @@
* [How To Use Truffle and Ganache to Create DeFi App](learn/how-to-articles/how-to-use-truffle-and-ganache-to-create-defi-app.md)
* [How to Migrate a dApp from Ethereum to the XDC Network Using Truffle](learn/how-to-articles/how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md)
* [How to Migrate from Solana to the XDC Network using Solang](learn/how-to-articles/how-to-migrate-from-solana-to-the-xdc-network-using-solang.md)
- * [How to Create an XRC20 Token Using Foundry](learn/how-to-articles/how-to-create-an-xrc20-token-using-foundry.md)
+ * [How to Create and Deploy an XRC20 Token Using Foundry](learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-foundry.md)
* [Community Support](learn/community-support.md)
* [How to Report an Issue](learn/community-support/how-to-report-an-issue.md)
* [Contributing and Feedback Guide](gitbook.md)
diff --git a/goplugin/about.md b/goplugin/about.md
index deaab2e1..25afb735 100644
--- a/goplugin/about.md
+++ b/goplugin/about.md
@@ -1,12 +1,11 @@
# About
-
-
-
+\
+
+
+[](https://goplugin.co)
+
+\
Decentralized Oracle Platform, provides cost effective solutions to any smart contract which runs on the XDC Network Eco System.
diff --git a/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-foundry.md b/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-foundry.md
index ef24a029..3d384ff9 100644
--- a/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-foundry.md
+++ b/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-foundry.md
@@ -1,600 +1,3 @@
-# How to make a XRC-20 Royalty Token with Foundry.
-This tutorial’s purpose is to create an XRC-20 token with foundry that will return a royalty amount (of that XRC-20 token) to the original creator of the contract.
-
-# 🧭 Table of contents
-
-- [How to make a XRC-20 Royalty Token with Foundry.](#how-to-make-a-xrc-20-royalty-token-with-foundry)
-- [🧭 Table of contents](#-table-of-contents)
-- [📰 Overview](#-overview)
- - [What you will learn](#what-you-will-learn)
- - [What you will do](#what-you-will-do)
-- [The Tools We're Using](#the-tools-were-using)
-- [Set up Foundry](#set-up-foundry)
- - [Installing Foundry For MacOS / Linux:](#installing-foundry-for-macos--linux)
- - [Installing Foundry For Windows:](#installing-foundry-for-windows)
-- [environment SetUp](#environment-setup)
-- [Smart Contract Development](#smart-contract-development)
-- [Testing Our Smart Contract](#testing-our-smart-contract)
- - [Create your test contract](#create-your-test-contract)
-- [Deploying Our Smart Contract To The Blockchain](#deploying-our-smart-contract-to-the-blockchain)
- - [Deploying Our Contract](#deploying-our-contract)
-- [Veryfing Contracts on the Block Explorer](#veryfing-contracts-on-the-block-explorer)
-
-
-# 📰 Overview
-
-
-
-
-[Foundry](https://book.getfoundry.sh/) is a smart contract development toolchain.
-
-Foundry manages your dependencies, compiles your project, runs tests, deploys, and lets you interact with the chain from the command-line and via Solidity scripts.
-
-### What you will learn
-In this tutorial, you will learn how to set up Foundry and use it to build, test and deploy a XRC20 Royalty Token on both the XDC Network mainnet and XDC Apothem testnet.
-
-### What you will do
-- Install and setup Foundry
-- Create an XRC20 Royalty token
-- Compile the Contract
-- Deploy the Contract
-- Interact with the XRC20 Royalty token
-- Check the deployment status on [XDC Mainnet](https://explorer.xinfin.network/) and [XDC Testnet](https://apothem.blocksscan.io/)
-
-# The Tools We're Using
-- [Foundry](https://book.getfoundry.sh/) : a fast Solidity development toolkit that enables developers to write their tests in Solidity.
-- [Solmate](https://github.com/Rari-Capital/solmate) : a library that contains gas-optimized contracts such as ERC20, ERC721, and more.
-- [Visual Studio Code](https://code.visualstudio.com/) : a source-code editor made by Microsoft with the Electron Framework, for Windows, Linux and macOS.
-- [XDC Testnet explorer](https://explorer.xinfin.network/)
-- [Testnet XDC Faucet](https://faucet.apothem.network/) : a faucet that gives 1000 XDC for test.
-- [XDCPay](https://chrome.google.com/webstore/detail/xdcpay/bocpokimicclpaiekenaeelehdjllofo) : is an extension for accessing XDC's XDPoS enabled distributed applications, or "Dapps" in your browser.
-
-# Set up Foundry
-Before we can start writing some code, we need to set up our environment. We're going to be writing our contracts and testing them in Foundry.
-
-### Installing Foundry For MacOS / Linux:
-
-Open-up terminal and type in the command:
-
-```bash
-curl -L https://foundry.paradigm.xyz | bash
-```
-
-Afterward type:
-```bash
-foundryup
-```
-Foundry should now be installed and ready to go!
-
-### Installing Foundry For Windows:
-
-If using Windows, you need to install Foundry from the source. First, install [Rust](https://rustup.rs/) with the [official documentation](https://book.getfoundry.sh/getting-started/installation).
-
-Then, open the command prompt and type in the command:
-```bash
-cargo install --git https://github.com/foundry-rs/foundry foundry-cli anvil --bins --locked
-```
-To update from source, run the same command again.
-
-# environment SetUp
-
-Now that we've installed Foundry, it's time to set up our folder where we will write our smart contract. From the same terminal window that you installed Foundry, type the following commands:
-
-1. Make our folder where will we initialize our project. Then navigate into that folder with the following commands:
-```bash
-mkdir XRC20_Royalty && cd XRC20_Royalty
-```
-2. Initialize our Foundry project within our XRC20_Royalty folder:
-```bash
-forge init
-```
-3. Install Solmate into our Foundry project:
-```bash
-forge install rari-capital/solmate
-```
-4. Create a remappings.txt file for the Solmate library we just added:
-```bash
-touch remappings.txt
-```
-5. Open up your project in your IDE. For this tutorial, we’ll be using VSCode with this Solidity plugin:
-```bash
-code .
-```
-Here’s what our IDE looks like.
-
-
-
-
-6. Add these lines to remappings.txt so we can easily call the Solmate library in our contract:
-```bash
-solmate/=lib/solmate/src/
-forge-std=lib/forge-std/src/
-```
-Now that our environment and libraries are set up, we'll move into developing our smart contract!
-
-# Smart Contract Development
-
-We will make a contract that passes tokens to the original contract creator whenever a token is transferred between wallets!
-
-1. In your IDE, navigate to `src/Counter.sol` and rename the file to `RoyaltyToken.sol`.
-
-2. Import the Solmate ERC20 library in `RoyaltyToken.sol` and change the name of the contract. Under `pragma solidity ^0.8.14;`, add the following lines of code:
-```bash
-import { ERC20 } from "solmate/tokens/ERC20.sol";
-
-contract RoyaltyToken is ERC20 {}
-```
-3. Add in our state variables for the royalties. In the contract, add an address `royaltyAddress` variable and uint256 `royaltyFeePercentage` variable:
-```bash
-contract RoyaltyToken is ERC20 {
- address public royaltyAddress;
- uint256 public royaltyFeePercentage;
-}
-```
-4. Make a constructor for the token. A constructor is what creates our token from the imported Solmate template.
-
-Add the following variables to the constructor:
-
-1. `string memory _name`
-2. `string memory _token`
-3. `uint8 _decimals`
-4. `uint256 _royaltyFeePercentage`
-5. `uint256 _initialSupply`
-Directly after we’ve added these variables and closed the `()`, add `ERC20(_name, _symbol, _decimals)`.
-
-After that add brackets `{}` and inside the brackets set the following variables:
-
-Set `royaltyAddress` variable as the wallet address of the creator of the contract: `royaltyAddress = msg.sender;`
-The `RoyaltyFeePercentage` as the constructor variable: `royaltyFeePercentage = _royaltyFeePercentage;`
-Mint the tokens to the creator of the contract and pass in the `_initialSupply` variable: `_mint(msg.sender, _initialSupply);`
-Our constructor should now look like the following:
-```bash
-contract RoyaltyToken is ERC20 {
- address public royaltyAddress;
- uint256 public royaltyFeePercentage;
-
- constructor(
- string memory _name,
- string memory _symbol,
- uint8 _decimals,
- uint256 _royaltyFeePercentage,
- uint256 _initialSupply
- ) ERC20(_name, _symbol, _decimals) {
- royaltyAddress = msg.sender;
- royaltyFeePercentage = _royaltyFeePercentage;
- _mint(msg.sender, _initialSupply);
- }
-}
-```
-5. Next, override the transfer function.
-```bash
-function transfer(address to, uint256 amount) public virtual returns (bool) {
- balanceOf[msg.sender] -= amount;
-
- // Cannot overflow because the sum of all user
- // balances can't exceed the max uint256 value.
- unchecked {
- balanceOf[to] += amount;
- }
-
- emit Transfer(msg.sender, to, amount);
-
- return true;
- }
-```
-
-Our contract now looks like this:
-
-```bash
-pragma solidity ^0.8.14;
-
-import { ERC20 } from "solmate/tokens/ERC20.sol";
-
-contract RoyaltyToken is ERC20 {
- address public royaltyAddress;
- uint256 public royaltyFeePercentage;
-
- constructor(
- string memory _name,
- string memory _symbol,
- uint8 _decimals,
- uint256 _royaltyFeePercentage,
- uint256 _initialSupply
- ) ERC20(_name, _symbol, _decimals) {
- royaltyAddress = msg.sender;
- royaltyFeePercentage = _royaltyFeePercentage;
- _mint(msg.sender, _initialSupply);
- }
-
- function transfer(address to, uint256 amount) public virtual returns (bool) {
- balanceOf[msg.sender] -= amount;
-
- // Cannot overflow because the sum of all user
- // balances can't exceed the max uint256 value.
- unchecked {
- balanceOf[to] += amount;
- }
-
- emit Transfer(msg.sender, to, amount);
-
- return true;
- }
-}
-```
-Add override after virtual in the function declaration:
-
-
-`function transfer(address to, uint256 amount) public virtual override returns (bool) {
-...
-} `
-Inside of the `transfer` function, create a uint256 called `royaltyAmount` and set it equal to the amount in the function parameters multiplied by the `royaltyFeePercentage` divided by `100`. This calculates the royalty amount that we will be sending to our `royaltyAddress`.
-```bash
-uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
-```
-```bash
-function transfer(address to, uint256 amount) public virtual returns (bool) {
- uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
- balanceOf[msg.sender] -= amount;
-
- // Cannot overflow because the sum of all user
- // balances can't exceed the max uint256 value.
- unchecked {
- balanceOf[to] += amount;
- }
-
- emit Transfer(msg.sender, to, amount);
-
- return true;
- }
-```
-In the `unchecked {}` for the `balanceOf[to]`, subtract the amount by the `royaltyAmount` and add an additional `balanceOf[royaltyAddress]` where we add the `royaltyAmount`:
-
-```bash
-function transfer(address to, uint256 amount) public virtual returns (bool) {
- uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
- balanceOf[msg.sender] -= amount;
-
- // Cannot overflow because the sum of all user
- // balances can't exceed the max uint256 value.
- unchecked {
- //subtract the amount by the royalty amount
- balanceOf[to] += amount - royaltyAmount;
- //add to the royaltyAddress wallet the royaltyAmount
- balanceOf[royaltyAddress] += royaltyAmount;
- }
-
- emit Transfer(msg.sender, to, amount);
-
- return true;
- }
-```
-Add an additional emit Transfer where we send the royaltyAddress the royaltyAmount. Additionally, subtract the original emit Transfer amount by the royaltyAmount:
-
-```bash
-function transfer(address to, uint256 amount) public virtual override returns (bool) {
- uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
-
- balanceOf[msg.sender] -= amount;
-
- // Cannot overflow because the sum of all user
- // balances can't exceed the max uint256 value.
-
- unchecked {
- //subtract the amount by the royalty amount
- balanceOf[to] += amount - royaltyAmount;
- //add to the royaltyAddress wallet the royaltyAmount
- balanceOf[royaltyAddress] += royaltyAmount;
- }
- //transfer to the royalty address
- emit Transfer(msg.sender, royaltyAddress, royaltyAmount);
- //transfer to the original address
- emit Transfer(msg.sender, to, amount - royaltyAmount);
-
- return true;
- }
-```
-6. Our contract is now finished! In total it should look like this:
-
-```bash
-// SPDX-License-Identifier: UNLICENSED
-pragma solidity ^0.8.14;
-
-import { ERC20 } from "solmate/tokens/ERC20.sol";
-
-contract RoyaltyToken is ERC20 {
-
- address public royaltyAddress;
- uint256 public royaltyFeePercentage;
-
- constructor(
- string memory _name,
- string memory _symbol,
- uint8 _decimals,
- uint256 _royaltyFeePercentage,
- uint256 _initialSupply
- ) ERC20(_name, _symbol, _decimals) {
- royaltyAddress = msg.sender;
- royaltyFeePercentage = _royaltyFeePercentage;
- _mint(msg.sender, _initialSupply);
- }
-
- function transferWithRoyalty (address to, uint256 amount) public returns (bool) {
- uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
-
- transfer(royaltyAddress, royaltyAmount);
-
- transfer(to, amount - royaltyAmount);
-
- return true;
- }
-
- function transfer(address to, uint256 amount) public virtual override returns (bool) {
- uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
-
- balanceOf[msg.sender] -= amount;
-
- // Cannot overflow because the sum of all user
- // balances can't exceed the max uint256 value.
- unchecked {
- balanceOf[to] += amount - royaltyAmount;
- balanceOf[royaltyAddress] += royaltyAmount;
- }
- //transfer to the royalty address
- emit Transfer(msg.sender, royaltyAddress, royaltyAmount);
- //transfer to the original address
- emit Transfer(msg.sender, to, amount - royaltyAmount);
-
- return true;
- }
-}
-```
-
-# Testing Our Smart Contract
-Thanks to Foundry, we can test our new `RoyaltyToken.sol` contract in Solidity!
-
-Set up your test contract
-
-1. In your IDE, head to `test/Counter.t.sol` and rename the file to `RoyaltyToken.t.sol`.
-
-2. Delete everything in the original body of `RoyaltyToken.t.sol`.
-
-3. Add our solidity version to the top: `pragma solidity ^0.8.14;`.
-
-4. Import the RoyaltyToken from `royaltyToken.sol`. Add `import {RoyaltyToken} from "src//RoyaltyToken.sol";` to the top of your contract.
-
-5. Import forge testing tools: `import "forge-std/Test.sol";`.
-
-6. Make a new contract called `RoyaltyTokenTest` and set it to a `Test`. Our contract should look like this.
-
-```bash
-pragma solidity ^0.8.14;
-
-import {RoyaltyToken} from "src//RoyaltyToken.sol";
-
-import "forge-std/Test.sol";
-
-contract RoyaltyTokenTest is Test {}
-```
-### Create your test contract
-1. Create your `RoyaltyToken`, `RoyaltyFeePercentage`, and `InitialSupply` arguments. For this test, we will be using `2%` for the fee and `10,000` initial tokens:
-
-```bash
-pragma solidity ^0.8.14;
-
-import {RoyaltyToken} from "src//RoyaltyToken.sol";
-
-import "forge-std/Test.sol";
-
-contract RoyaltyTokenTest is Test {
- RoyaltyToken public token;
- uint256 public royaltyFeePercentage = 2;
- uint256 public initialSupply = 10 ** 4;
-}
-```
-2. Create a `setUp()` function that constructs our `RoyaltyToken`.
-```bash
-pragma solidity ^0.8.14;
-
-import {RoyaltyToken} from "src//RoyaltyToken.sol";
-
-import "forge-std/Test.sol";
-
-contract RoyaltyTokenTest is Test {
- RoyaltyToken public token;
- uint256 public royaltyFeePercentage = 2;
- uint256 public initialSupply = 10 ** 4;
-
- function setUp() public {
- token = new RoyaltyToken("RoyaltyToken", "ROYT", 18, royaltyFeePercentage, initialSupply);
- }
-
-}
-```
-3. Create a `testTransfer()` function that makes two dummy addresses and transfers funds between them. We will transfer 1,000 of the 10,000 tokens we created to an address. We're then going to check whether the address received 980 of those 1,000 tokens and whether our original contract address received the other 20. Afterward, we will initiate a transfer of 100 tokens between the newly created address and another wallet. We'll then check whether all 3 of the wallets have the correct amounts.
-```bash
-function testTransfer() public {
- address alice = address(1);
- address bob = address(2);
-
- token.transfer(alice, 1000);
-
- assertEq(token.balanceOf(alice), 980);
- assertEq(token.balanceOf(address(this)), 9020);
-
- hoax(alice);
- token.transfer(bob, 100);
-
- assertEq(token.balanceOf(alice), 880);
- assertEq(token.balanceOf(bob), 98);
- assertEq(token.balanceOf(address(this)), 9022);
- }
-```
-4. Our entire contract should look like this:
-```bash
-// SPDX-License-Identifier: UNLICENSED
-pragma solidity ^0.8.14;
-
-import {RoyaltyToken} from "src//RoyaltyToken.sol";
-
-import "forge-std/Test.sol";
-
-contract RoyaltyTokenTest is Test {
- RoyaltyToken public token;
- uint256 public royaltyFeePercentage = 2;
- uint256 public initialSupply = 10 ** 4;
-
-
- function setUp() public {
- token = new RoyaltyToken("RoyaltyToken", "ROYT", 18, royaltyFeePercentage, initialSupply);
- }
-
- function testTransfer() public {
- address alice = address(1);
- address bob = address(2);
-
- token.transfer(alice, 1000);
-
- assertEq(token.balanceOf(alice), 980);
- assertEq(token.balanceOf(address(this)), 9020);
-
- hoax(alice);
- token.transfer(bob, 100);
-
- assertEq(token.balanceOf(alice), 880);
- assertEq(token.balanceOf(bob), 98);
- assertEq(token.balanceOf(address(this)), 9022);
- }
-}
-```
-5. Now, let’s compile our contract. Open up that terminal window we used earlier and type the command `forge build` .
-```bash
-forge build
-```
-
-`Compiling...
-[⠰] Compiling 19 files with 0.8.14
-[⠒] Solc 0.8.14 finished in 2.00s
-Compiler run successful`
-
-Our smart contract is finished and is correctly compiling! Now let's test our smart contract to make sure it's actually doing what we want it to do.
-
-6. Open up terminal and run `forge test`. This runs our tests and helps us understand whether or not they passed.
-```bash
-forge test
-```
-
-`Compiling...
-No files changed, compilation skipped
-
-Running 1 test for test/RoyaltyToken.t.sol:RoyaltyTokenTest
-[PASS] testTransfer() (gas: 78242)
-Test result: ok. 1 passed; 0 failed; finished in 1.45ms`
-
-If all goes well, you've just successfully made a smart contract in foundry, overrode the original transfer function, and ran some successful tests! Now, it's time to deploy the contract.
-
-# Deploying Our Smart Contract To The Blockchain
-It's time for us to deploy our smart contract to the blockchain.
-
-1. Open up terminal and run `cast wallet new` - Create a new random keypair.
-```bash
-cast wallet new
-```
-
-`Successfully created new keypair.
-Address: 0x80B75825D86a005453A08cD1a6Bd44C24d73A41d
-Private Key: 0x4159ae5d34bb48367f9773c48de0e0effb2082681a69cd95f4e613246720af24`
-
-2. Now Copy the address and go to XDC faucet for [test XDC](https://faucet.apothem.network/), And replace `0x` by xdc.Click on request 1000 XDC.
-
-
-
-We've got everything we need to deploy our contract to the blockchain now.
-
-### Deploying Our Contract
-Head back to your terminal window to complete deployment.
-
-1. Open up the terminal and type the following command, replacing [PASTE YOUR PRIVATE KEY HERE]
-```bash
-forge create --rpc-url https://erpc.apothem.network --private-key [PASTE YOUR PRIVATE KEY HERE] src/RoyaltyToken.sol:RoyaltyToken --constructor-args "RoyaltyToken" "ROYT" 18 2 10000000000000000000000 --legacy
-```
-
-`Compiling...
-No files changed, compilation skipped
-Deployer: 0x80B75825D86a005453A08cD1a6Bd44C24d73A41d
-Deployed to: 0x27f4D21150640df0856fF6CB5d57eB4447CC59AD
-Transaction hash: 0x89f0edbf4755e93b8d25857e5a0fa0f7cae414cefac42e6ec9cb02930a932d41`
-
-
-We can now see that our contract is deployed to the blockchain. If I copy the address in Deployed to, we can view the contract on [explorer](https://apothem.blocksscan.io/address/xdc27f4D21150640df0856fF6CB5d57eB4447CC59AD#transactions).
-
-
-
-# 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 [Apothem Block Explorer](https://apothem.blocksscan.io/address/xdc27f4D21150640df0856fF6CB5d57eB4447CC59AD#transactions).
-1. Flatten our smart contract, Open up the terminal and type the following command
-```bash
-forge flatten --output src/Contract.flattened.sol src/RoyaltyToken.sol
-```
-`Flattened file written at src/Contract.flattened.sol`
-Now open the `Contract.flattened.sol` file and copy all source code, go to the [block explorer](https://apothem.blocksscan.io/address/xdc27f4D21150640df0856fF6CB5d57eB4447CC59AD#transactions) and click on Verify and Publish.
-
-
-
-
-
-
-
-
-If everything is correctly filled out, your contract page on the block explorer should display a new tab called Contract.
-
----
-For more information about XDC Network, Please Visit [XDC Network Documention](https://docs.xdc.community/).
-For more information about Foundry, Please Visit [Foundry Book](https://book.getfoundry.sh/).
-XDC Network [Disocrd](https://discord.gg/RBRx2HvbMr).
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+# How to Create and Deploy an XRC20 Token Using Foundry
+Hello World
From 4fb2ce670cf4a65f69735a85da3b248b4de67770 Mon Sep 17 00:00:00 2001
From: Jon McBee
Date: Tue, 22 Nov 2022 09:03:19 -0500
Subject: [PATCH 009/115] Update
how-to-create-and-deploy-an-xrc20-token-using-foundry.md
Promoting content after rename of doc
---
...and-deploy-an-xrc20-token-using-foundry.md | 601 +++++++++++++++++-
1 file changed, 599 insertions(+), 2 deletions(-)
diff --git a/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-foundry.md b/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-foundry.md
index 3d384ff9..680f0a85 100644
--- a/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-foundry.md
+++ b/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-foundry.md
@@ -1,3 +1,600 @@
-# How to Create and Deploy an XRC20 Token Using Foundry
+# How to make a XRC-20 Royalty Token with Foundry.
+This tutorial’s purpose is to create an XRC-20 token with foundry that will return a royalty amount (of that XRC-20 token) to the original creator of the contract.
+
+# 🧭 Table of contents
+
+- [How to make a XRC-20 Royalty Token with Foundry.](#how-to-make-a-xrc-20-royalty-token-with-foundry)
+- [🧭 Table of contents](#-table-of-contents)
+- [📰 Overview](#-overview)
+ - [What you will learn](#what-you-will-learn)
+ - [What you will do](#what-you-will-do)
+- [The Tools We're Using](#the-tools-were-using)
+- [Set up Foundry](#set-up-foundry)
+ - [Installing Foundry For MacOS / Linux:](#installing-foundry-for-macos--linux)
+ - [Installing Foundry For Windows:](#installing-foundry-for-windows)
+- [environment SetUp](#environment-setup)
+- [Smart Contract Development](#smart-contract-development)
+- [Testing Our Smart Contract](#testing-our-smart-contract)
+ - [Create your test contract](#create-your-test-contract)
+- [Deploying Our Smart Contract To The Blockchain](#deploying-our-smart-contract-to-the-blockchain)
+ - [Deploying Our Contract](#deploying-our-contract)
+- [Veryfing Contracts on the Block Explorer](#veryfing-contracts-on-the-block-explorer)
+
+
+# 📰 Overview
+
+
+
+
+[Foundry](https://book.getfoundry.sh/) is a smart contract development toolchain.
+
+Foundry manages your dependencies, compiles your project, runs tests, deploys, and lets you interact with the chain from the command-line and via Solidity scripts.
+
+### What you will learn
+In this tutorial, you will learn how to set up Foundry and use it to build, test and deploy a XRC20 Royalty Token on both the XDC Network mainnet and XDC Apothem testnet.
+
+### What you will do
+- Install and setup Foundry
+- Create an XRC20 Royalty token
+- Compile the Contract
+- Deploy the Contract
+- Interact with the XRC20 Royalty token
+- Check the deployment status on [XDC Mainnet](https://explorer.xinfin.network/) and [XDC Testnet](https://apothem.blocksscan.io/)
+
+# The Tools We're Using
+- [Foundry](https://book.getfoundry.sh/) : a fast Solidity development toolkit that enables developers to write their tests in Solidity.
+- [Solmate](https://github.com/Rari-Capital/solmate) : a library that contains gas-optimized contracts such as ERC20, ERC721, and more.
+- [Visual Studio Code](https://code.visualstudio.com/) : a source-code editor made by Microsoft with the Electron Framework, for Windows, Linux and macOS.
+- [XDC Testnet explorer](https://explorer.xinfin.network/)
+- [Testnet XDC Faucet](https://faucet.apothem.network/) : a faucet that gives 1000 XDC for test.
+- [XDCPay](https://chrome.google.com/webstore/detail/xdcpay/bocpokimicclpaiekenaeelehdjllofo) : is an extension for accessing XDC's XDPoS enabled distributed applications, or "Dapps" in your browser.
+
+# Set up Foundry
+Before we can start writing some code, we need to set up our environment. We're going to be writing our contracts and testing them in Foundry.
+
+### Installing Foundry For MacOS / Linux:
+
+Open-up terminal and type in the command:
+
+```bash
+curl -L https://foundry.paradigm.xyz | bash
+```
+
+Afterward type:
+```bash
+foundryup
+```
+Foundry should now be installed and ready to go!
+
+### Installing Foundry For Windows:
+
+If using Windows, you need to install Foundry from the source. First, install [Rust](https://rustup.rs/) with the [official documentation](https://book.getfoundry.sh/getting-started/installation).
+
+Then, open the command prompt and type in the command:
+```bash
+cargo install --git https://github.com/foundry-rs/foundry foundry-cli anvil --bins --locked
+```
+To update from source, run the same command again.
+
+# environment SetUp
+
+Now that we've installed Foundry, it's time to set up our folder where we will write our smart contract. From the same terminal window that you installed Foundry, type the following commands:
+
+1. Make our folder where will we initialize our project. Then navigate into that folder with the following commands:
+```bash
+mkdir XRC20_Royalty && cd XRC20_Royalty
+```
+2. Initialize our Foundry project within our XRC20_Royalty folder:
+```bash
+forge init
+```
+3. Install Solmate into our Foundry project:
+```bash
+forge install rari-capital/solmate
+```
+4. Create a remappings.txt file for the Solmate library we just added:
+```bash
+touch remappings.txt
+```
+5. Open up your project in your IDE. For this tutorial, we’ll be using VSCode with this Solidity plugin:
+```bash
+code .
+```
+Here’s what our IDE looks like.
+
+
+
+
+6. Add these lines to remappings.txt so we can easily call the Solmate library in our contract:
+```bash
+solmate/=lib/solmate/src/
+forge-std=lib/forge-std/src/
+```
+Now that our environment and libraries are set up, we'll move into developing our smart contract!
+
+# Smart Contract Development
+
+We will make a contract that passes tokens to the original contract creator whenever a token is transferred between wallets!
+
+1. In your IDE, navigate to `src/Counter.sol` and rename the file to `RoyaltyToken.sol`.
+
+2. Import the Solmate ERC20 library in `RoyaltyToken.sol` and change the name of the contract. Under `pragma solidity ^0.8.14;`, add the following lines of code:
+```bash
+import { ERC20 } from "solmate/tokens/ERC20.sol";
+
+contract RoyaltyToken is ERC20 {}
+```
+3. Add in our state variables for the royalties. In the contract, add an address `royaltyAddress` variable and uint256 `royaltyFeePercentage` variable:
+```bash
+contract RoyaltyToken is ERC20 {
+ address public royaltyAddress;
+ uint256 public royaltyFeePercentage;
+}
+```
+4. Make a constructor for the token. A constructor is what creates our token from the imported Solmate template.
+
+Add the following variables to the constructor:
+
+1. `string memory _name`
+2. `string memory _token`
+3. `uint8 _decimals`
+4. `uint256 _royaltyFeePercentage`
+5. `uint256 _initialSupply`
+Directly after we’ve added these variables and closed the `()`, add `ERC20(_name, _symbol, _decimals)`.
+
+After that add brackets `{}` and inside the brackets set the following variables:
+
+Set `royaltyAddress` variable as the wallet address of the creator of the contract: `royaltyAddress = msg.sender;`
+The `RoyaltyFeePercentage` as the constructor variable: `royaltyFeePercentage = _royaltyFeePercentage;`
+Mint the tokens to the creator of the contract and pass in the `_initialSupply` variable: `_mint(msg.sender, _initialSupply);`
+Our constructor should now look like the following:
+```bash
+contract RoyaltyToken is ERC20 {
+ address public royaltyAddress;
+ uint256 public royaltyFeePercentage;
+
+ constructor(
+ string memory _name,
+ string memory _symbol,
+ uint8 _decimals,
+ uint256 _royaltyFeePercentage,
+ uint256 _initialSupply
+ ) ERC20(_name, _symbol, _decimals) {
+ royaltyAddress = msg.sender;
+ royaltyFeePercentage = _royaltyFeePercentage;
+ _mint(msg.sender, _initialSupply);
+ }
+}
+```
+5. Next, override the transfer function.
+```bash
+function transfer(address to, uint256 amount) public virtual returns (bool) {
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ balanceOf[to] += amount;
+ }
+
+ emit Transfer(msg.sender, to, amount);
+
+ return true;
+ }
+```
+
+Our contract now looks like this:
+
+```bash
+pragma solidity ^0.8.14;
+
+import { ERC20 } from "solmate/tokens/ERC20.sol";
+
+contract RoyaltyToken is ERC20 {
+ address public royaltyAddress;
+ uint256 public royaltyFeePercentage;
+
+ constructor(
+ string memory _name,
+ string memory _symbol,
+ uint8 _decimals,
+ uint256 _royaltyFeePercentage,
+ uint256 _initialSupply
+ ) ERC20(_name, _symbol, _decimals) {
+ royaltyAddress = msg.sender;
+ royaltyFeePercentage = _royaltyFeePercentage;
+ _mint(msg.sender, _initialSupply);
+ }
+
+ function transfer(address to, uint256 amount) public virtual returns (bool) {
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ balanceOf[to] += amount;
+ }
+
+ emit Transfer(msg.sender, to, amount);
+
+ return true;
+ }
+}
+```
+Add override after virtual in the function declaration:
+
+
+`function transfer(address to, uint256 amount) public virtual override returns (bool) {
+...
+} `
+Inside of the `transfer` function, create a uint256 called `royaltyAmount` and set it equal to the amount in the function parameters multiplied by the `royaltyFeePercentage` divided by `100`. This calculates the royalty amount that we will be sending to our `royaltyAddress`.
+```bash
+uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+```
+```bash
+function transfer(address to, uint256 amount) public virtual returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ balanceOf[to] += amount;
+ }
+
+ emit Transfer(msg.sender, to, amount);
+
+ return true;
+ }
+```
+In the `unchecked {}` for the `balanceOf[to]`, subtract the amount by the `royaltyAmount` and add an additional `balanceOf[royaltyAddress]` where we add the `royaltyAmount`:
+
+```bash
+function transfer(address to, uint256 amount) public virtual returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ //subtract the amount by the royalty amount
+ balanceOf[to] += amount - royaltyAmount;
+ //add to the royaltyAddress wallet the royaltyAmount
+ balanceOf[royaltyAddress] += royaltyAmount;
+ }
+
+ emit Transfer(msg.sender, to, amount);
+
+ return true;
+ }
+```
+Add an additional emit Transfer where we send the royaltyAddress the royaltyAmount. Additionally, subtract the original emit Transfer amount by the royaltyAmount:
+
+```bash
+function transfer(address to, uint256 amount) public virtual override returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+
+ unchecked {
+ //subtract the amount by the royalty amount
+ balanceOf[to] += amount - royaltyAmount;
+ //add to the royaltyAddress wallet the royaltyAmount
+ balanceOf[royaltyAddress] += royaltyAmount;
+ }
+ //transfer to the royalty address
+ emit Transfer(msg.sender, royaltyAddress, royaltyAmount);
+ //transfer to the original address
+ emit Transfer(msg.sender, to, amount - royaltyAmount);
+
+ return true;
+ }
+```
+6. Our contract is now finished! In total it should look like this:
+
+```bash
+// SPDX-License-Identifier: UNLICENSED
+pragma solidity ^0.8.14;
+
+import { ERC20 } from "solmate/tokens/ERC20.sol";
+
+contract RoyaltyToken is ERC20 {
+
+ address public royaltyAddress;
+ uint256 public royaltyFeePercentage;
+
+ constructor(
+ string memory _name,
+ string memory _symbol,
+ uint8 _decimals,
+ uint256 _royaltyFeePercentage,
+ uint256 _initialSupply
+ ) ERC20(_name, _symbol, _decimals) {
+ royaltyAddress = msg.sender;
+ royaltyFeePercentage = _royaltyFeePercentage;
+ _mint(msg.sender, _initialSupply);
+ }
+
+ function transferWithRoyalty (address to, uint256 amount) public returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+
+ transfer(royaltyAddress, royaltyAmount);
+
+ transfer(to, amount - royaltyAmount);
+
+ return true;
+ }
+
+ function transfer(address to, uint256 amount) public virtual override returns (bool) {
+ uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
+
+ balanceOf[msg.sender] -= amount;
+
+ // Cannot overflow because the sum of all user
+ // balances can't exceed the max uint256 value.
+ unchecked {
+ balanceOf[to] += amount - royaltyAmount;
+ balanceOf[royaltyAddress] += royaltyAmount;
+ }
+ //transfer to the royalty address
+ emit Transfer(msg.sender, royaltyAddress, royaltyAmount);
+ //transfer to the original address
+ emit Transfer(msg.sender, to, amount - royaltyAmount);
+
+ return true;
+ }
+}
+```
+
+# Testing Our Smart Contract
+Thanks to Foundry, we can test our new `RoyaltyToken.sol` contract in Solidity!
+
+Set up your test contract
+
+1. In your IDE, head to `test/Counter.t.sol` and rename the file to `RoyaltyToken.t.sol`.
+
+2. Delete everything in the original body of `RoyaltyToken.t.sol`.
+
+3. Add our solidity version to the top: `pragma solidity ^0.8.14;`.
+
+4. Import the RoyaltyToken from `royaltyToken.sol`. Add `import {RoyaltyToken} from "src//RoyaltyToken.sol";` to the top of your contract.
+
+5. Import forge testing tools: `import "forge-std/Test.sol";`.
+
+6. Make a new contract called `RoyaltyTokenTest` and set it to a `Test`. Our contract should look like this.
+
+```bash
+pragma solidity ^0.8.14;
+
+import {RoyaltyToken} from "src//RoyaltyToken.sol";
+
+import "forge-std/Test.sol";
+
+contract RoyaltyTokenTest is Test {}
+```
+### Create your test contract
+1. Create your `RoyaltyToken`, `RoyaltyFeePercentage`, and `InitialSupply` arguments. For this test, we will be using `2%` for the fee and `10,000` initial tokens:
+
+```bash
+pragma solidity ^0.8.14;
+
+import {RoyaltyToken} from "src//RoyaltyToken.sol";
+
+import "forge-std/Test.sol";
+
+contract RoyaltyTokenTest is Test {
+ RoyaltyToken public token;
+ uint256 public royaltyFeePercentage = 2;
+ uint256 public initialSupply = 10 ** 4;
+}
+```
+2. Create a `setUp()` function that constructs our `RoyaltyToken`.
+```bash
+pragma solidity ^0.8.14;
+
+import {RoyaltyToken} from "src//RoyaltyToken.sol";
+
+import "forge-std/Test.sol";
+
+contract RoyaltyTokenTest is Test {
+ RoyaltyToken public token;
+ uint256 public royaltyFeePercentage = 2;
+ uint256 public initialSupply = 10 ** 4;
+
+ function setUp() public {
+ token = new RoyaltyToken("RoyaltyToken", "ROYT", 18, royaltyFeePercentage, initialSupply);
+ }
+
+}
+```
+3. Create a `testTransfer()` function that makes two dummy addresses and transfers funds between them. We will transfer 1,000 of the 10,000 tokens we created to an address. We're then going to check whether the address received 980 of those 1,000 tokens and whether our original contract address received the other 20. Afterward, we will initiate a transfer of 100 tokens between the newly created address and another wallet. We'll then check whether all 3 of the wallets have the correct amounts.
+```bash
+function testTransfer() public {
+ address alice = address(1);
+ address bob = address(2);
+
+ token.transfer(alice, 1000);
+
+ assertEq(token.balanceOf(alice), 980);
+ assertEq(token.balanceOf(address(this)), 9020);
+
+ hoax(alice);
+ token.transfer(bob, 100);
+
+ assertEq(token.balanceOf(alice), 880);
+ assertEq(token.balanceOf(bob), 98);
+ assertEq(token.balanceOf(address(this)), 9022);
+ }
+```
+4. Our entire contract should look like this:
+```bash
+// SPDX-License-Identifier: UNLICENSED
+pragma solidity ^0.8.14;
+
+import {RoyaltyToken} from "src//RoyaltyToken.sol";
+
+import "forge-std/Test.sol";
+
+contract RoyaltyTokenTest is Test {
+ RoyaltyToken public token;
+ uint256 public royaltyFeePercentage = 2;
+ uint256 public initialSupply = 10 ** 4;
+
+
+ function setUp() public {
+ token = new RoyaltyToken("RoyaltyToken", "ROYT", 18, royaltyFeePercentage, initialSupply);
+ }
+
+ function testTransfer() public {
+ address alice = address(1);
+ address bob = address(2);
+
+ token.transfer(alice, 1000);
+
+ assertEq(token.balanceOf(alice), 980);
+ assertEq(token.balanceOf(address(this)), 9020);
+
+ hoax(alice);
+ token.transfer(bob, 100);
+
+ assertEq(token.balanceOf(alice), 880);
+ assertEq(token.balanceOf(bob), 98);
+ assertEq(token.balanceOf(address(this)), 9022);
+ }
+}
+```
+5. Now, let’s compile our contract. Open up that terminal window we used earlier and type the command `forge build` .
+```bash
+forge build
+```
+
+`Compiling...
+[⠰] Compiling 19 files with 0.8.14
+[⠒] Solc 0.8.14 finished in 2.00s
+Compiler run successful`
+
+Our smart contract is finished and is correctly compiling! Now let's test our smart contract to make sure it's actually doing what we want it to do.
+
+6. Open up terminal and run `forge test`. This runs our tests and helps us understand whether or not they passed.
+```bash
+forge test
+```
+
+`Compiling...
+No files changed, compilation skipped
+
+Running 1 test for test/RoyaltyToken.t.sol:RoyaltyTokenTest
+[PASS] testTransfer() (gas: 78242)
+Test result: ok. 1 passed; 0 failed; finished in 1.45ms`
+
+If all goes well, you've just successfully made a smart contract in foundry, overrode the original transfer function, and ran some successful tests! Now, it's time to deploy the contract.
+
+# Deploying Our Smart Contract To The Blockchain
+It's time for us to deploy our smart contract to the blockchain.
+
+1. Open up terminal and run `cast wallet new` - Create a new random keypair.
+```bash
+cast wallet new
+```
+
+`Successfully created new keypair.
+Address: 0x80B75825D86a005453A08cD1a6Bd44C24d73A41d
+Private Key: 0x4159ae5d34bb48367f9773c48de0e0effb2082681a69cd95f4e613246720af24`
+
+2. Now Copy the address and go to XDC faucet for [test XDC](https://faucet.apothem.network/), And replace `0x` by xdc.Click on request 1000 XDC.
+
+
+
+We've got everything we need to deploy our contract to the blockchain now.
+
+### Deploying Our Contract
+Head back to your terminal window to complete deployment.
+
+1. Open up the terminal and type the following command, replacing [PASTE YOUR PRIVATE KEY HERE]
+```bash
+forge create --rpc-url https://erpc.apothem.network --private-key [PASTE YOUR PRIVATE KEY HERE] src/RoyaltyToken.sol:RoyaltyToken --constructor-args "RoyaltyToken" "ROYT" 18 2 10000000000000000000000 --legacy
+```
+
+`Compiling...
+No files changed, compilation skipped
+Deployer: 0x80B75825D86a005453A08cD1a6Bd44C24d73A41d
+Deployed to: 0x27f4D21150640df0856fF6CB5d57eB4447CC59AD
+Transaction hash: 0x89f0edbf4755e93b8d25857e5a0fa0f7cae414cefac42e6ec9cb02930a932d41`
+
+
+We can now see that our contract is deployed to the blockchain. If I copy the address in Deployed to, we can view the contract on [explorer](https://apothem.blocksscan.io/address/xdc27f4D21150640df0856fF6CB5d57eB4447CC59AD#transactions).
+
+
+
+# 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 [Apothem Block Explorer](https://apothem.blocksscan.io/address/xdc27f4D21150640df0856fF6CB5d57eB4447CC59AD#transactions).
+1. Flatten our smart contract, Open up the terminal and type the following command
+```bash
+forge flatten --output src/Contract.flattened.sol src/RoyaltyToken.sol
+```
+`Flattened file written at src/Contract.flattened.sol`
+Now open the `Contract.flattened.sol` file and copy all source code, go to the [block explorer](https://apothem.blocksscan.io/address/xdc27f4D21150640df0856fF6CB5d57eB4447CC59AD#transactions) and click on Verify and Publish.
+
+
+
+
+
+
+
+
+If everything is correctly filled out, your contract page on the block explorer should display a new tab called Contract.
+
+---
+For more information about XDC Network, Please Visit [XDC Network Documention](https://docs.xdc.org/).
+For more information about Foundry, Please Visit [Foundry Book](https://book.getfoundry.sh/).
+XDC Network [Disocrd](https://discord.gg/RBRx2HvbMr).
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-Hello World
From 8a51f8bf50793e7f21a2480bef48faa26af9b3cc Mon Sep 17 00:00:00 2001
From: Lance Lilly
Date: Wed, 23 Nov 2022 17:57:32 +0000
Subject: [PATCH 010/115] GitBook: [#139] No subject
---
get-started/xips.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/get-started/xips.md b/get-started/xips.md
index 9315e4b3..132d76a5 100644
--- a/get-started/xips.md
+++ b/get-started/xips.md
@@ -189,6 +189,7 @@ The current XIP editors are
* Jon McBee (@walterblueu)
* Fisher Yu (@fishermanymc)
+* Phillipe Menezes
Emeritus XIP editors are
From 00d67836dfaccc1159b2cbb47aa2a8e8afdbd9cd Mon Sep 17 00:00:00 2001
From: Jon McBee
Date: Wed, 8 Feb 2023 01:54:07 +0000
Subject: [PATCH 011/115] GITBOOK-140: subnets
---
.gitbook/assets/.env | 1 +
.gitbook/assets/.env.sample | 0
.gitbook/assets/.gitignore | 2 +
.gitbook/assets/.pwd | 0
.gitbook/assets/add.sh | 21 +
.gitbook/assets/bootnode.key | 1 +
.gitbook/assets/enodes_list.txt | 0
.gitbook/assets/genesis.json | 113 ++
.gitbook/assets/labels | 1489 +++++++++++++++++
.gitbook/assets/local run.sh | 45 +
.gitbook/assets/milestones | 1271 ++++++++++++++
.gitbook/assets/node1 (1).sh | 45 +
.gitbook/assets/node1.sh | 30 +
.gitbook/assets/node2 (1).sh | 30 +
.gitbook/assets/node2.sh | 45 +
.gitbook/assets/node3 (1).sh | 45 +
.gitbook/assets/node3.sh | 30 +
.gitbook/assets/node4.sh | 21 +
.gitbook/assets/node5.sh | 21 +
.gitbook/assets/node6.sh | 21 +
.gitbook/assets/pwd.txt | 0
SUMMARY.md | 3 +
...flattening-smart-contracts-with-hardhat.md | 151 +-
...flattening-smart-contracts-with-truffle.md | 163 +-
get-started/dev-environment/brownie.md | 239 ++-
get-started/xdc-design/xdpos-2.0.md | 2 +-
.../how-to-report-an-issue.md | 2 +-
...-network-using-openzeppelin-and-hardhat.md | 167 +-
...o-interact-with-xrc20-and-xrc721-tokens.md | 346 ++--
...and-deploy-an-xrc20-token-using-foundry.md | 288 ++--
...rc20-token-using-hardhat-and-typescript.md | 201 +--
...and-deploy-an-xrc20-token-using-hardhat.md | 206 +--
...and-deploy-an-xrc20-token-using-truffle.md | 209 ++-
...-and-deploy-an-xrc721-nft-using-hardhat.md | 197 +--
...ntract-on-the-xdc-network-using-truffle.md | 163 +-
...hereum-to-the-xdc-network-using-truffle.md | 149 +-
...tion-on-the-xdc-network-using-ethers.js.md | 155 +-
...-truffle-and-ganache-to-create-defi-app.md | 195 ++-
.../one-click-installer-masternode-macos.md | 2 +-
subnets/README.md | 174 ++
subnets/deploy-a-subnet.md | 3 +
subnets/requirements.md | 2 +
42 files changed, 4737 insertions(+), 1511 deletions(-)
create mode 100644 .gitbook/assets/.env
create mode 100644 .gitbook/assets/.env.sample
create mode 100644 .gitbook/assets/.gitignore
create mode 100644 .gitbook/assets/.pwd
create mode 100644 .gitbook/assets/add.sh
create mode 100644 .gitbook/assets/bootnode.key
create mode 100644 .gitbook/assets/enodes_list.txt
create mode 100644 .gitbook/assets/genesis.json
create mode 100644 .gitbook/assets/labels
create mode 100644 .gitbook/assets/local run.sh
create mode 100644 .gitbook/assets/milestones
create mode 100644 .gitbook/assets/node1 (1).sh
create mode 100644 .gitbook/assets/node1.sh
create mode 100644 .gitbook/assets/node2 (1).sh
create mode 100644 .gitbook/assets/node2.sh
create mode 100644 .gitbook/assets/node3 (1).sh
create mode 100644 .gitbook/assets/node3.sh
create mode 100644 .gitbook/assets/node4.sh
create mode 100644 .gitbook/assets/node5.sh
create mode 100644 .gitbook/assets/node6.sh
create mode 100644 .gitbook/assets/pwd.txt
create mode 100644 subnets/README.md
create mode 100644 subnets/deploy-a-subnet.md
create mode 100644 subnets/requirements.md
diff --git a/.gitbook/assets/.env b/.gitbook/assets/.env
new file mode 100644
index 00000000..eec3aa44
--- /dev/null
+++ b/.gitbook/assets/.env
@@ -0,0 +1 @@
+PRIVATE_KEY_1=
diff --git a/.gitbook/assets/.env.sample b/.gitbook/assets/.env.sample
new file mode 100644
index 00000000..e69de29b
diff --git a/.gitbook/assets/.gitignore b/.gitbook/assets/.gitignore
new file mode 100644
index 00000000..97dba2e5
--- /dev/null
+++ b/.gitbook/assets/.gitignore
@@ -0,0 +1,2 @@
+*_network
+nodes*
\ No newline at end of file
diff --git a/.gitbook/assets/.pwd b/.gitbook/assets/.pwd
new file mode 100644
index 00000000..e69de29b
diff --git a/.gitbook/assets/add.sh b/.gitbook/assets/add.sh
new file mode 100644
index 00000000..3ece0b45
--- /dev/null
+++ b/.gitbook/assets/add.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+export $(cat .env | xargs)
+Bin_NAME=XDC
+WORK_DIR=$PWD
+PROJECT_DIR="/home/xinfin/github/xinFinOrg/XDPoS-TestNet-Apothem"
+cd $PROJECT_DIR && make $Bin_NAME
+cd $WORK_DIR
+
+if [ ! -d ./nodes/4/$Bin_NAME/chaindata ]
+then
+ wallet4=$(${PROJECT_DIR}/build/bin/$Bin_NAME account import --password .pwd --datadir ./nodes/4 <(echo ${PRIVATE_KEY_4}) | awk -v FS="({|})" '{print $2}')
+ ${PROJECT_DIR}/build/bin/$Bin_NAME --datadir ./nodes/4 init ./genesis/genesis.json
+else
+ wallet4=$(${PROJECT_DIR}/build/bin/$Bin_NAME account list --datadir ./nodes/4 | head -n 1 | awk -v FS="({|})" '{print $2}')
+fi
+
+VERBOSITY=3
+GASPRICE="1"
+
+echo Starting the nodes ...
+${PROJECT_DIR}/build/bin/$Bin_NAME --bootnodes "enode://7d8ffe6d28f738d8b7c32f11fb6daa6204abae990a842025b0a969aabdda702aca95a821746332c2e618a92736538761b1660aa9defb099bc46b16db28992bc9@127.0.0.1:30301" --syncmode 'full' --datadir ./nodes/4 --networkid 853 --port 30306 --rpc --rpccorsdomain "*" --rpcaddr 0.0.0.0 --rpcport 8548 --rpcvhosts "*" --unlock "${wallet4}" --password ./.pwd --mine --gasprice "${GASPRICE}" --targetgaslimit "420000000" --verbosity ${VERBOSITY} --ethstats "XinFin-MasterNode-04:xinfin_network_stats@localhost:3005"
diff --git a/.gitbook/assets/bootnode.key b/.gitbook/assets/bootnode.key
new file mode 100644
index 00000000..fee293bd
--- /dev/null
+++ b/.gitbook/assets/bootnode.key
@@ -0,0 +1 @@
+7b7742af825d6dd12b5da3ad24a01692ff0c17269db139b29712e35ac0840eb5
\ No newline at end of file
diff --git a/.gitbook/assets/enodes_list.txt b/.gitbook/assets/enodes_list.txt
new file mode 100644
index 00000000..e69de29b
diff --git a/.gitbook/assets/genesis.json b/.gitbook/assets/genesis.json
new file mode 100644
index 00000000..5458f864
--- /dev/null
+++ b/.gitbook/assets/genesis.json
@@ -0,0 +1,113 @@
+{
+ "config": {
+ "chainId": 50,
+ "homesteadBlock": 1,
+ "eip150Block": 2,
+ "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
+ "eip155Block": 3,
+ "eip158Block": 3,
+ "byzantiumBlock": 4,
+ "XDPoS": {
+ "period": 2,
+ "epoch": 900,
+ "reward": 5000,
+ "rewardCheckpoint": 900,
+ "gap": 450,
+ "foudationWalletAddr": "xdc92a289fe95a85c53b8d0d113cbaef0c1ec98ac65"
+ }
+ },
+ "nonce": "0x0",
+ "timestamp": "0x5cefae27",
+ "extraData": "0x000000000000000000000000000000000000000000000000000000000000000025c65b4b379ac37cf78357c4915f73677022eaffc7d49d0a2cf198deebd6ce581af465944ec8b2bbcfccdea1006a5cfa7d9484b5b293b46964c265c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
+ "gasLimit": "0x47b760",
+ "difficulty": "0x1",
+ "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
+ "coinbase": "xdc0000000000000000000000000000000000000000",
+ "alloc": {
+ "0000000000000000000000000000000000000000": {
+ "balance": "0x0"
+ },
+ "0000000000000000000000000000000000000001": {
+ "balance": "0x0"
+ },
+ "0000000000000000000000000000000000000088": {
+ "code": "0x606060405260043610610196576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063012679511461019b578063025e7c27146101c957806302aa9be21461022c57806306a49fce1461026e5780630db02622146102d85780630e3e4fb81461030157806315febd68146103715780632a3640b1146103a85780632d15cc041461042a5780632f9c4bba146104b8578063302b687214610522578063326586521461058e5780633477ee2e14610640578063441a3e70146106a357806358e7525f146106cf5780635b860d271461071c5780635b9cd8cc146107695780636dd7d8ea1461082457806372e44a3814610852578063a9a981a31461089f578063a9ff959e146108c8578063ae6e43f5146108f1578063b642facd1461092a578063c45607df146109a3578063d09f1ab4146109f0578063d161c76714610a19578063d51b9e9314610a42578063d55b7dff14610a93578063ef18374a14610abc578063f2ee3c7d14610ae5578063f5c9512514610b1e578063f8ac9dd514610b4c575b600080fd5b6101c7600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610b75565b005b34156101d457600080fd5b6101ea60048080359060200190919050506111fc565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561023757600080fd5b61026c600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001909190505061123b565b005b341561027957600080fd5b610281611796565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b838110156102c45780820151818401526020810190506102a9565b505050509050019250505060405180910390f35b34156102e357600080fd5b6102eb61182a565b6040518082815260200191505060405180910390f35b341561030c57600080fd5b610357600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050611830565b604051808215151515815260200191505060405180910390f35b341561037c57600080fd5b610392600480803590602001909190505061185f565b6040518082815260200191505060405180910390f35b34156103b357600080fd5b6103e8600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506118bb565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561043557600080fd5b610461600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050611909565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b838110156104a4578082015181840152602081019050610489565b505050509050019250505060405180910390f35b34156104c357600080fd5b6104cb6119dc565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b8381101561050e5780820151818401526020810190506104f3565b505050509050019250505060405180910390f35b341561052d57600080fd5b610578600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050611a79565b6040518082815260200191505060405180910390f35b341561059957600080fd5b6105c5600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050611b03565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156106055780820151818401526020810190506105ea565b50505050905090810190601f1680156106325780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561064b57600080fd5b6106616004808035906020019091905050611da2565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34156106ae57600080fd5b6106cd6004808035906020019091908035906020019091905050611de1565b005b34156106da57600080fd5b610706600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190505061208d565b6040518082815260200191505060405180910390f35b341561072757600080fd5b610753600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506120d9565b6040518082815260200191505060405180910390f35b341561077457600080fd5b6107a9600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080359060200190919050506121a1565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156107e95780820151818401526020810190506107ce565b50505050905090810190601f1680156108165780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610850600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190505061226a565b005b341561085d57600080fd5b610889600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050612653565b6040518082815260200191505060405180910390f35b34156108aa57600080fd5b6108b261266b565b6040518082815260200191505060405180910390f35b34156108d357600080fd5b6108db612671565b6040518082815260200191505060405180910390f35b34156108fc57600080fd5b610928600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050612677565b005b341561093557600080fd5b610961600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050612c36565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34156109ae57600080fd5b6109da600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050612ca2565b6040518082815260200191505060405180910390f35b34156109fb57600080fd5b610a03612cee565b6040518082815260200191505060405180910390f35b3415610a2457600080fd5b610a2c612cf4565b6040518082815260200191505060405180910390f35b3415610a4d57600080fd5b610a79600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050612cfa565b604051808215151515815260200191505060405180910390f35b3415610a9e57600080fd5b610aa6612d53565b6040518082815260200191505060405180910390f35b3415610ac757600080fd5b610acf612d59565b6040518082815260200191505060405180910390f35b3415610af057600080fd5b610b1c600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050612d63565b005b3415610b2957600080fd5b610b4a600480803590602001908201803590602001919091929050506134f1565b005b3415610b5757600080fd5b610b5f6135f0565b6040518082815260200191505060405180910390f35b6000600b543410151515610b8857600080fd5b6000600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002080549050141580610c1c57506000600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002080549050115b1515610c2757600080fd5b81600160008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160149054906101000a900460ff16151515610c8457600080fd5b610cd934600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600101546135f690919063ffffffff16565b915060088054806001018281610cef919061362d565b9160005260206000209001600085909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550506060604051908101604052803373ffffffffffffffffffffffffffffffffffffffff16815260200160011515815260200183815250600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008201518160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060208201518160000160146101000a81548160ff02191690831515021790555060408201518160010155905050610eb834600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060020160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546135f690919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060020160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610f5160016009546135f690919063ffffffff16565b6009819055506000600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208054905014156110185760078054806001018281610fb6919061362d565b9160005260206000209001600033909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050600a600081548092919060010191905055505b600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208054806001018281611069919061362d565b9160005260206000209001600085909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208054806001018281611109919061362d565b9160005260206000209001600033909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550507f7635f1d87b47fba9f2b09e56eb4be75cca030e0cb179c1602ac9261d39a8f5c1338434604051808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001828152602001935050505060405180910390a1505050565b60078181548110151561120b57fe5b90600052602060002090016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000828280600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060020160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101515156112cd57600080fd5b3373ffffffffffffffffffffffffffffffffffffffff16600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16141561140657600b546113f882600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060020160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461361490919063ffffffff16565b1015151561140557600080fd5b5b61145b84600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206001015461361490919063ffffffff16565b600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206001018190555061153384600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060020160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461361490919063ffffffff16565b600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060020160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506115cb43600f546135f690919063ffffffff16565b9250611632846000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000016000868152602001908152602001600020546135f690919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000016000858152602001908152602001600020819055506000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060010180548060010182816116db9190613659565b9160005260206000209001600085909190915055507faa0e554f781c3c3b2be110a0557f260f11af9a8aa2c64bc1e7a31dbb21e32fa2338686604051808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001828152602001935050505060405180910390a15050505050565b61179e613685565b600880548060200260200160405190810160405280929190818152602001828054801561182057602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190600101908083116117d6575b5050505050905090565b600a5481565b60056020528160005260406000206020528060005260406000206000915091509054906101000a900460ff1681565b60008060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000016000838152602001908152602001600020549050919050565b6006602052816000526040600020818154811015156118d657fe5b90600052602060002090016000915091509054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b611911613685565b600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208054806020026020016040519081016040528092919081815260200182805480156119d057602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019060010190808311611986575b50505050509050919050565b6119e4613699565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600101805480602002602001604051908101604052809291908181526020018280548015611a6f57602002820191906000526020600020905b815481526020019060010190808311611a5b575b5050505050905090565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060020160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b611b0b6136ad565b611b1482612cfa565b15611c655760036000611b2684612c36565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600160036000611b6f86612c36565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208054905003815481101515611bba57fe5b90600052602060002090018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015611c595780601f10611c2e57610100808354040283529160200191611c59565b820191906000526020600020905b815481529060010190602001808311611c3c57829003601f168201915b50505050509050611d9d565b600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206001600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208054905003815481101515611cf657fe5b90600052602060002090018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015611d955780601f10611d6a57610100808354040283529160200191611d95565b820191906000526020600020905b815481529060010190602001808311611d7857829003601f168201915b505050505090505b919050565b600881815481101515611db157fe5b90600052602060002090016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008282600082111515611df457600080fd5b814310151515611e0357600080fd5b60008060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600001600084815260200190815260200160002054111515611e6457600080fd5b816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060010182815481101515611eb357fe5b906000526020600020900154141515611ecb57600080fd5b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160008681526020019081526020016000205492506000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000016000868152602001908152602001600020600090556000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060010184815481101515611fc457fe5b9060005260206000209001600090553373ffffffffffffffffffffffffffffffffffffffff166108fc849081150290604051600060405180830381858888f19350505050151561201357600080fd5b7ff279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b568338685604051808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001838152602001828152602001935050505060405180910390a15050505050565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600101549050919050565b60008082600160008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160149054906101000a900460ff16151561213857600080fd5b61214184612c36565b915061214b612d59565b6064600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020540281151561219757fe5b0492505050919050565b6003602052816000526040600020818154811015156121bc57fe5b9060005260206000209001600091509150508054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156122625780601f1061223757610100808354040283529160200191612262565b820191906000526020600020905b81548152906001019060200180831161224557829003601f168201915b505050505081565b600c54341015151561227b57600080fd5b80600160008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160149054906101000a900460ff1615156122d757600080fd5b61232c34600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600101546135f690919063ffffffff16565b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600101819055506000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060020160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054141561249b57600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020805480600101828161244b919061362d565b9160005260206000209001600033909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505b61252d34600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060020160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546135f690919063ffffffff16565b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060020160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055507f66a9138482c99e9baf08860110ef332cc0c23b4a199a53593d8db0fc8f96fbfc338334604051808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001828152602001935050505060405180910390a15050565b60046020528060005260406000206000915090505481565b60095481565b600f5481565b6000806000833373ffffffffffffffffffffffffffffffffffffffff16600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614151561271957600080fd5b84600160008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160149054906101000a900460ff16151561277557600080fd5b6000600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160146101000a81548160ff0219169083151502179055506127e6600160095461361490919063ffffffff16565b600981905550600094505b6008805490508510156128bb578573ffffffffffffffffffffffffffffffffffffffff1660088681548110151561282457fe5b906000526020600020900160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156128ae5760088581548110151561287b57fe5b906000526020600020900160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556128bb565b84806001019550506127f1565b600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060020160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054935061299284600160008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206001015461361490919063ffffffff16565b600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600101819055506000600160008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060020160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550612a7243600e546135f690919063ffffffff16565b9250612ad9846000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000016000868152602001908152602001600020546135f690919063ffffffff16565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000016000858152602001908152602001600020819055506000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206001018054806001018281612b829190613659565b9160005260206000209001600085909190915055507f4edf3e325d0063213a39f9085522994a1c44bea5f39e7d63ef61260a1e58c6d33387604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390a1505050505050565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b6000600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020805490509050919050565b600d5481565b600e5481565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160149054906101000a900460ff169050919050565b600b5481565b6000600a54905090565b600080612d6e613685565b600080600033600160008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160149054906101000a900460ff161515612dcf57600080fd5b87600160008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160149054906101000a900460ff161515612e2b57600080fd5b612e3433612c36565b9750612e3f89612c36565b9650600560008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151515612ed757600080fd5b6001600560008a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506001600460008973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540192505081905550604b612fc4612d59565b6064600460008b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020540281151561301057fe5b041015156134e65760016008805490500360405180591061302e5750595b9080825280602002602001820160405250955060009450600093505b600880549050841015613357578673ffffffffffffffffffffffffffffffffffffffff166130b160088681548110151561308057fe5b906000526020600020900160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16612c36565b73ffffffffffffffffffffffffffffffffffffffff16141561334a576130e3600160095461361490919063ffffffff16565b6009819055506008848154811015156130f857fe5b906000526020600020900160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16868680600101975081518110151561313857fe5b9060200190602002019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505060088481548110151561318357fe5b906000526020600020900160006101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055600160006008868154811015156131c457fe5b906000526020600020900160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600080820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556000820160146101000a81549060ff021916905560018201600090555050600360008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006132bb91906136c1565b600660008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600061330691906136e2565b600460008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600090555b838060010194505061304a565b600092505b600780549050831015613439578673ffffffffffffffffffffffffffffffffffffffff1660078481548110151561338f57fe5b906000526020600020900160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16141561342c576007838154811015156133e657fe5b906000526020600020900160006101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055600a6000815480929190600190039190505550613439565b828060010193505061335c565b7fe18d61a5bf4aa2ab40afc88aa9039d27ae17ff4ec1c65f5f414df6f02ce8b35e8787604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200180602001828103825283818151815260200191508051906020019060200280838360005b838110156134d15780820151818401526020810190506134b6565b50505050905001935050505060405180910390a15b505050505050505050565b600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002080548060010182816135429190613703565b91600052602060002090016000848490919290919250919061356592919061372f565b50507f949360d814b28a3b393a68909efe1fee120ee09cac30f360a0f80ab5415a611a338383604051808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001806020018281038252848482818152602001925080828437820191505094505050505060405180910390a15050565b600c5481565b600080828401905083811015151561360a57fe5b8091505092915050565b600082821115151561362257fe5b818303905092915050565b8154818355818115116136545781836000526020600020918201910161365391906137af565b5b505050565b8154818355818115116136805781836000526020600020918201910161367f91906137af565b5b505050565b602060405190810160405280600081525090565b602060405190810160405280600081525090565b602060405190810160405280600081525090565b50805460008255906000526020600020908101906136df91906137d4565b50565b508054600082559060005260206000209081019061370091906137af565b50565b81548183558181151161372a5781836000526020600020918201910161372991906137d4565b5b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061377057803560ff191683800117855561379e565b8280016001018555821561379e579182015b8281111561379d578235825591602001919060010190613782565b5b5090506137ab91906137af565b5090565b6137d191905b808211156137cd5760008160009055506001016137b5565b5090565b90565b6137fd91905b808211156137f957600081816137f09190613800565b506001016137da565b5090565b90565b50805460018160011615610100020316600290046000825580601f106138265750613845565b601f01602090049060005260206000209081019061384491906137af565b5b505600a165627a7a72305820f5bbb127b52ce86c873faef85cff176563476a5e49a3d88eaa9a06a8f432c9080029",
+ "storage": {
+ "0x0000000000000000000000000000000000000000000000000000000000000007": "0x0000000000000000000000000000000000000000000000000000000000000001",
+ "0x0000000000000000000000000000000000000000000000000000000000000008": "0x0000000000000000000000000000000000000000000000000000000000000003",
+ "0x0000000000000000000000000000000000000000000000000000000000000009": "0x0000000000000000000000000000000000000000000000000000000000000003",
+ "0x000000000000000000000000000000000000000000000000000000000000000a": "0x0000000000000000000000000000000000000000000000000000000000000001",
+ "0x000000000000000000000000000000000000000000000000000000000000000b": "0x000000000000000000000000000000000000000000084595161401484a000000",
+ "0x000000000000000000000000000000000000000000000000000000000000000c": "0x00000000000000000000000000000000000000000000054b40b1f852bda00000",
+ "0x000000000000000000000000000000000000000000000000000000000000000d": "0x0000000000000000000000000000000000000000000000000000000000000012",
+ "0x000000000000000000000000000000000000000000000000000000000000000e": "0x000000000000000000000000000000000000000000000000000000000013c680",
+ "0x000000000000000000000000000000000000000000000000000000000000000f": "0x0000000000000000000000000000000000000000000000000000000000069780",
+ "0x1cb68bf63bb3b55abf504ef789bb06e8b2b266a334ca39892e163225a47b8267": "0x000000000000000000000000000000000000000000084595161401484a000000",
+ "0x2c6b8fd5b2b39958a7e5a98eebf2c1c31122e89c7961ce1025e69a3d3f07fd20": "0x0000000000000000000000000000000000000000000000000000000000000001",
+ "0x3639e2dfabac2c6baff147abd66f76b8e526e974a9a2a14163169aa03d2f8d4b": "0x0000000000000000000000000000000000000000000000000000000000000001",
+ "0x473ba2a6d1aa200b3118a8abc51fe248a479e882e6c655ae014d9c66fbc181ed": "0x00000000000000000000000025c65b4b379ac37cf78357c4915f73677022eaff",
+ "0x473ba2a6d1aa200b3118a8abc51fe248a479e882e6c655ae014d9c66fbc181ee": "0x000000000000000000000000c7d49d0a2cf198deebd6ce581af465944ec8b2bb",
+ "0x473ba2a6d1aa200b3118a8abc51fe248a479e882e6c655ae014d9c66fbc181ef": "0x000000000000000000000000cfccdea1006a5cfa7d9484b5b293b46964c265c0",
+ "0x53dbb2c13e64ef254df4bb7c7b541e84dd24870927f98f151db88daa464fb4dc": "0x000000000000000000000000381047523972c9fdc3aa343e0b96900a8e2fa765",
+ "0x67a3292220e327ce969d100d7e4d83dd4b05efa763a5e4cdb04e0c0107736472": "0x000000000000000000000001381047523972c9fdc3aa343e0b96900a8e2fa765",
+ "0x67a3292220e327ce969d100d7e4d83dd4b05efa763a5e4cdb04e0c0107736473": "0x000000000000000000000000000000000000000000084595161401484a000000",
+ "0x78dfe8da08db00fe2cd4ddbd11f9cb7e4245ce35275d7734678593942034e181": "0x000000000000000000000001381047523972c9fdc3aa343e0b96900a8e2fa765",
+ "0x78dfe8da08db00fe2cd4ddbd11f9cb7e4245ce35275d7734678593942034e182": "0x000000000000000000000000000000000000000000084595161401484a000000",
+ "0x90e333b6971c3ecd09a0da09b031d63cdd2dc213d199a66955a8bf7df8a8142d": "0x000000000000000000000000000000000000000000084595161401484a000000",
+ "0xa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c688": "0x000000000000000000000000381047523972c9fdc3aa343e0b96900a8e2fa765",
+ "0xac80bed7555f6f181a34915490d97d0bfe2c0e116d1c73b34523ca0d9749955c": "0x000000000000000000000000381047523972c9fdc3aa343e0b96900a8e2fa765",
+ "0xae7e2a864ae923819e93a9f6183bc7ca0dcee93a0759238acd92344ad3216228": "0x000000000000000000000000000000000000000000084595161401484a000000",
+ "0xb375859c4c97d60e8a699586dc5dd215f38f99e40430bb9261f085ee694ffb2c": "0x0000000000000000000000000000000000000000000000000000000000000001",
+ "0xd5d5b62da76a3a9f2df0e9276cbaf8973a778bf41f7f4942e06243f195493e99": "0x000000000000000000000000381047523972c9fdc3aa343e0b96900a8e2fa765",
+ "0xec8699f61c2c8bbdbc66463590788e526c60046dda98e8c70df1fb756050baa4": "0x0000000000000000000000000000000000000000000000000000000000000003",
+ "0xf3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee3": "0x00000000000000000000000025c65b4b379ac37cf78357c4915f73677022eaff",
+ "0xf3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee4": "0x000000000000000000000000c7d49d0a2cf198deebd6ce581af465944ec8b2bb",
+ "0xf3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee5": "0x000000000000000000000000cfccdea1006a5cfa7d9484b5b293b46964c265c0",
+ "0xf4dd36495f675c407ac8f8d6dd8cc40162c854dba3ce4ce8919af34d0b1ed47c": "0x000000000000000000000001381047523972c9fdc3aa343e0b96900a8e2fa765",
+ "0xf4dd36495f675c407ac8f8d6dd8cc40162c854dba3ce4ce8919af34d0b1ed47d": "0x000000000000000000000000000000000000000000084595161401484a000000"
+ },
+ "balance": "0x18d0bf423c03d8de000000"
+ },
+ "0000000000000000000000000000000000000089": {
+ "code": "0x6060604052600436106100565763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663e341eaa4811461005b578063e7ec6aef14610076578063f4145a83146100df575b600080fd5b341561006657600080fd5b610074600435602435610104565b005b341561008157600080fd5b61008c600435610227565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156100cb5780820151838201526020016100b3565b505050509050019250505060405180910390f35b34156100ea57600080fd5b6100f26102ac565b60405190815260200160405180910390f35b438290101561011257600080fd5b600280546101289184910263ffffffff6102b216565b43111561013457600080fd5b600082815260016020819052604090912080549091810161015583826102c8565b5060009182526020808320919091018390558282528190526040902080546001810161018183826102c8565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff19163373ffffffffffffffffffffffffffffffffffffffff8116919091179091557f62855fa22e051687c32ac285857751f6d3f2c100c72756d8d30cb7ecb1f64f5490838360405173ffffffffffffffffffffffffffffffffffffffff909316835260208301919091526040808301919091526060909101905180910390a15050565b61022f6102f1565b600082815260208181526040918290208054909290918281020190519081016040528092919081815260200182805480156102a057602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311610275575b50505050509050919050565b60025481565b6000828201838110156102c157fe5b9392505050565b8154818355818115116102ec576000838152602090206102ec918101908301610303565b505050565b60206040519081016040526000815290565b61032191905b8082111561031d5760008155600101610309565b5090565b905600a165627a7a72305820a8ceddaea8e4ae00991e2ae81c8c88e160dd8770f255523282c24c2df4c30ec70029",
+ "storage": {
+ "0x0000000000000000000000000000000000000000000000000000000000000002": "0x0000000000000000000000000000000000000000000000000000000000000384"
+ },
+ "balance": "0x0"
+ },
+ "0000000000000000000000000000000000000090": {
+ "code": "0x6060604052600436106100615763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663284180fc811461006657806334d38600146100d8578063d442d6cc14610129578063e11f5ba21461015a575b600080fd5b341561007157600080fd5b610085600160a060020a0360043516610170565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156100c45780820151838201526020016100ac565b505050509050019250505060405180910390f35b34156100e357600080fd5b61012760046024813581810190830135806020818102016040519081016040528093929190818152602001838360200280828437509496506101f395505050505050565b005b341561013457600080fd5b610148600160a060020a0360043516610243565b60405190815260200160405180910390f35b341561016557600080fd5b61012760043561025e565b61017861028e565b60008083600160a060020a0316600160a060020a031681526020019081526020016000208054806020026020016040519081016040528092919081815260200182805480156101e757602002820191906000526020600020905b815481526001909101906020018083116101d2575b50505050509050919050565b610384430661032081101561020757600080fd5b610352811061021557600080fd5b600160a060020a033316600090815260208190526040902082805161023e9291602001906102a0565b505050565b600160a060020a031660009081526001602052604090205490565b610384430661035281101561027257600080fd5b50600160a060020a033316600090815260016020526040902055565b60206040519081016040526000815290565b8280548282559060005260206000209081019282156102dd579160200282015b828111156102dd57825182556020909201916001909101906102c0565b506102e99291506102ed565b5090565b61030791905b808211156102e957600081556001016102f3565b905600a165627a7a7230582034991c8dc4001fc254f3ba2811c05d2e7d29bee3908946ca56d1545b2c852de20029",
+ "balance": "0x0"
+ },
+ "0000000000000000000000000000000000000099": {
+ "code": "0x60606040526004361061011c5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663025e7c278114610165578063173825d91461019757806320ea8d86146101b65780632f54bf6e146101cc5780633411c81c146101ff57806354741525146102215780637065cb4814610250578063784547a71461026f5780638b51d13f146102855780639ace38c21461029b578063a0e67e2b14610349578063a8abe69a146103af578063b5dc40c3146103d2578063b77bf600146103e8578063ba51a6df146103fb578063c01a8c8414610411578063c642747414610427578063d74f8edd1461048c578063dc8452cd1461049f578063e20056e6146104b2578063ee22610b146104d7575b60003411156101635733600160a060020a03167fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c3460405190815260200160405180910390a25b005b341561017057600080fd5b61017b6004356104ed565b604051600160a060020a03909116815260200160405180910390f35b34156101a257600080fd5b610163600160a060020a0360043516610515565b34156101c157600080fd5b6101636004356106aa565b34156101d757600080fd5b6101eb600160a060020a0360043516610788565b604051901515815260200160405180910390f35b341561020a57600080fd5b6101eb600435600160a060020a036024351661079d565b341561022c57600080fd5b61023e600435151560243515156107bd565b60405190815260200160405180910390f35b341561025b57600080fd5b610163600160a060020a0360043516610829565b341561027a57600080fd5b6101eb600435610965565b341561029057600080fd5b61023e6004356109e9565b34156102a657600080fd5b6102b1600435610a58565b604051600160a060020a038516815260208101849052811515606082015260806040820181815290820184818151815260200191508051906020019080838360005b8381101561030b5780820151838201526020016102f3565b50505050905090810190601f1680156103385780820380516001836020036101000a031916815260200191505b509550505050505060405180910390f35b341561035457600080fd5b61035c610b36565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561039b578082015183820152602001610383565b505050509050019250505060405180910390f35b34156103ba57600080fd5b61035c60043560243560443515156064351515610b9f565b34156103dd57600080fd5b61035c600435610cc7565b34156103f357600080fd5b61023e610e2b565b341561040657600080fd5b610163600435610e31565b341561041c57600080fd5b610163600435610ec4565b341561043257600080fd5b61023e60048035600160a060020a03169060248035919060649060443590810190830135806020601f82018190048102016040519081016040528181529291906020840183838082843750949650610fb295505050505050565b341561049757600080fd5b61023e610fd1565b34156104aa57600080fd5b61023e610fd6565b34156104bd57600080fd5b610163600160a060020a0360043581169060243516610fdc565b34156104e257600080fd5b61016360043561118a565b60038054829081106104fb57fe5b600091825260209091200154600160a060020a0316905081565b600030600160a060020a031633600160a060020a031614151561053757600080fd5b600160a060020a038216600090815260026020526040902054829060ff16151561056057600080fd5b600160a060020a0383166000908152600260205260408120805460ff1916905591505b600354600019018210156106435782600160a060020a03166003838154811015156105aa57fe5b600091825260209091200154600160a060020a03161415610638576003805460001981019081106105d757fe5b60009182526020909120015460038054600160a060020a0390921691849081106105fd57fe5b6000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055610643565b600190910190610583565b6003805460001901906106569082611442565b50600354600454111561066f5760035461066f90610e31565b82600160a060020a03167f8001553a916ef2f495d26a907cc54d96ed840d7bda71e73194bf5a9df7a76b9060405160405180910390a2505050565b33600160a060020a03811660009081526002602052604090205460ff1615156106d257600080fd5b600082815260016020908152604080832033600160a060020a038116855292529091205483919060ff16151561070757600080fd5b600084815260208190526040902060030154849060ff161561072857600080fd5b6000858152600160209081526040808320600160a060020a033316808552925291829020805460ff1916905586917ff6a317157440607f36269043eb55f1287a5a19ba2216afeab88cd46cbcfb88e9905160405180910390a35050505050565b60026020526000908152604090205460ff1681565b600160209081526000928352604080842090915290825290205460ff1681565b6000805b600554811015610822578380156107ea575060008181526020819052604090206003015460ff16155b8061080e575082801561080e575060008181526020819052604090206003015460ff165b1561081a576001820191505b6001016107c1565b5092915050565b30600160a060020a031633600160a060020a031614151561084957600080fd5b600160a060020a038116600090815260026020526040902054819060ff161561087157600080fd5b81600160a060020a038116151561088757600080fd5b600380549050600101600454603282111580156108a45750818111155b80156108af57508015155b80156108ba57508115155b15156108c557600080fd5b600160a060020a0385166000908152600260205260409020805460ff1916600190811790915560038054909181016108fd8382611442565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0387169081179091557ff39e6e1eb0edcf53c221607b54b00cd28f3196fed0a24994dc308b8f611b682d60405160405180910390a25050505050565b600080805b6003548110156109e2576000848152600160205260408120600380549192918490811061099357fe5b6000918252602080832090910154600160a060020a0316835282019290925260400190205460ff16156109c7576001820191505b6004548214156109da57600192506109e2565b60010161096a565b5050919050565b6000805b600354811015610a525760008381526001602052604081206003805491929184908110610a1657fe5b6000918252602080832090910154600160a060020a0316835282019290925260400190205460ff1615610a4a576001820191505b6001016109ed565b50919050565b60006020528060005260406000206000915090508060000160009054906101000a9004600160a060020a031690806001015490806002018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610b235780601f10610af857610100808354040283529160200191610b23565b820191906000526020600020905b815481529060010190602001808311610b0657829003601f168201915b5050506003909301549192505060ff1684565b610b3e61146b565b6003805480602002602001604051908101604052809291908181526020018280548015610b9457602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610b76575b505050505090505b90565b610ba761146b565b610baf61146b565b600080600554604051805910610bc25750595b9080825280602002602001820160405250925060009150600090505b600554811015610c5757858015610c07575060008181526020819052604090206003015460ff16155b80610c2b5750848015610c2b575060008181526020819052604090206003015460ff165b15610c4f5780838381518110610c3d57fe5b60209081029091010152600191909101905b600101610bde565b878703604051805910610c675750595b908082528060200260200182016040525093508790505b86811015610cbc57828181518110610c9257fe5b906020019060200201518489830381518110610caa57fe5b60209081029091010152600101610c7e565b505050949350505050565b610ccf61146b565b610cd761146b565b6003546000908190604051805910610cec5750595b9080825280602002602001820160405250925060009150600090505b600354811015610db45760008581526001602052604081206003805491929184908110610d3157fe5b6000918252602080832090910154600160a060020a0316835282019290925260400190205460ff1615610dac576003805482908110610d6c57fe5b600091825260209091200154600160a060020a0316838381518110610d8d57fe5b600160a060020a03909216602092830290910190910152600191909101905b600101610d08565b81604051805910610dc25750595b90808252806020026020018201604052509350600090505b81811015610e2357828181518110610dee57fe5b90602001906020020151848281518110610e0457fe5b600160a060020a03909216602092830290910190910152600101610dda565b505050919050565b60055481565b30600160a060020a031633600160a060020a0316141515610e5157600080fd5b6003548160328211801590610e665750818111155b8015610e7157508015155b8015610e7c57508115155b1515610e8757600080fd5b60048390557fa3f1ee9126a074d9326c682f561767f710e927faa811f7a99829d49dc421797a8360405190815260200160405180910390a1505050565b33600160a060020a03811660009081526002602052604090205460ff161515610eec57600080fd5b6000828152602081905260409020548290600160a060020a03161515610f1157600080fd5b600083815260016020908152604080832033600160a060020a038116855292529091205484919060ff1615610f4557600080fd5b6000858152600160208181526040808420600160a060020a033316808652925292839020805460ff191690921790915586917f4a504a94899432a9846e1aa406dceb1bcfd538bb839071d49d1e5e23f5be30ef905160405180910390a3610fab8561118a565b5050505050565b6000610fbf848484611345565b9050610fca81610ec4565b9392505050565b603281565b60045481565b600030600160a060020a031633600160a060020a0316141515610ffe57600080fd5b600160a060020a038316600090815260026020526040902054839060ff16151561102757600080fd5b600160a060020a038316600090815260026020526040902054839060ff161561104f57600080fd5b600092505b6003548310156110e85784600160a060020a031660038481548110151561107757fe5b600091825260209091200154600160a060020a031614156110dd57836003848154811015156110a257fe5b6000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03929092169190911790556110e8565b600190920191611054565b600160a060020a03808616600081815260026020526040808220805460ff199081169091559388168252908190208054909316600117909255907f8001553a916ef2f495d26a907cc54d96ed840d7bda71e73194bf5a9df7a76b90905160405180910390a283600160a060020a03167ff39e6e1eb0edcf53c221607b54b00cd28f3196fed0a24994dc308b8f611b682d60405160405180910390a25050505050565b33600160a060020a03811660009081526002602052604081205490919060ff1615156111b557600080fd5b600083815260016020908152604080832033600160a060020a038116855292529091205484919060ff1615156111ea57600080fd5b600085815260208190526040902060030154859060ff161561120b57600080fd5b61121486610965565b1561133d576000868152602081905260409081902060038101805460ff19166001908117909155815490820154919750600160a060020a03169160028801905180828054600181600116156101000203166002900480156112b65780601f1061128b576101008083540402835291602001916112b6565b820191906000526020600020905b81548152906001019060200180831161129957829003601f168201915b505091505060006040518083038185875af1925050501561130357857f33e13ecb54c3076d8e8bb8c2881800a4d972b792045ffae98fdf46df365fed7560405160405180910390a261133d565b857f526441bb6c1aba3c9a4a6ca1d6545da9c2333c8c48343ef398eb858d72b7923660405160405180910390a260038501805460ff191690555b505050505050565b600083600160a060020a038116151561135d57600080fd5b600554915060806040519081016040908152600160a060020a0387168252602080830187905281830186905260006060840181905285815290819052208151815473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0391909116178155602082015181600101556040820151816002019080516113e892916020019061147d565b506060820151600391909101805460ff191691151591909117905550600580546001019055817fc0ba8fe4b176c1714197d43b9cc6bcf797a4a7461c5fe8d0ef6e184ae7601e5160405160405180910390a2509392505050565b815481835581811511611466576000838152602090206114669181019083016114fb565b505050565b60206040519081016040526000815290565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106114be57805160ff19168380011785556114eb565b828001600101855582156114eb579182015b828111156114eb5782518255916020019190600101906114d0565b506114f79291506114fb565b5090565b610b9c91905b808211156114f757600081556001016115015600a165627a7a72305820d42d65ce3cd184b1c0e98ae5fe9841a03ddd21c504e98c38f8d89df83b2b6be60029",
+ "storage": {
+ "0x0000000000000000000000000000000000000000000000000000000000000003": "0x0000000000000000000000000000000000000000000000000000000000000002",
+ "0x0000000000000000000000000000000000000000000000000000000000000004": "0x0000000000000000000000000000000000000000000000000000000000000002",
+ "0x78b26c076ef10b04070ffc86c9b244b91eb38d2b654f4e2e617edf56d2d830d8": "0x0000000000000000000000000000000000000000000000000000000000000001",
+ "0xc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b": "0x0000000000000000000000006aaf1ac2c2afdd2bca4fea2dc471d467781418c3",
+ "0xc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85c": "0x000000000000000000000000c476ce3240bb44e36746f74001d8a0d62bc917f6",
+ "0xc420d2a03bcba1d1b98a4b32ba6d074d885b5a5f366e4de6b9a7fd70184950cd": "0x0000000000000000000000000000000000000000000000000000000000000001"
+ },
+ "balance": "0x0"
+ },
+ "54d4369719bf06b194c32f8be57e2605dd5b59e5": {
+ "balance": "0x7912752226cec5131e000000"
+ },
+ "746249c61f5832c5eed53172776b460491bdcd5c": {
+ "code": "0x60606040526004361061011c5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663025e7c278114610165578063173825d91461019757806320ea8d86146101b65780632f54bf6e146101cc5780633411c81c146101ff57806354741525146102215780637065cb4814610250578063784547a71461026f5780638b51d13f146102855780639ace38c21461029b578063a0e67e2b14610349578063a8abe69a146103af578063b5dc40c3146103d2578063b77bf600146103e8578063ba51a6df146103fb578063c01a8c8414610411578063c642747414610427578063d74f8edd1461048c578063dc8452cd1461049f578063e20056e6146104b2578063ee22610b146104d7575b60003411156101635733600160a060020a03167fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c3460405190815260200160405180910390a25b005b341561017057600080fd5b61017b6004356104ed565b604051600160a060020a03909116815260200160405180910390f35b34156101a257600080fd5b610163600160a060020a0360043516610515565b34156101c157600080fd5b6101636004356106aa565b34156101d757600080fd5b6101eb600160a060020a0360043516610788565b604051901515815260200160405180910390f35b341561020a57600080fd5b6101eb600435600160a060020a036024351661079d565b341561022c57600080fd5b61023e600435151560243515156107bd565b60405190815260200160405180910390f35b341561025b57600080fd5b610163600160a060020a0360043516610829565b341561027a57600080fd5b6101eb600435610965565b341561029057600080fd5b61023e6004356109e9565b34156102a657600080fd5b6102b1600435610a58565b604051600160a060020a038516815260208101849052811515606082015260806040820181815290820184818151815260200191508051906020019080838360005b8381101561030b5780820151838201526020016102f3565b50505050905090810190601f1680156103385780820380516001836020036101000a031916815260200191505b509550505050505060405180910390f35b341561035457600080fd5b61035c610b36565b60405160208082528190810183818151815260200191508051906020019060200280838360005b8381101561039b578082015183820152602001610383565b505050509050019250505060405180910390f35b34156103ba57600080fd5b61035c60043560243560443515156064351515610b9f565b34156103dd57600080fd5b61035c600435610cc7565b34156103f357600080fd5b61023e610e2b565b341561040657600080fd5b610163600435610e31565b341561041c57600080fd5b610163600435610ec4565b341561043257600080fd5b61023e60048035600160a060020a03169060248035919060649060443590810190830135806020601f82018190048102016040519081016040528181529291906020840183838082843750949650610fb295505050505050565b341561049757600080fd5b61023e610fd1565b34156104aa57600080fd5b61023e610fd6565b34156104bd57600080fd5b610163600160a060020a0360043581169060243516610fdc565b34156104e257600080fd5b61016360043561118a565b60038054829081106104fb57fe5b600091825260209091200154600160a060020a0316905081565b600030600160a060020a031633600160a060020a031614151561053757600080fd5b600160a060020a038216600090815260026020526040902054829060ff16151561056057600080fd5b600160a060020a0383166000908152600260205260408120805460ff1916905591505b600354600019018210156106435782600160a060020a03166003838154811015156105aa57fe5b600091825260209091200154600160a060020a03161415610638576003805460001981019081106105d757fe5b60009182526020909120015460038054600160a060020a0390921691849081106105fd57fe5b6000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055610643565b600190910190610583565b6003805460001901906106569082611442565b50600354600454111561066f5760035461066f90610e31565b82600160a060020a03167f8001553a916ef2f495d26a907cc54d96ed840d7bda71e73194bf5a9df7a76b9060405160405180910390a2505050565b33600160a060020a03811660009081526002602052604090205460ff1615156106d257600080fd5b600082815260016020908152604080832033600160a060020a038116855292529091205483919060ff16151561070757600080fd5b600084815260208190526040902060030154849060ff161561072857600080fd5b6000858152600160209081526040808320600160a060020a033316808552925291829020805460ff1916905586917ff6a317157440607f36269043eb55f1287a5a19ba2216afeab88cd46cbcfb88e9905160405180910390a35050505050565b60026020526000908152604090205460ff1681565b600160209081526000928352604080842090915290825290205460ff1681565b6000805b600554811015610822578380156107ea575060008181526020819052604090206003015460ff16155b8061080e575082801561080e575060008181526020819052604090206003015460ff165b1561081a576001820191505b6001016107c1565b5092915050565b30600160a060020a031633600160a060020a031614151561084957600080fd5b600160a060020a038116600090815260026020526040902054819060ff161561087157600080fd5b81600160a060020a038116151561088757600080fd5b600380549050600101600454603282111580156108a45750818111155b80156108af57508015155b80156108ba57508115155b15156108c557600080fd5b600160a060020a0385166000908152600260205260409020805460ff1916600190811790915560038054909181016108fd8382611442565b506000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0387169081179091557ff39e6e1eb0edcf53c221607b54b00cd28f3196fed0a24994dc308b8f611b682d60405160405180910390a25050505050565b600080805b6003548110156109e2576000848152600160205260408120600380549192918490811061099357fe5b6000918252602080832090910154600160a060020a0316835282019290925260400190205460ff16156109c7576001820191505b6004548214156109da57600192506109e2565b60010161096a565b5050919050565b6000805b600354811015610a525760008381526001602052604081206003805491929184908110610a1657fe5b6000918252602080832090910154600160a060020a0316835282019290925260400190205460ff1615610a4a576001820191505b6001016109ed565b50919050565b60006020528060005260406000206000915090508060000160009054906101000a9004600160a060020a031690806001015490806002018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610b235780601f10610af857610100808354040283529160200191610b23565b820191906000526020600020905b815481529060010190602001808311610b0657829003601f168201915b5050506003909301549192505060ff1684565b610b3e61146b565b6003805480602002602001604051908101604052809291908181526020018280548015610b9457602002820191906000526020600020905b8154600160a060020a03168152600190910190602001808311610b76575b505050505090505b90565b610ba761146b565b610baf61146b565b600080600554604051805910610bc25750595b9080825280602002602001820160405250925060009150600090505b600554811015610c5757858015610c07575060008181526020819052604090206003015460ff16155b80610c2b5750848015610c2b575060008181526020819052604090206003015460ff165b15610c4f5780838381518110610c3d57fe5b60209081029091010152600191909101905b600101610bde565b878703604051805910610c675750595b908082528060200260200182016040525093508790505b86811015610cbc57828181518110610c9257fe5b906020019060200201518489830381518110610caa57fe5b60209081029091010152600101610c7e565b505050949350505050565b610ccf61146b565b610cd761146b565b6003546000908190604051805910610cec5750595b9080825280602002602001820160405250925060009150600090505b600354811015610db45760008581526001602052604081206003805491929184908110610d3157fe5b6000918252602080832090910154600160a060020a0316835282019290925260400190205460ff1615610dac576003805482908110610d6c57fe5b600091825260209091200154600160a060020a0316838381518110610d8d57fe5b600160a060020a03909216602092830290910190910152600191909101905b600101610d08565b81604051805910610dc25750595b90808252806020026020018201604052509350600090505b81811015610e2357828181518110610dee57fe5b90602001906020020151848281518110610e0457fe5b600160a060020a03909216602092830290910190910152600101610dda565b505050919050565b60055481565b30600160a060020a031633600160a060020a0316141515610e5157600080fd5b6003548160328211801590610e665750818111155b8015610e7157508015155b8015610e7c57508115155b1515610e8757600080fd5b60048390557fa3f1ee9126a074d9326c682f561767f710e927faa811f7a99829d49dc421797a8360405190815260200160405180910390a1505050565b33600160a060020a03811660009081526002602052604090205460ff161515610eec57600080fd5b6000828152602081905260409020548290600160a060020a03161515610f1157600080fd5b600083815260016020908152604080832033600160a060020a038116855292529091205484919060ff1615610f4557600080fd5b6000858152600160208181526040808420600160a060020a033316808652925292839020805460ff191690921790915586917f4a504a94899432a9846e1aa406dceb1bcfd538bb839071d49d1e5e23f5be30ef905160405180910390a3610fab8561118a565b5050505050565b6000610fbf848484611345565b9050610fca81610ec4565b9392505050565b603281565b60045481565b600030600160a060020a031633600160a060020a0316141515610ffe57600080fd5b600160a060020a038316600090815260026020526040902054839060ff16151561102757600080fd5b600160a060020a038316600090815260026020526040902054839060ff161561104f57600080fd5b600092505b6003548310156110e85784600160a060020a031660038481548110151561107757fe5b600091825260209091200154600160a060020a031614156110dd57836003848154811015156110a257fe5b6000918252602090912001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03929092169190911790556110e8565b600190920191611054565b600160a060020a03808616600081815260026020526040808220805460ff199081169091559388168252908190208054909316600117909255907f8001553a916ef2f495d26a907cc54d96ed840d7bda71e73194bf5a9df7a76b90905160405180910390a283600160a060020a03167ff39e6e1eb0edcf53c221607b54b00cd28f3196fed0a24994dc308b8f611b682d60405160405180910390a25050505050565b33600160a060020a03811660009081526002602052604081205490919060ff1615156111b557600080fd5b600083815260016020908152604080832033600160a060020a038116855292529091205484919060ff1615156111ea57600080fd5b600085815260208190526040902060030154859060ff161561120b57600080fd5b61121486610965565b1561133d576000868152602081905260409081902060038101805460ff19166001908117909155815490820154919750600160a060020a03169160028801905180828054600181600116156101000203166002900480156112b65780601f1061128b576101008083540402835291602001916112b6565b820191906000526020600020905b81548152906001019060200180831161129957829003601f168201915b505091505060006040518083038185875af1925050501561130357857f33e13ecb54c3076d8e8bb8c2881800a4d972b792045ffae98fdf46df365fed7560405160405180910390a261133d565b857f526441bb6c1aba3c9a4a6ca1d6545da9c2333c8c48343ef398eb858d72b7923660405160405180910390a260038501805460ff191690555b505050505050565b600083600160a060020a038116151561135d57600080fd5b600554915060806040519081016040908152600160a060020a0387168252602080830187905281830186905260006060840181905285815290819052208151815473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0391909116178155602082015181600101556040820151816002019080516113e892916020019061147d565b506060820151600391909101805460ff191691151591909117905550600580546001019055817fc0ba8fe4b176c1714197d43b9cc6bcf797a4a7461c5fe8d0ef6e184ae7601e5160405160405180910390a2509392505050565b815481835581811511611466576000838152602090206114669181019083016114fb565b505050565b60206040519081016040526000815290565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106114be57805160ff19168380011785556114eb565b828001600101855582156114eb579182015b828111156114eb5782518255916020019190600101906114d0565b506114f79291506114fb565b5090565b610b9c91905b808211156114f757600081556001016115015600a165627a7a72305820d42d65ce3cd184b1c0e98ae5fe9841a03ddd21c504e98c38f8d89df83b2b6be60029",
+ "storage": {
+ "0x0000000000000000000000000000000000000000000000000000000000000003": "0x0000000000000000000000000000000000000000000000000000000000000002",
+ "0x0000000000000000000000000000000000000000000000000000000000000004": "0x0000000000000000000000000000000000000000000000000000000000000002",
+ "0x53a74cb8e1409f2fa6885f50a9cd170366c9e7e52c8ca5e4c8268ec2e66088e0": "0x0000000000000000000000000000000000000000000000000000000000000001",
+ "0xb689ca06605d85e946f5fb4cd76cafa04abd8cd4d1cd4e2e8a559464b7f2b8ca": "0x0000000000000000000000000000000000000000000000000000000000000001",
+ "0xc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b": "0x000000000000000000000000ca97040ea64b0eb127370b92f6941e9d0cb87134",
+ "0xc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85c": "0x000000000000000000000000d1c8103106710ba08b5596c0ed115b508c879c74"
+ },
+ "balance": "0x0"
+ }
+ },
+ "number": "0x0",
+ "gasUsed": "0x0",
+ "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
+}
diff --git a/.gitbook/assets/labels b/.gitbook/assets/labels
new file mode 100644
index 00000000..7b202152
--- /dev/null
+++ b/.gitbook/assets/labels
@@ -0,0 +1,1489 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Labels · XinFinOrg/Local_DPoS_Setup · GitHub
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ You can’t perform that action at this time.
+
+
+
+
+ You signed in with another tab or window. Reload to refresh your session.
+ You signed out in another tab or window. Reload to refresh your session.
+
If this project had milestones, we’d show you them here. Promise!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ You can’t perform that action at this time.
+
+
+
+
+ You signed in with another tab or window. Reload to refresh your session.
+ You signed out in another tab or window. Reload to refresh your session.
+
+
Press `ENTER` to get started with a new JavaScript Hardhat Project. Then you will be presented with the following options:
-```sh
+```
? Hardhat project root: ‣ /home/path/to/MyCounter
// Press ENTER or y
@@ -90,17 +92,15 @@ Press `ENTER` to get started with a new JavaScript Hardhat Project. Then you wil
The standard Hardhat project comes with a pre-created `Lock.sol` contract and `deploy.js` script. Lets clean up our working environment before moving forward:
-```sh
+```
rm -rf ./contracts/Lock.sol ./scripts/deploy.js ./test/Lock.js
```
And your folder files will look like this:
-
-
-
+
-## ⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat
+### ⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat
In order to get started deploying new contracts on XDC Mainnet and/or Apothem, we need to install a new dependency called `dotenv` that will be used in the `hardhat.config.js` file:
@@ -121,6 +121,7 @@ XINFIN_NETWORK_URL=https://erpc.xinfin.network
APOTHEM_NETWORK_URL=https://erpc.apothem.network
PRIVATE_KEY=202e3c9d30bbeca38d6578659919d4c3dc989ae18c16756690877fdc4dfa607f
```
+
🚨 **Do not use the Private Key in the example above in production or you can risk losing your assets!** 🚨
And finally, we can configure the `hardhat.config.js` file for both Apothem and XinFin Networks by writting:
@@ -144,16 +145,17 @@ module.exports = {
};
```
-## ⚒ Adding Testnet XDC to Development Wallet
+### ⚒ Adding Testnet XDC to Development Wallet
Let's check our Signer's Address on Hardhat by accessing the hardhat console:
-```sh
+```
npx hardhat console --network xinfin
```
+
If you get an error that hardhat is not installed locally and are running on a Windows OS you will need to execute:
-```sh
+```
npm install --save-dev @nomicfoundation/hardhat-toolbox
```
@@ -172,15 +174,13 @@ This account is on the Ethereum standard format starting with `0x`, but we can s
With this account in hand, we can head to the [Apothem Faucet](https://faucet.apothem.network/) and claim some TXDC for development purposes:
-
-
-
+
-# 💵 Writing Smart Contract
+## 💵 Writing Smart Contract
We will be using OpenZeppelin for this guide so lets install it first:
-```sh
+```
npm install @openzeppelin/contracts
```
@@ -212,32 +212,31 @@ contract MyCounter {
}
```
-## 💵 Compiling and Testing
+### 💵 Compiling and Testing
We can now compile our `MyCounter.sol` by running:
-```sh
+```
npx hardhat compile
```
If everything is correctly configured and there is no errors, you should see the following message on your console:
-```sh
+```
Downloading compiler 0.8.16
Compiled 2 Solidity files successfully
```
And your folder should look like this:
-
-
-
+
-### Testing
+#### Testing
Now lets create a simple test to see everything works as intended before we deploy our contract to live network. This will save us time and gas fees, so it is recommended you do as much as possible tests for your smart contracts before deploying.
Create file `MyCounter.js` under `test` directory:
+
```javascript
const { expect } = require("chai");
@@ -270,13 +269,13 @@ describe("MyCounter contract", function () {
Then run:
-```sh
+```
npx hardhat test
```
Your output should look like this:
-```sh
+```
MyCounter contract
✔ should deploy MyCounter (847ms)
✔ should increment and decrement MyCounter and show current count (66ms)
@@ -284,11 +283,11 @@ MyCounter contract
2 passing (916ms)
```
-## 💵 Deploying Contract
+### 💵 Deploying Contract
In order to deploy our newly compiled contract artifacts to the blockchain, we need to create a deployment script into the script folder:
-```sh
+```
touch ./scripts/deploy.js
```
@@ -316,13 +315,13 @@ main()
If the deployment script have no errors, we can go ahead and run the command:
-```sh
+```
npx hardhat run scripts/deploy.js --network xinfin
```
For deployment on XDC mainet, or:
-```sh
+```
npx hardhat run scripts/deploy.js --network apothem
```
@@ -330,12 +329,12 @@ For deployment on the XDC Apothem Testnet. In either case, you need to have enou
If the deployment is sucessful, the console should log the following message after migrations complete processing:
-```sh
+```
MyCounter Successfully Deployed!
MyCounter address: 0xfCd7d366048a50E0600C46Dd854Da343050EB3A1
```
-## 💵 Flattening Contract
+### 💵 Flattening Contract
If smart contract imports external files like ours, we need to flatten it before verifying on Block Explorer.
@@ -347,40 +346,34 @@ npx hardhat flatten contracts/MyCounter.sol > MyCounterFlatten.sol
Then open `MyCounterFlatten.sol` and remove every line which starts with `// SPDX-License-Identifier` except the first one. We do this because Block Explorer does not accepts contracts with mutliple license definitions.
-# 🔍 Veryfing Contracts on the Block Explorer
+## 🔍 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/).
Lets grab the `MyCounter.sol` address from the previous step: 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/):
-
-
-
+
And click in the `Verify And Publish` Option.
We will be redirected to the Contract verification page where we need to fill out:
-- Contract Name: MyCounter
-- Compiler: Check your `hardhat-config.js` file for Compiler Version
-- Contract Code: Just paste everything from your `MyCounterFlatten.sol` file
+* Contract Name: _MyCounter_
+* Compiler: _Check your_ `hardhat-config.js` _file for Compiler Version_
+* Contract Code: _Just paste everything from your_ `MyCounterFlatten.sol` _file_
❕ Keep in mind that `Contract Code` should be `MyCounterFlatten.sol`, not `MyCounter.sol`. ❕
Once everything is filled out, press Submit!
-
-
-
+
If everything is correctly filled out, your contract page on the block explorer should display a new tab called `Contract`:
-
-
-
+
----
+***
-For more information about Hardhat, Please Visit [Hardhat Documentation](https://hardhat.org/tutorial).
-For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.community/).
+For more information about Hardhat, Please Visit [Hardhat Documentation](https://hardhat.org/tutorial).\
+For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.community/).\
Resources used during the deployment of the MyCounter can be found at [MyCounter Contract Folder](https://github.com/XDC-Community/docs/tree/main/how-to/SmartContract/Flatten/Hardhat/example-flatten-smart-contract).
diff --git a/get-details/smart-contract-details/flattening-smart-contracts/flattening-smart-contracts-with-truffle.md b/get-details/smart-contract-details/flattening-smart-contracts/flattening-smart-contracts-with-truffle.md
index 9214cb3f..5c0d79ce 100644
--- a/get-details/smart-contract-details/flattening-smart-contracts/flattening-smart-contracts-with-truffle.md
+++ b/get-details/smart-contract-details/flattening-smart-contracts/flattening-smart-contracts-with-truffle.md
@@ -1,53 +1,58 @@
---
id: flatten-contract-truffle
title: Flatten a Smart Contract Using Truffle
-description: "Use Truffle to deploy and verify smart contract"
keywords:
- docs
- apothem
- token
- flatten
- truffle
+description: Use Truffle to deploy and verify smart contract
---
-# 🧭 Table of contents
-
-- [🧭 Table of contents](#-table-of-contents)
-- [📰 Overview](#-overview)
- - [What you will learn](#what-you-will-learn)
- - [What you will do](#what-you-will-do)
-- [🚀 Setting up the development environment](#-setting-up-the-development-environment)
- - [⚒ 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 Smart Contract](#-writing-smart-contract)
- - [💵 Compiling and Testing](#-compiling-and-testing)
- - [Testing](#testing)
- - [💵 Deploying Contract](#-deploying-contract)
- - [💵 Flattening Contract](#-flattening-contract)
-- [🔍 Veryfing Contracts on the Block Explorer](#-veryfing-contracts-on-the-block-explorer)
-
-# 📰 Overview
+# Flattening Smart Contracts with Truffle
+
+## 🧭 Table of contents
+
+* [🧭 Table of contents](flattening-smart-contracts-with-truffle.md#-table-of-contents)
+* [📰 Overview](flattening-smart-contracts-with-truffle.md#-overview)
+ * [What you will learn](flattening-smart-contracts-with-truffle.md#what-you-will-learn)
+ * [What you will do](flattening-smart-contracts-with-truffle.md#what-you-will-do)
+* [🚀 Setting up the development environment](flattening-smart-contracts-with-truffle.md#-setting-up-the-development-environment)
+ * [⚒ Starting a new Truffle Project](flattening-smart-contracts-with-truffle.md#-starting-a-new-truffle-project)
+ * [⚒ Configuring XDC Mainnet and Apothem Testnet on Truffle](flattening-smart-contracts-with-truffle.md#-configuring-xdc-mainnet-and-apothem-testnet-on-truffle)
+ * [⚒ Adding Testnet XDC to Development Wallet](flattening-smart-contracts-with-truffle.md#-adding-testnet-xdc-to-development-wallet)
+* [💵 Writing Smart Contract](flattening-smart-contracts-with-truffle.md#-writing-smart-contract)
+ * [💵 Compiling and Testing](flattening-smart-contracts-with-truffle.md#-compiling-and-testing)
+ * [Testing](flattening-smart-contracts-with-truffle.md#testing)
+ * [💵 Deploying Contract](flattening-smart-contracts-with-truffle.md#-deploying-contract)
+ * [💵 Flattening Contract](flattening-smart-contracts-with-truffle.md#-flattening-contract)
+* [🔍 Veryfing Contracts on the Block Explorer](flattening-smart-contracts-with-truffle.md#-veryfing-contracts-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.
-### What you will learn
+#### What you will learn
+
In this tutorial, you will learn how to set up Truffle and use it to build, test and deploy smart contract on both the XDC Network mainnet and XDC Apothem testnet and verify it on Block Explorer.
-### What you will do
-- Install and set up Truffle
-- Create a complex smart contract with dependencies (like OpenZeppelin)
-- Compile the smart contract
-- Test the smart contract
-- Deploy the smart contract
-- Flatten the smart contract
-- Verify the smart contract
+#### What you will do
+
+* Install and set up Truffle
+* Create a complex smart contract with dependencies (like OpenZeppelin)
+* Compile the smart contract
+* Test the smart contract
+* Deploy the smart contract
+* Flatten the smart contract
+* Verify the smart contract
-# 🚀 Setting up the development environment
+## 🚀 Setting up the development environment
There are a few technical requirements before we start. Please install the following:
-- [Node.js v8+ LTS and npm](https://nodejs.org/en/) (comes with Node)
-- [Git](https://git-scm.com/)
+* [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:
@@ -55,7 +60,7 @@ Once we have those installed, we only need one command to install Truffle:
npm install -g truffle
```
-To verify that Truffle is installed properly, type **`truffle version`** on a terminal. You should see something like:
+To verify that Truffle is installed properly, type **`truffle version`** on a terminal. You should see something like:
```bash
Truffle v5.5.27 (core: 5.5.27)
@@ -67,7 +72,7 @@ Web3.js v1.7.4
If you see an error instead, make sure that your npm modules are added to your path.
-## ⚒ Starting a new Truffle Project
+### ⚒ Starting a new Truffle Project
Lets start by setting up our folder, we are creating a project called `MyCounter`, create a new `MyCounter` folder by running on terminal
@@ -94,31 +99,29 @@ http://trufflesuite.com/docs
And your folder files will look like this:
-
-
-
-
+
-## ⚒ Configuring XDC Mainnet and Apothem Testnet on Truffle
+### ⚒ 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`.
- 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 might need to install it first.\
+‼️You can skip this step if you already have yarn installed‼️
-```sh
+```
npm install --global yarn
```
Initialize your package manager on your folder and install the required dependencies:
-```sh
+```
yarn init -y
yarn add @truffle/hdwallet-provider dotenv
```
You will also need a **24-Word Mnemonic Phrase**. To configure your wallet, create a new `.env` file and write your mnemonic by running:
-```sh
+```
touch .env
echo MNEMONIC=arm derive cupboard decade course garlic journey blast tribe describe curve obey >> .env
```
@@ -129,7 +132,6 @@ Remember to change the **24-Word Mnemonic** above for your own mnemonic. The con
MNEMONIC=arm derive cupboard decade course garlic journey blast tribe describe curve obey
```
-
🚨 **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:
@@ -173,17 +175,17 @@ module.exports = {
};
```
-## ⚒ Adding Testnet XDC to Development Wallet
+### ⚒ Adding Testnet XDC to Development Wallet
It is possible to list all XDC addresses bound to your mnemonic on truffle by accessing the truffle console:
-```sh
+```
truffle console --network xinfin
```
Once the truffle console CLI opens, you can run:
-```sh
+```
truffle(xinfin)> accounts
```
@@ -208,21 +210,19 @@ These accounts are on the Ethereum standard format starting with `0x`, but we ca
With this account in hand, we can head to the [Apothem Faucet](https://faucet.apothem.network/) and claim some TXDC for development purposes:
-
-
-
+
-# 💵 Writing Smart Contract
+## 💵 Writing Smart Contract
We will be using OpenZeppelin for this guide so lets install it first:
-```sh
+```
yarn add @openzeppelin/contracts
```
or using `npm`
-```sh
+```
npm install @openzeppelin/contracts
```
@@ -254,17 +254,17 @@ contract MyCounter {
}
```
-## 💵 Compiling and Testing
+### 💵 Compiling and Testing
We can compile our `MyCounter.sol` by running:
-```sh
+```
truffle compile
```
If everything is correctly configured and there is no errors, you should see the following message on your console:
-```sh
+```
Compiling your contracts...
===========================
> Compiling ./contracts/MyCounter.sol
@@ -276,15 +276,14 @@ Compiling your contracts...
And your folder should look like this:
-
-
-
+
-### Testing
+#### Testing
Now lets create a simple test to see everything works as intended before we deploy our contract to live network. This will save us time and gas fees, so it is recommended you do as much as possible tests for your smart contracts before deploying.
Create file `MyCounter.js` under `test` directory:
+
```javascript
const MyCounter = artifacts.require("MyCounter");
@@ -315,13 +314,13 @@ contract("MyCounter", (accounts) => {
Then run
-```sh
+```
truffle test
```
Your output should look like this:
-```sh
+```
Contract: MyCounter
✔ should deploy MyCounter
✔ should increment and decrement MyCounter and show current count (131ms)
@@ -329,11 +328,11 @@ Contract: MyCounter
2 passing (197ms)
```
-## 💵 Deploying Contract
+### 💵 Deploying Contract
In order to deploy our newly compiled contract artifacts to the blockchain, we need to create a deployment script into the migrations folder:
-```sh
+```
touch ./migrations/1_token_migration.js
```
@@ -349,13 +348,13 @@ module.exports = function (deployer) {
If the migration script have no errors, we can go ahead and run the command:
-```sh
+```
truffle migrate --network xinfin
```
For deployment on XDC mainet, or:
-```sh
+```
truffle migrate --network apothem
```
@@ -363,7 +362,7 @@ For deployment on the XDC Apothem Testnet. In either case, you need to have enou
If the deployment is sucessful, the console should log the following message after migrations complete processing:
-```sh
+```
1_counter_migration.js
======================
@@ -391,7 +390,7 @@ Summary
> Final cost: 0.0032993 ETH
```
-## 💵 Flattening Contract
+### 💵 Flattening Contract
If smart contract imports external files like our, we need to flatten it before verifying on Block Explorer.
@@ -415,19 +414,19 @@ truffle-flattener contracts/MyCounter.sol > MyCounterFlatten.sol
Then open `MyCounterFlatten.sol` and remove every line which starts with `// SPDX-License-Identifier` except the first one. We do this because Block Explorer does not accepts contracts with mutliple license definition.
-# 🔍 Veryfing Contracts on the Block Explorer
+## 🔍 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/).
First lets check the address our contract is deployed to by running:
-```sh
+```
truffle networks
```
If you have a contract already deployed, the console should log something like this:
-```sh
+```
Network: apothem (id: 51)
No contracts deployed.
@@ -437,34 +436,28 @@ Network: xinfin (id: 50)
Here we have a `MyCounter` 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/):
-
-
-
+
And click in the `Verify And Publish` Option.
We will be redirected to the Contract verification page where we need to fill out:
-- Contract Name: MyCounter
-- Compiler: Check your `truffle-config.js` file for Compiler Version
-- Contract Code: Just paste everything from your `MyCounterFlatten.sol` file
+* Contract Name: _MyCounter_
+* Compiler: _Check your_ `truffle-config.js` _file for Compiler Version_
+* Contract Code: _Just paste everything from your_ `MyCounterFlatten.sol` _file_
❕ Keep in mind that `Contract Code` should be `MyCounterFlatten.sol`, not `MyCounter.sol`. ❕
Once everything is filled out, press Submit!
-
-
-
+
If everything is correctly filled out, your contract page on the block explorer should display a new tab called `Contract`:
-
-
-
+
----
+***
-For more information about Truffle Suite, Please Visit [Truffle Suite Documentation](https://trufflesuite.com/docs/truffle/).
-For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.community/).
+For more information about Truffle Suite, Please Visit [Truffle Suite Documentation](https://trufflesuite.com/docs/truffle/).\
+For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.community/).\
Resources used during the deployment of the MyCounter can be found at [MyCounter Contract Folder](https://github.com/XDC-Community/docs/tree/main/how-to/SmartContract/Flatten/Truffle/example-flatten-smart-contract).
diff --git a/get-started/dev-environment/brownie.md b/get-started/dev-environment/brownie.md
index 3898a18a..c7223734 100644
--- a/get-started/dev-environment/brownie.md
+++ b/get-started/dev-environment/brownie.md
@@ -1,120 +1,119 @@
-Brownie is Python-Based framework for developing custom smart contracts on the Blockchain, we will be deploying XRC20 to XDC Network using brownie
-
-Things we need:
- - Python > 3.8
- - eth-brownie
-
- ##### Brownie works well with Python above 3.8
-
- ```code
- python -m pip install eth-brownie
- ```
- 
-
- 
-
- Will get you the latest eth-brownie version from pypi packages
-
- After installation eth-brownie should be in your terminal enviroment as *brownie*
-
- Fire up a terminal and type *brownie --help* to make sure everything is good
-
- 
-
-#### Connecting to XDC Network Using Brownie
-
-Using a suitable RPC address we will be connecting to a node on XDC Network to be use on brownie
-
-We will connect to Testnet using RPC https://apothemxdcpayrpc.blocksscan.io/
-
-```brownie network list``` will print a list of network that we have available and ready to use yet we need to add XDC since it does not come by default in brownie
-
-To easily connect to XDC Network when using brownie we will be adding it as default in our Brownie Networks enviroment type the following:
-
-```brownie networks add xdc testnet host=https://apothemxdcpayrpc.blocksscan.io/ chainid=51```
-
-
-
-### Interacting with XDC Network using Brownie
-
-We our network already added on our brownie list we will proceed to interact with it
-
-Lighting up a terminal type ```brownie console --network tesnet```
-
-
-
-```chain.id``` print us ```51``` letting us know that are already connected to XDC
-
-### Querying Account balances
-
-We will add an account to query the balance we have available on XDC
-
-```
->>> from web3 import Account
->>> account = accounts.add(Account.create().key)
->>> account.address
-'0x4D0928Df315D816d9a6540CF79D7c547C5294eA8'
->>> account.balance()
-100000000000000000000
->>>
-```
-
-
-
-Our balance in fact:
-
-
-
-
-
-
-
-## Initializing a new Brownie Project
-
-Using ```brownie init``` will output us a project structure containing folder to initialize our new project (tokens, etc)
-
-
-
-#### Transfering XDC between Accounts using Brownie
-
-below we are transfering some XDC main token between accounts using browning
-
-
-
-
-
-### Compiling a XRC20 & deploying to the network
-
- We will be deploying the following XRC20
- ```solidity
- pragma solidity >=0.8.0 <0.9.0;
-import "./XRC20.sol";
-address constant owner = 0x4D0928Df315D816d9a6540CF79D7c547C5294eA8;
-contract BlastToken is XRC20Token {
- constructor() XRC20Token('Blaster Token', 'Blast', 18, 1000*10**18) {}
-}
- ```
-
-
-
-
-
-Deployed Token
-
-
-
-After deployment the we can see "Blast Token" on-chain https://explorer.apothem.network/tokens/xdcaccf490aea9a2c17d60a62672ee519e61b5a1ec5
-
-### Adding the token to XDC Pay & transfering
-
-
-
-
-
-
-
-## Some transactions done
-
-https://explorer.apothem.network/txs/0x23bbf8d8f84bbfdc85cce7493cb388e968f0aed3715b95fa81d3ac7c1614d004#overview
-
-https://explorer.apothem.network/txs/0x2acf5757d236580c98b0c7e4ec864f700964ffa0cf3fcf7fe6130fe2a77a8d0c#overview
\ No newline at end of file
+# Brownie
+
+Brownie is Python-Based framework for developing custom smart contracts on the Blockchain, we will be deploying XRC20 to XDC Network using brownie
+
+Things we need:
+
+* Python > 3.8
+* eth-brownie
+
+**Brownie works well with Python above 3.8**
+
+```
+ python -m pip install eth-brownie
+```
+
+
+
+
+
+Will get you the latest eth-brownie version from pypi packages
+
+After installation eth-brownie should be in your terminal enviroment as _brownie_
+
+Fire up a terminal and type _brownie --help_ to make sure everything is good
+
+
+
+**Connecting to XDC Network Using Brownie**
+
+Using a suitable RPC address we will be connecting to a node on XDC Network to be use on brownie
+
+We will connect to Testnet using RPC https://apothemxdcpayrpc.blocksscan.io/
+
+`brownie network list` will print a list of network that we have available and ready to use yet we need to add XDC since it does not come by default in brownie
+
+To easily connect to XDC Network when using brownie we will be adding it as default in our Brownie Networks enviroment type the following:
+
+`brownie networks add xdc testnet host=https://apothemxdcpayrpc.blocksscan.io/ chainid=51`
+
+
+
+#### Interacting with XDC Network using Brownie
+
+We our network already added on our brownie list we will proceed to interact with it
+
+Lighting up a terminal type `brownie console --network tesnet`
+
+
+
+`chain.id` print us `51` letting us know that are already connected to XDC
+
+#### Querying Account balances
+
+We will add an account to query the balance we have available on XDC
+
+```
+>>> from web3 import Account
+>>> account = accounts.add(Account.create().key)
+>>> account.address
+'0x4D0928Df315D816d9a6540CF79D7c547C5294eA8'
+>>> account.balance()
+100000000000000000000
+>>>
+```
+
+
+
+Our balance in fact:
+
+
+
+### Initializing a new Brownie Project
+
+Using `brownie init` will output us a project structure containing folder to initialize our new project (tokens, etc)
+
+
+
+**Transfering XDC between Accounts using Brownie**
+
+below we are transfering some XDC main token between accounts using browning
+
+
+
+
+
+#### Compiling a XRC20 & deploying to the network
+
+We will be deploying the following XRC20
+
+```solidity
+pragma solidity >=0.8.0 <0.9.0;
+import "./XRC20.sol";
+address constant owner = 0x4D0928Df315D816d9a6540CF79D7c547C5294eA8;
+contract BlastToken is XRC20Token {
+ constructor() XRC20Token('Blaster Token', 'Blast', 18, 1000*10**18) {}
+}
+```
+
+
+
+
+
+Deployed Token
+
+
+
+After deployment the we can see "Blast Token" on-chain https://explorer.apothem.network/tokens/xdcaccf490aea9a2c17d60a62672ee519e61b5a1ec5
+
+#### Adding the token to XDC Pay & transfering
+
+
+
+
+
+### Some transactions done
+
+https://explorer.apothem.network/txs/0x23bbf8d8f84bbfdc85cce7493cb388e968f0aed3715b95fa81d3ac7c1614d004#overview
+
+https://explorer.apothem.network/txs/0x2acf5757d236580c98b0c7e4ec864f700964ffa0cf3fcf7fe6130fe2a77a8d0c#overview
diff --git a/get-started/xdc-design/xdpos-2.0.md b/get-started/xdc-design/xdpos-2.0.md
index e8d1c33e..9c22fee3 100644
--- a/get-started/xdc-design/xdpos-2.0.md
+++ b/get-started/xdc-design/xdpos-2.0.md
@@ -98,7 +98,7 @@ The protocol is a leader-based one proceeding in rounds. Each round has a differ
The block data structure is similar to that in Ethereum, except that a parentQC field is added to the block header. Here QC stands for quorum certificate. It is created by the leader of round-r for the block in r −1 (the parent block) when at least tH = dVALIDATOR\_SET\_SIZE × 2/3e master nodes have voted for this parent block, certifying that this parent block has been approved by the super-majority of the nodes. A QC contains the parent block hash1 , the round number, and the metadata such as signatures of the vote messages. In case of no proposal and/or a timeout in a round r − 1, nodes will send a "timeout" message for this round, and the leader of round r will gather tH of them into a timeout certificate (TC), so that this round can be dropped from the 1This parent hash is the same as header.parentHash. But we do not override header.parentHash for the sake of backwards-compatibility. 6 blockchain. We note that round number is not the same as block number - round number might be skipped in the blockchain but block numbers are guaranteed to be consecutive. Figure 2 shows an example of the main chain with QCs. Note that round r + 2 is skipped in the main chain due to timeout. The specification of data structures is provided in Algorithm 1.
-
Figure 2: XDC blockchain
+
Figure 2: XDC blockchain
`Algorithm 1 Data Structures in the protocol`
diff --git a/learn/community-support/how-to-report-an-issue.md b/learn/community-support/how-to-report-an-issue.md
index b94c722c..30511a68 100644
--- a/learn/community-support/how-to-report-an-issue.md
+++ b/learn/community-support/how-to-report-an-issue.md
@@ -35,7 +35,7 @@ In general the issue reporting process has two steps:
1. On [xdc.dev](https://www.xdc.dev/) (after having created an account) click on the "Create Post" button in the upper right hand corner.
-
+
2. Add a descriptive title to your post and be sure to provide a link back to the GitHub issue in the body of the post.
diff --git a/learn/how-to-articles/create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md b/learn/how-to-articles/create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md
index 18ec1f90..1be864a3 100644
--- a/learn/how-to-articles/create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md
+++ b/learn/how-to-articles/create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md
@@ -1,60 +1,58 @@
# Create and Deploy Your First Smart Contract on the XDC Network Using OpenZeppelin and Hardhat
-# 🧭 Table of contents
-
-- [Create and Deploy Your First Smart Contract on the XDC Network Using OpenZeppelin and Hardhat](#create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat)
-- [🧭 Table of contents](#-table-of-contents)
-- [📰 Overview](#-overview)
- - [What you will learn](#what-you-will-learn)
- - [What you will do](#what-you-will-do)
-- [⚒ Starting a new Hardhat Project](#-starting-a-new-hardhat-project)
- - [Prerequisites](#prerequisites)
- - [Setup for a Hardhat Project](#setup-for-a-hardhat-project)
-- [💵 Write Smart Contract Using OpenZeppelin](#-write-smart-contract-using-openzeppelin)
- - [Compile the Contract](#compile-the-contract)
- - [Writing a script file to deploy the contract](#writing-a-script-file-to-deploy-the-contract)
- - [Setup .env file](#setup-env-file)
- - [⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat](#-configuring-xdc-mainnet-and-apothem-testnet-on-hardhat)
- - [💵 Deploying the contract](#-deploying-the-contract)
- - [Flattening the Smart Contract](#flattening-the-smart-contract)
- - [🔍 Veryfing Contracts on the Block Explorer](#-veryfing-contracts-on-the-block-explorer)
-
-# 📰 Overview
-
-
+## Create and Deploy Your First Smart Contract on the XDC Network Using OpenZeppelin and Hardhat
+
+## 🧭 Table of contents
+
+* [Create and Deploy Your First Smart Contract on the XDC Network Using OpenZeppelin and Hardhat](create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md#create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat)
+* [🧭 Table of contents](create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md#-table-of-contents)
+* [📰 Overview](create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md#-overview)
+ * [What you will learn](create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md#what-you-will-learn)
+ * [What you will do](create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md#what-you-will-do)
+* [⚒ Starting a new Hardhat Project](create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md#-starting-a-new-hardhat-project)
+ * [Prerequisites](create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md#prerequisites)
+ * [Setup for a Hardhat Project](create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md#setup-for-a-hardhat-project)
+* [💵 Write Smart Contract Using OpenZeppelin](create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md#-write-smart-contract-using-openzeppelin)
+ * [Compile the Contract](create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md#compile-the-contract)
+ * [Writing a script file to deploy the contract](create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md#writing-a-script-file-to-deploy-the-contract)
+ * [Setup .env file](create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md#setup-env-file)
+ * [⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat](create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md#-configuring-xdc-mainnet-and-apothem-testnet-on-hardhat)
+ * [💵 Deploying the contract](create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md#-deploying-the-contract)
+ * [Flattening the Smart Contract](create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md#flattening-the-smart-contract)
+ * [🔍 Veryfing Contracts on the Block Explorer](create-and-deploy-your-first-smart-contract-on-the-xdc-network-using-openzeppelin-and-hardhat.md#-veryfing-contracts-on-the-block-explorer)
+
+## 📰 Overview
[OpenZeppelin](https://www.openzeppelin.com/) is an open-source framework that helps to build secure smart contracts to automate your decentralized applications.
OpenZeppelin contracts are written in solidity and use ERC standards for Ethereum-based tokens.
-### What you will learn
+#### What you will learn
In this tutorial, you will learn how to set up Hardhat and use it to build, test, and deploy a smart contract build with OpenZeppelin on both the XDC Network mainnet and XDC Apothem testnet.
-The complete tutorial code can be found [here](./xdc-openzeppelin).
+The complete tutorial code can be found [here](xdc-openzeppelin/).
-### What you will do
+#### What you will do
-- Install and setup Hardhat
-- Create a smart contract with the help of openzeppelin
-- Compile the smart contract
-- Deploy the smart contract
-- Interact with the smart contract
-- Check the deployment status on [xinfin.network](https://xinfin.network/#stats)
+* Install and setup Hardhat
+* Create a smart contract with the help of openzeppelin
+* Compile the smart contract
+* Deploy the smart contract
+* Interact with the smart contract
+* Check the deployment status on [xinfin.network](https://xinfin.network/#stats)
-# ⚒ Starting a new Hardhat Project
+## ⚒ Starting a new Hardhat Project
-### Prerequisites
+#### Prerequisites
Metamask wallet ([Extension link](https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn?hl=en)) or XDC Pay wallet ([Extension link](https://chrome.google.com/webstore/detail/xdcpay/bocpokimicclpaiekenaeelehdjllofo))
-Don't know how to create a wallet? [Click here](https://myterablock.medium.com/how-to-create-or-import-a-metamask-wallet-a551fc2f5a6b#:~:text=Click%20on%20the%20MetaMask%20extension,or%20create%20a%20new%20one.&text=Click%20on%20%E2%80%9CCreate%20a%20Wallet,%E2%80%9CNo%20Thanks%E2%80%9D%20to%20proceed.)
+Don't know how to create a wallet? [Click here](https://myterablock.medium.com/how-to-create-or-import-a-metamask-wallet-a551fc2f5a6b)
Node.js. ([Download link](https://nodejs.org/en/download/))
-### Setup for a Hardhat Project
+#### Setup for a Hardhat Project
First, you'll need to setup your hardhat project. Open the terminal and follow these commands.
@@ -78,12 +76,12 @@ In the same directory, run:
npx hardhat
```
-
+
-- Select `Create a Javascript project` or `Create a Typescript project` according to your requirement.
-- Specify Hardhat Project root or press enter for already specified path.
-- Specify `y` for yes and `n` for no for adding a .gitignore
-- Press enter for `Do you want to install this sample project's dependencies with npm (@nomicfoundation/hardhat-toolbox)?`
+* Select `Create a Javascript project` or `Create a Typescript project` according to your requirement.
+* Specify Hardhat Project root or press enter for already specified path.
+* Specify `y` for yes and `n` for no for adding a .gitignore
+* Press enter for `Do you want to install this sample project's dependencies with npm (@nomicfoundation/hardhat-toolbox)?`
Note: If you are on windows, install this:
@@ -91,10 +89,9 @@ Note: If you are on windows, install this:
npm install --save-dev @nomicfoundation/hardhat-toolbox
```
-Now, you will have a folder structure as below
-
+Now, you will have a folder structure as below 
-# 💵 Write Smart Contract Using OpenZeppelin
+## 💵 Write Smart Contract Using OpenZeppelin
To use OpenZeppelin contracts, install the package in the project using:
@@ -171,9 +168,9 @@ contract MyToken is ERC20 {
}
```
-## Compile the Contract
+### Compile the Contract
-- To compile the contract, write the following in the terminal:
+* To compile the contract, write the following in the terminal:
```bash
npx hardhat compile
@@ -183,11 +180,11 @@ If this returns errors, check your contract and rectify them.
If everything is correctly configured and there is no errors, you should see the following message on your console:
-```sh
+```
Compiled 5 Solidity files successfully
```
-## Writing a script file to deploy the contract
+### Writing a script file to deploy the contract
For writing the script to deploy the contract, create `deploy.js` in `scripts` folder, if it is already not there. Copy the following code in the `deploy.js`:
@@ -213,19 +210,19 @@ main()
});
```
-- To add the XDC Testnet network to metamask: (If you are using XDCPay, you don't have to follow this step)
+* To add the XDC Testnet network to metamask: (If you are using XDCPay, you don't have to follow this step)
-
+
-- To add XDC mainnet network to metamask: (If you are using XDCPay you don't have to follow this step)
+* To add XDC mainnet network to metamask: (If you are using XDCPay you don't have to follow this step)
-
+
-## Setup .env file
+### Setup .env file
> Make sure you do not push this file to github.
-- Make a `.env` at the root of the project to store the private key and network url.
+* Make a `.env` at the root of the project to store the private key and network url.
```python
XINFIN_NETWORK_URL="enter-network-rpc-url-here"
@@ -242,30 +239,29 @@ PRIVATE_KEY=202e3c9d30bbeca38d6578659919d4c3dc989ae18c16756690877fdc4dfa607f
🚨 **Do not use the Private Key in the example above in production or you can risk losing your assets!** 🚨
-- Dont know how to get your private key? Open your XDCPay wallet extension and click on the three dots on the top-left. This will open a popup.
-
+* Dont know how to get your private key? Open your XDCPay wallet extension and click on the three dots on the top-left. This will open a popup. 
Click on the `Export Private key` inside the popup.
-
+
Enter the password that you used while creating the account.
-
+
Copy your private key. This key will be used to sign transactions when deploying the contract through hardhat.
-
+
-## ⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat
+### ⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat
-- To be able to import env file variables, please install `dotenv` from your terminal:
+* To be able to import env file variables, please install `dotenv` from your terminal:
```bash
npm install dotenv
```
-- Open the `hardhat.config.js` file. Now we will add the network url and private key of our wallet to this file, so that we can deploy our contract. Your `harhat.config.js` should look like this.
+* Open the `hardhat.config.js` file. Now we will add the network url and private key of our wallet to this file, so that we can deploy our contract. Your `harhat.config.js` should look like this.
```jsx
require("@nomicfoundation/hardhat-toolbox");
@@ -286,7 +282,7 @@ module.exports = {
};
```
-## 💵 Deploying the contract
+### 💵 Deploying the contract
After writing code for the setup and contract, go back to the terminal. Make sure you are in your project directory and type:
@@ -298,7 +294,7 @@ npx hardhat run scripts/deploy.js --network xinfin
For the testnet:
-```sh
+```
npx hardhat run scripts/deploy.js --network apothem
```
@@ -306,11 +302,11 @@ In either case, you need to have enough funds to pay gas fees on the address tha
If the deployment is sucessful, the console should log the following message after migrations complete processing:
-```sh
+```
My token contract address: 0xc8Ac88d77b9870D289806F54AfF9057f170bAb21
```
-## Flattening the Smart Contract
+### Flattening the Smart Contract
When importing third-party libraries like OpenZeppelin, it becomes necessary to flatten your smart contract and then verify it on the blockscan, because blockscan doesn't have access to the OpenZeppelin's code. When we flatten the code, the OpenZeppelin's code will be included in the same file as your samrt contract.
@@ -328,7 +324,7 @@ npx hardhat flatten ./contracts/MyToken.sol > flattenedMyToken.sol
This will create a new file `flattenedMyToken.sol` which would include flattened code for your smart contract.
-## 🔍 Veryfing Contracts on the Block Explorer
+### 🔍 Veryfing Contracts on the Block Explorer
Once you have successfully deployed your smart contract to the blockchain, it might be interesting to verify your contract on [XinFin Block Explorer](https://explorer.xinfin.network/).
@@ -336,45 +332,30 @@ Change the prefix `0x` to `xdc` to look for your contract on [XinFin Block Explo
In this example, there is a `MyToken` contract deployed on XDC Mainnet at the `0x802555081f6AAcE51559d0650Bf15f242aBe7fd7`. You could search for your newly deployed contract on [XinFin Block Explorer](https://explorer.xinfin.network/):
-
-
-
-
-
+
Click in the `Verify And Publish` Option.
You will be redirected to the contract verification page where we need to fill out:
-- Contract Name: MyToken
-- Compiler: Check your `hardhat-config.js` file for Compiler Version
-- Contract Code: Just paste everything from your `flattenedMyToken.sol` file
+* Contract Name: _MyToken_
+* Compiler: _Check your_ `hardhat-config.js` _file for Compiler Version_
+* Contract Code: _Just paste everything from your_ `flattenedMyToken.sol` _file_
Once everything is filled out, press Submit!
-
-
-
-
-
+
If everything is correctly filled out, your contract page on the block explorer should display a new tab called `Contract`:
-
-
-
-
-
+
In this page you can Read from, Write to, or simply read the information tied to your Smart Contract on the blockchain:
-
-
-
-
+
----
+***
-For more information about Hardhat, Please Visit [Hardhat Documentation](https://hardhat.org/tutorial).
-For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).
+For more information about Hardhat, Please Visit [Hardhat Documentation](https://hardhat.org/tutorial).\
+For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).\
Resources used during the deployment of the openzeppelin ERC20 Token can be found [here](https://docs.openzeppelin.com/contracts/4.x/erc20).
diff --git a/learn/how-to-articles/how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md b/learn/how-to-articles/how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md
index 3d78fb2b..ede5f5d9 100644
--- a/learn/how-to-articles/how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md
+++ b/learn/how-to-articles/how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md
@@ -1,125 +1,129 @@
---
id: xdc-frontend-integration
title: Creating a front-end for an XDC dApp.
-description: "Creating a front-end for an XDC decentralized app and connecting it to XDC smart contracts."
keywords:
- docs
- apothem
- dApp
- front-end
- XRC20
+description: >-
+ Creating a front-end for an XDC decentralized app and connecting it to XDC
+ smart contracts.
---
-# 🧭 Table of contents
-
-- [🧭 Table of contents](#-table-of-contents)
-- [📰 Overview](#-overview)
- - [What you will learn](#what-you-will-learn)
- - [What you will do](#what-you-will-do)
- - [What you will need](#what-you-will-need)
-- [🚀 Project Introduction](#-project-introduction)
- - [Smart Contracts](#smart-contracts)
- - [Using Truffle](#using-truffle)
- - [Using Hardhat](#using-hardhat)
- - [Using Remix](#using-remix)
- - [XRC20 Egg Token](#xrc20-egg-token)
- - [XRC721 Egg NFT](#xrc721-egg-nft)
- - [About XRC721 Egg NFT Metadata](#about-xrc721-egg-nft-metadata)
- - [EGT Faucet](#egt-faucet)
- - [Migration script using Truffle](#migration-script-using-truffle)
- - [Migration script using Hardhat](#migration-script-using-hardhat)
-- [📀 Flattening Solidity files](#-flattening-solidity-files)
- - [Step 01](#step-01)
- - [Step 02](#step-02)
- - [Step 03](#step-03)
-- [🏗 Building a Front-End Application](#-building-a-front-end-application)
- - [Creating Smart Contract Instances in React](#creating-smart-contract-instances-in-react)
- - [EggToken.ts](#eggtokents)
- - [EggNFT.ts](#eggnftts)
- - [Faucet.ts](#faucetts)
- - [Creating Smart Contract Constants File](#creating-smart-contract-constants-file)
- - [Creating Smart Contract Wrappers in React](#creating-smart-contract-wrappers-in-react)
- - [EggTokenWrapper.ts](#eggtokenwrapperts)
- - [EggNFTWrapper.ts](#eggnftwrapperts)
- - [FaucetWrapper.ts](#faucetwrapperts)
- - [Creating a Blockchain Context Provider in React](#creating-a-blockchain-context-provider-in-react)
- - [Integrating Blockchain Methods to DOM elements](#integrating-blockchain-methods-to-dom-elements)
- - [Updating `app.tsx` elements](#updating-apptsx-elements)
-- [💧 Setting up Faucet Contract](#-setting-up-faucet-contract)
- - [On Truffle](#on-truffle)
- - [On Hardhat](#on-hardhat)
-- [🔥 DApp Demo](#-dapp-demo)
-
- # 📰 Overview
-
+# How-To Create a React App to Interact with XRC20 and XRC721 Tokens
+
+## 🧭 Table of contents
+
+* [🧭 Table of contents](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#-table-of-contents)
+* [📰 Overview](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#-overview)
+ * [What you will learn](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#what-you-will-learn)
+ * [What you will do](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#what-you-will-do)
+ * [What you will need](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#what-you-will-need)
+* [🚀 Project Introduction](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#-project-introduction)
+ * [Smart Contracts](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#smart-contracts)
+ * [Using Truffle](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#using-truffle)
+ * [Using Hardhat](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#using-hardhat)
+ * [Using Remix](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#using-remix)
+ * [XRC20 Egg Token](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#xrc20-egg-token)
+ * [XRC721 Egg NFT](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#xrc721-egg-nft)
+ * [About XRC721 Egg NFT Metadata](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#about-xrc721-egg-nft-metadata)
+ * [EGT Faucet](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#egt-faucet)
+ * [Migration script using Truffle](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#migration-script-using-truffle)
+ * [Migration script using Hardhat](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#migration-script-using-hardhat)
+* [📀 Flattening Solidity files](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#-flattening-solidity-files)
+ * [Step 01](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#step-01)
+ * [Step 02](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#step-02)
+ * [Step 03](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#step-03)
+* [🏗 Building a Front-End Application](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#-building-a-front-end-application)
+ * [Creating Smart Contract Instances in React](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#creating-smart-contract-instances-in-react)
+ * [EggToken.ts](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#eggtokents)
+ * [EggNFT.ts](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#eggnftts)
+ * [Faucet.ts](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#faucetts)
+ * [Creating Smart Contract Constants File](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#creating-smart-contract-constants-file)
+ * [Creating Smart Contract Wrappers in React](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#creating-smart-contract-wrappers-in-react)
+ * [EggTokenWrapper.ts](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#eggtokenwrapperts)
+ * [EggNFTWrapper.ts](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#eggnftwrapperts)
+ * [FaucetWrapper.ts](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#faucetwrapperts)
+ * [Creating a Blockchain Context Provider in React](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#creating-a-blockchain-context-provider-in-react)
+ * [Integrating Blockchain Methods to DOM elements](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#integrating-blockchain-methods-to-dom-elements)
+ * [Updating `app.tsx` elements](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#updating-apptsx-elements)
+* [💧 Setting up Faucet Contract](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#-setting-up-faucet-contract)
+ * [On Truffle](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#on-truffle)
+ * [On Hardhat](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#on-hardhat)
+* [🔥 DApp Demo](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#-dapp-demo)
+
+## 📰 Overview
+
In this tutorial, you will work with a few different tools to create a working decentralized App front-end from start to finish, leveraging [React](https://reactjs.org/) to bootstrap our front end. [Web3Modal](https://www.npmjs.com/package/web3modal) and [web3.js](https://www.npmjs.com/package/web3) will be used to create a touchpoint between our front-end and the XDC Network. You'll use the smart contract development environment of your choice: [Truffle](https://trufflesuite.com/), [Hardhat](https://hardhat.org/) or [Remix](https://remix.xinfin.network/)!
-### What you will learn
+#### What you will learn
+
In this tutorial, you will learn how to interact with XDC Network smart contracts and tokens through a simple web front-end on the XDC Network mainnet and XDC Apothem testnet.
-### What you will do
- - Create a simple web front end
- - Further instructions on how to deploy multiple smart contracts
- - Interact with smart contracts
- - Create Interfaces to use XRC20 tokens on a React App
- - Create Interfaces to use XRC721 tokens on a React App
+#### What you will do
-### What you will need
+* Create a simple web front end
+* Further instructions on how to deploy multiple smart contracts
+* Interact with smart contracts
+* Create Interfaces to use XRC20 tokens on a React App
+* Create Interfaces to use XRC721 tokens on a React App
+
+#### What you will need
There are a few technical requirements before we start. Please install the following:
-- [Node.js v8+ LTS and npm](https://nodejs.org/en/) (comes with Node)
-- [Git](https://git-scm.com/)
+* [Node.js v8+ LTS and npm](https://nodejs.org/en/) (comes with Node)
+* [Git](https://git-scm.com/)
As you will be using XDCPay to interact with our first dApp on XDC Network, you can download XDCPay at:
-- [XDCPay on Chrome Store](https://chrome.google.com/webstore/detail/xdcpay/bocpokimicclpaiekenaeelehdjllofo)
+* [XDCPay on Chrome Store](https://chrome.google.com/webstore/detail/xdcpay/bocpokimicclpaiekenaeelehdjllofo)
-# 🚀 Project Introduction
+## 🚀 Project Introduction
This tutorial is full of important concepts and we wanted to make something both interesting and fun, with that in mind, we are happy to introduce `EGG GACHA`!
-
-
-
-
-
- EGG GACHA!
-
-
+
+
+**EGG GACHA!**
Gacha is a Japanese term for a small toy sold in a plastic capsule in a vending machine. And this is what we will make: A NFT vending machine where you can trade in an XRC20 token for a new XRC721 non-fungible token. We will create in the course of this tutorial:
- 1. An XRC20 Token called `EGT` (Egg Tokens);
- 2. An XRC721 Token called `EGGS`;
- 3. An `EGT Faucet` smart contract, so people can get more `EGT` and buy new `EGGS`;
- 4. An interface where users can interact with `EGT`, `EGGS` and the `EGT Faucet` Smart Contract;
-
- ## Smart Contracts
-
+1. An XRC20 Token called `EGT` (Egg Tokens);
+2. An XRC721 Token called `EGGS`;
+3. An `EGT Faucet` smart contract, so people can get more `EGT` and buy new `EGGS`;
+4. An interface where users can interact with `EGT`, `EGGS` and the `EGT Faucet` Smart Contract;
+
+### Smart Contracts
+
It is not uncommon to see several smart contracts interacting in a real-world application to create a complete user experience - and that's what you'll be doing here. You will deploy three smart contracts that depend on one another to create our decentralized app experience.
**If you have never deployed a Smart Contract on XDC Mainnet or Apothem Tesnet, please check the following tutorials before continuing** (You can chose between using **Truffle**, **Hardhat** or **Remix**):
-### Using Truffle
-:rotating_light: [Use Truffle to deploy a Smart Contract](https://github.com/XDC-Community/docs/blob/main/how-to/truffle.md)
-:rotating_light: [Use Truffle to deploy a XRC20 Token](https://github.com/XDC-Community/docs/blob/main/how-to/XRC20/Truffle/how-to.md)
-:rotating_light: [Use Truffle to deploy a XRC721 Token](https://github.com/XDC-Community/docs/blob/main/how-to/XRC721/Truffle/how-to.md)
+#### Using Truffle
+
+:rotating\_light: [Use Truffle to deploy a Smart Contract](../../how-to/truffle.md)\
+:rotating\_light: [Use Truffle to deploy a XRC20 Token](../../how-to/XRC20/Truffle/how-to.md)\
+:rotating\_light: [Use Truffle to deploy a XRC721 Token](../../how-to/XRC721/Truffle/how-to.md)
+
+#### Using Hardhat
-### Using Hardhat
-:rotating_light: [Use Hardhat to deploy a Smart Contract](https://github.com/XDC-Community/docs/blob/main/how-to/contract-hardhat.md)
-:rotating_light: [Use Hardhat to deploy a XRC20 Token](https://github.com/XDC-Community/docs/blob/main/how-to/XRC20/Hardhat/how-to.md)
+:rotating\_light: [Use Hardhat to deploy a Smart Contract](../../how-to/contract-hardhat.md)\
+:rotating\_light: [Use Hardhat to deploy a XRC20 Token](../../how-to/XRC20/Hardhat/how-to.md)
-### Using Remix
-:rotating_light: [Use Remix to deploy a Smart Contract](https://github.com/XDC-Community/docs/blob/main/how-to/remix-example.md)
-:rotating_light: [Use Remix to deploy a XRC20 Token](https://github.com/XDC-Community/docs/blob/main/how-to/XRC20/Remix/how-to.md)
-:rotating_light: [Use Remix to deploy a XRC721 Token](https://github.com/XDC-Community/docs/blob/main/how-to/XRC721/Remix/XRC721.md)
+#### Using Remix
-## XRC20 Egg Token
+:rotating\_light: [Use Remix to deploy a Smart Contract](../../how-to/remix-example.md)\
+:rotating\_light: [Use Remix to deploy a XRC20 Token](../../how-to/XRC20/Remix/how-to.md)\
+:rotating\_light: [Use Remix to deploy a XRC721 Token](../../how-to/XRC721/Remix/XRC721.md)
-First, you will abstract some of the code for the EGT tokens using Open Zeppelin's [Smart Contract Wizard](https://docs.openzeppelin.com/contracts/4.x/wizard). If you followed one of the tutorials listed in the [Smart Contracts](#smart-contracts) section, you might need to install `@openzeppelin/contracts` to your working directory first:
+### XRC20 Egg Token
-```sh
+First, you will abstract some of the code for the EGT tokens using Open Zeppelin's [Smart Contract Wizard](https://docs.openzeppelin.com/contracts/4.x/wizard). If you followed one of the tutorials listed in the [Smart Contracts](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#smart-contracts) section, you might need to install `@openzeppelin/contracts` to your working directory first:
+
+```
npm install @openzeppelin/contracts
```
@@ -141,7 +145,7 @@ contract EggToken is ERC20, Ownable {
:bangbang: IMPORTANT: the contract above needs to be flattened to get verified on the block explorer :bangbang:
-## XRC721 Egg NFT
+### XRC721 Egg NFT
Following the same logic as above, you will ceate an `Eggs.sol` file using a Open Zeppelin's smart contracts with a few small changes:
@@ -228,14 +232,14 @@ contract EggNFT is ERC721, ERC721Enumerable, ERC721URIStorage, Ownable {
}
}
```
+
:bangbang: IMPORTANT: the contract above needs to be flattened to get verified on the block explorer :bangbang:
-## About XRC721 Egg NFT Metadata
+### About XRC721 Egg NFT Metadata
In the section above, we define the NFT metadata inside the `buyEgg()` method:
```solidity
-
_setTokenURI(tokenId,
string(
abi.encodePacked(
@@ -251,7 +255,7 @@ This URI is pointing to a pre-defined list of assets created for this tutorial a
Publishing files to IPFS is not within the scope of this tutorial, but if you want to know more, check out [This tutorial on how to create NFTs and publish metadata to IPFS using Pinata](https://github.com/menezesphill/eggnator).
-## EGT Faucet
+### EGT Faucet
You also need to provide users a way to claim a few `EGT` tokens! The best way to do so is creating a FAUCET smart contract. Our faucet will have a `claimTokens()` method that users can call to get `50 EGT tokens` for free every 24-hours. Create a `Faucet.sol` contract with the following code:
@@ -305,9 +309,9 @@ contract Faucet is Ownable {
}
```
-## Migration script using Truffle
+### Migration script using Truffle
-If you followed the [Use Truffle to deploy a Smart Contract](https://github.com/XDC-Community/docs/blob/main/how-to/truffle.md) tutorial, you might need to adjust your migration script accordingly so all three smart contracts are correctly deployed to the blockchain. For Truffle, you'll need to create a `1_project_migration.js` file with the following code:
+If you followed the [Use Truffle to deploy a Smart Contract](../../how-to/truffle.md) tutorial, you might need to adjust your migration script accordingly so all three smart contracts are correctly deployed to the blockchain. For Truffle, you'll need to create a `1_project_migration.js` file with the following code:
```jsx
const EGT = artifacts.require("EggToken");
@@ -323,14 +327,11 @@ module.exports = function (deployer) {
And your folder should look like this:
-
-
-
-
+
-## Migration script using Hardhat
+### Migration script using Hardhat
-Conversely, if you followed the [Use Hardhat to deploy a Smart Contract](https://github.com/XDC-Community/docs/blob/main/how-to/contract-hardhat.md) tutorial, you need to adjust your `deploy.js` script to deploy all three contracts:
+Conversely, if you followed the [Use Hardhat to deploy a Smart Contract](../../how-to/contract-hardhat.md) tutorial, you need to adjust your `deploy.js` script to deploy all three contracts:
```jsx
async function main() {
@@ -365,88 +366,76 @@ async function main() {
And your folder should look like this:
-
-
-
+
-# 📀 Flattening Solidity files
+## 📀 Flattening Solidity files
To **Verify and Publish** your smart contracts inherited from `@openzeppelin/contracts`, you'll need to flatten your solidity smart contract into one file. In this section, you will learn how to use the [Solidity Visual Developer](https://marketplace.visualstudio.com/items?itemName=tintinweb.solidity-visual-auditor) plugin on **VSCode** to flatten your smart contracts.
-### Step 01
+#### Step 01
- - On the left-sided panel, click on `Extensions` (or press `CTRL`+`SHIFT`+`X`);
- - Seach for `Solidity`;
- - Find `Solidity Visual Developer` and click in install.
+* On the left-sided panel, click on `Extensions` (or press `CTRL`+`SHIFT`+`X`);
+* Seach for `Solidity`;
+* Find `Solidity Visual Developer` and click in install.
-
-
-
+
-### Step 02
+#### Step 02
- - Go to `Explorer` on the left-side panel (or press `CTRL`+`SHIFT`+`E`);
- - Select the `.sol` file you want to flatten;
- - On the top of your visual code Editor window, you will see a list of new commands. Find `flatten` and click on it:
-
-
-
-
+* Go to `Explorer` on the left-side panel (or press `CTRL`+`SHIFT`+`E`);
+* Select the `.sol` file you want to flatten;
+* On the top of your visual code Editor window, you will see a list of new commands. Find `flatten` and click on it:
-### Step 03
+
- - Once you click on `flatten`, a new editor window will open to the right;
- - Press `CTRL`+`S` to Save As and name it `{name}-flat.sol` or whatever you feel is a good option to keep your folder organized;
- - Repeat the process to any `.sol` file that uses `import @openzeppelin/contracts`;
-
-
-
-
+#### Step 03
+
+* Once you click on `flatten`, a new editor window will open to the right;
+* Press `CTRL`+`S` to Save As and name it `{name}-flat.sol` or whatever you feel is a good option to keep your folder organized;
+* Repeat the process to any `.sol` file that uses `import @openzeppelin/contracts`;
+
+
By the end of this process, your folder should look like this:
-
-
-
+
-:rotating_light: **Remember to use the FLATTENED `.sol` files instead of the original file when verifying these contracts on the XDC Block Explorer.**
+:rotating\_light: **Remember to use the FLATTENED `.sol` files instead of the original file when verifying these contracts on the XDC Block Explorer.**
-# 🏗 Building a Front-End Application
+## 🏗 Building a Front-End Application
We prepared a project scaffold for the Egg Gacha. You can find the project folder [Here](https://github.com/menezesphill/egg-gacha-scaffold). Get started by cloning this dApp to your working directory:
-```sh
+```
git clone https://github.com/menezesphill/egg-gacha-scaffold.git
cd egg-gacha-scaffold
```
Once you have cloned your dApp scaffold, you can install all the necessary dependencies. You can either use `yarn` or `npm`, but in this example we use `npm`:
-```sh
+```
npm install
```
When npm finishes installing your dependencies, you can run the `start` script to see if everything is working:
-```sh
+```
npm run start
```
You should see the following React App served at `http://localhost:3000/`:
-
-
-
+
In this project folder, you will find a `contexts` folder with all methods necessary to connect to your `XDCPay` wallet. If you are not sure where this code is coming from or how to use it, please check the [XDCPay Integration Tutorial](https://github.com/menezesphill/docs/blob/main/how-to/XDCPay/Integration/how-to.md) before continuing.
We are ready to move to the next steps if you see the page above!
-## Creating Smart Contract Instances in React
+### Creating Smart Contract Instances in React
You will start by creating your smart contract instances in React. Create a `blockchain` folder locally, and a sub-folder called `contracts`:
-```sh
+```
mkdir -p ./src/blockchain/contracts
```
@@ -468,19 +457,17 @@ The only files you need to import from `Truffle` and `Hardhat` (whichever you de
Move or copy these three `.json` files to our recently created `./src/blockchain/contracts` folder. Our working directory should now look like this:
-
-
-
+
You'll need to install two new dependencies to your project, `web3-utils` and `web3-eth-contract`:
-```sh
+```
npm install web3-utils web3-eth-contract
```
-Create a generic contract handler in the `./src/blockchain/contracts` folder:
+Create a generic contract handler in the `./src/blockchain/contracts` folder:
-```sh
+```
touch ./src/blockchain/contracts/Contract.ts
```
@@ -548,7 +535,7 @@ export default Contract;
This way, you can your `EggToken`, `EggNFT` and `Faucet` contracts inherit from `Contract.ts`. You'll create three new files in the `./src/blockchain/contracts` folder:
-```sh
+```
touch ./src/blockchain/contracts/EggToken.ts
touch ./src/blockchain/contracts/EggNFT.ts
touch ./src/blockchain/contracts/Faucet.ts
@@ -556,7 +543,7 @@ touch ./src/blockchain/contracts/Faucet.ts
And each one of these files extends `Contract`:
-### EggToken.ts
+#### EggToken.ts
```jsx
// EggToken.ts
@@ -573,7 +560,7 @@ class EggToken extends Contract {
export default EggToken;
```
-### EggNFT.ts
+#### EggNFT.ts
```jsx
// EggNFT.ts
@@ -590,7 +577,7 @@ class EggNFT extends Contract {
export default EggNFT;
```
-### Faucet.ts
+#### Faucet.ts
```jsx
// Faucet.ts
@@ -609,21 +596,19 @@ export default Faucet;
At this point, your project folder should look like this:
-
-
-
+
-## Creating Smart Contract Constants File
+### Creating Smart Contract Constants File
-At this point, if you still haven't deployed the contracts, remember to check the scripts provided in [Migration script using Truffle](#migration-script-using-truffle) or [Migration script using Hardhat](#migration-script-using-hardhat). In this instance, we will show you how to deploy them using `Truffle`:
+At this point, if you still haven't deployed the contracts, remember to check the scripts provided in [Migration script using Truffle](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#migration-script-using-truffle) or [Migration script using Hardhat](how-to-create-a-react-app-to-interact-with-xrc20-and-xrc721-tokens.md#migration-script-using-hardhat). In this instance, we will show you how to deploy them using `Truffle`:
-```sh
+```
truffle migrate --network apothem
```
If migrations complete sucessfully, you can run `truffle networks` to get your contract addresses:
-```sh
+```
Network: apothem (id: 51)
EggNFT: 0xDfe0F690Bb0F03b62D0350cc34B8195EdDa85134
EggToken: 0x8544C3568Fd88BC256eef824C5232fB12fAd2F69
@@ -635,7 +620,7 @@ Network: xinfin (id: 50)
To keep your React dApp folder organized, you will create a `constants.ts` file with your deployment information:
-```sh
+```
touch ./src/blockchain/constants.ts
```
@@ -661,18 +646,17 @@ export const FaucetAddress = {
};
```
-## Creating Smart Contract Wrappers in React
-
+### Creating Smart Contract Wrappers in React
The next step is to create Wrappers, where you'll define what kind of methods you want to access on the blockchain. You will create one for each contract:
-```sh
+```
touch ./src/blockchain/EggTokenWrapper.ts
touch ./src/blockchain/EggNFTWrapper.ts
touch ./src/blockchain/FaucetWrapper.ts
```
-### EggTokenWrapper.ts
+#### EggTokenWrapper.ts
You won't need to use all methods nor access all variables available in `EggToken.sol`, so you will only create the `balanceOf()`, `approve()`, and `allowance()` methods in your `EggTokenWrapper.ts` file:
@@ -733,7 +717,7 @@ export default class EggTokenWrapper {
}
```
-### EggNFTWrapper.ts
+#### EggNFTWrapper.ts
In `EggNFTWrapper.ts`, you will declare your `buyEgg()` method, which is probably the most important method, and a few other methods to help you display your collection in the front-end application like:`balanceOf()`, `tokenOfOwnerByIndex()`, and `tokenURI()`:
@@ -800,7 +784,7 @@ export default class EggNFTWrapper {
}
```
-### FaucetWrapper.ts
+#### FaucetWrapper.ts
Our `FaucetWrapper.ts` is the simpliest of the three contracts. You should only care about the `claimTokens()` method in your dApp:
@@ -840,9 +824,9 @@ export default class Faucetrapper {
}
```
-## Creating a Blockchain Context Provider in React
+### Creating a Blockchain Context Provider in React
-You are almost there! Next, you'll want to create a `Blockchain Context` so that you can access our blockchain methods throughout our React app. Right now, it might sound a bit exhausting to go through all these files, but trust us, in a real-world application, you will be glad you have created such a nice-looking and well-sectioned React project.
+You are almost there! Next, you'll want to create a `Blockchain Context` so that you can access our blockchain methods throughout our React app. Right now, it might sound a bit exhausting to go through all these files, but trust us, in a real-world application, you will be glad you have created such a nice-looking and well-sectioned React project.
If you feel like grabbing a coffee, go ahead, I'll be here waiting for you...
@@ -850,7 +834,7 @@ If you feel like grabbing a coffee, go ahead, I'll be here waiting for you...
...and continuing, it is now time to create a `BlockchainProvider.tsx` into our `contexts` folder:
-```sh
+```
touch ./src/contexts/BlockchainProvider.tsx
```
@@ -937,7 +921,7 @@ export default BlockchainProvider;
This way, whenever your `account` address, `chainId`, or `web3` provider changes, all contracts are updated accordingly throughout your React App, and you are also capable of tracking your EGGS NFTs images to show on the front-end.
-## Integrating Blockchain Methods to DOM elements
+### Integrating Blockchain Methods to DOM elements
Now you'll need to update our `index.tsx` file in the `src` with your newly created provider. Your `index.tsx` should look like this:
@@ -978,7 +962,7 @@ root.render(
);
```
-### Updating `app.tsx` elements
+#### Updating `app.tsx` elements
Next, move to your main App file at `./src/app.tsx` and make some changes:
@@ -1233,66 +1217,66 @@ const App: React.FC = () => {
export default App;
```
-🎉 Contrats! If you got this far, you have created your first fully functional decentralized app on XDC!
+🎉 Contrats! If you got this far, you have created your first fully functional decentralized app on XDC!
If you are not sure if your code is correct or if you feel you missed something, you can check the [Egg Gacha Scaffold Completed repo](https://github.com/menezesphill/egg-gacha-scaffold-completed)
-# 💧 Setting up Faucet Contract
+## 💧 Setting up Faucet Contract
You are almost ready to run your dApp demo, but first you'll need to fund your `Faucet` contract with some `EGT tokens`:
Move to your smart contract development environment.
-### On Truffle
+#### On Truffle
You will begin by starting your development tool console:
-```sh
+```
truffle console --network apothem
```
Once the console opens, please instantiate your `EggToken` contract:
-```sh
+```
truffle(apothem)> let eggToken = await EggToken.deployed()
// Should log: undefined
```
Next, instantiate your `Faucet` contract:
-```sh
+```
truffle(apothem)> let faucet = await Faucet.deployed()
// Should log: undefined
```
You first need to approve `Faucet` to spend your EggTokens:
-```sh
+```
truffle(apothem)> let amount = web3.utils.toWei("40000", "ether")
truffle(apothem)> eggToken.approve(faucet.address, amount)
```
It should log a Transaction Receipt (or a rejection in case it fails). If it failed, try again with a lower value, otherwise go ahead and use the `depositToken()` method:
-```sh
+```
truffle(apothem)> faucet.depositToken(amount)
```
It should log a Transaction Receipt (or a rejection in case it fails). If it failed, check if you hold the amount of tokens you are trying to deposit.
-### On Hardhat
+#### On Hardhat
Using hardhat, you'll need to remember tour smart contract addresses. Fortunately, you can find the addresses in your dApp folder at `./src/blockchain/constants.ts`.
You can begin by starting your development tool console:
-```sh
+```
npx hardhat console --network apothem
```
Once the console opens, attach your `EggToken` contract:
-```sh
+```
> const EggToken = await ethers.getContractFactory("EggToken");
// Should log: undefined
> const eggTokenInstance = await EggToken.attach('0x8544C3568Fd88BC256eef824C5232fB12fAd2F69');
@@ -1301,7 +1285,7 @@ Once the console opens, attach your `EggToken` contract:
Next, attach your `Faucet` contract:
-```sh
+```
> const Faucet = await ethers.getContractFactory("Faucet");
// Should log: undefined
> const faucetInstance = await Faucet.attach('0x71e9774B1c70202f072326759B55c9c2a9C46E0b');
@@ -1310,24 +1294,24 @@ Next, attach your `Faucet` contract:
You'll need to approve `Faucet` to spend tour EggTokens:
-```sh
+```
> let amount = ethers.utils.parseUnits("40000", 18)
> await eggTokenInstance.approve(faucetInstance.address, amount)
```
Then, call the `depositToken()`
-```sh
+```
> await faucetInstance.depositToken(amount)
```
You are now ready for your first dApp demo!
-# 🔥 DApp Demo
+## 🔥 DApp Demo
Head to our front-end folder and run:
-```sh
+```
npm run start
```
diff --git a/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-foundry.md b/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-foundry.md
index 680f0a85..65e3b6d1 100644
--- a/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-foundry.md
+++ b/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-foundry.md
@@ -1,58 +1,63 @@
-# How to make a XRC-20 Royalty Token with Foundry.
-This tutorial’s purpose is to create an XRC-20 token with foundry that will return a royalty amount (of that XRC-20 token) to the original creator of the contract.
-
-# 🧭 Table of contents
+# How to Create and Deploy an XRC20 Token Using Foundry
-- [How to make a XRC-20 Royalty Token with Foundry.](#how-to-make-a-xrc-20-royalty-token-with-foundry)
-- [🧭 Table of contents](#-table-of-contents)
-- [📰 Overview](#-overview)
- - [What you will learn](#what-you-will-learn)
- - [What you will do](#what-you-will-do)
-- [The Tools We're Using](#the-tools-were-using)
-- [Set up Foundry](#set-up-foundry)
- - [Installing Foundry For MacOS / Linux:](#installing-foundry-for-macos--linux)
- - [Installing Foundry For Windows:](#installing-foundry-for-windows)
-- [environment SetUp](#environment-setup)
-- [Smart Contract Development](#smart-contract-development)
-- [Testing Our Smart Contract](#testing-our-smart-contract)
- - [Create your test contract](#create-your-test-contract)
-- [Deploying Our Smart Contract To The Blockchain](#deploying-our-smart-contract-to-the-blockchain)
- - [Deploying Our Contract](#deploying-our-contract)
-- [Veryfing Contracts on the Block Explorer](#veryfing-contracts-on-the-block-explorer)
+## How to make a XRC-20 Royalty Token with Foundry.
+This tutorial’s purpose is to create an XRC-20 token with foundry that will return a royalty amount (of that XRC-20 token) to the original creator of the contract.
-# 📰 Overview
+## 🧭 Table of contents
+
+* [How to make a XRC-20 Royalty Token with Foundry.](how-to-create-and-deploy-an-xrc20-token-using-foundry.md#how-to-make-a-xrc-20-royalty-token-with-foundry)
+* [🧭 Table of contents](how-to-create-and-deploy-an-xrc20-token-using-foundry.md#-table-of-contents)
+* [📰 Overview](how-to-create-and-deploy-an-xrc20-token-using-foundry.md#-overview)
+ * [What you will learn](how-to-create-and-deploy-an-xrc20-token-using-foundry.md#what-you-will-learn)
+ * [What you will do](how-to-create-and-deploy-an-xrc20-token-using-foundry.md#what-you-will-do)
+* [The Tools We're Using](how-to-create-and-deploy-an-xrc20-token-using-foundry.md#the-tools-were-using)
+* [Set up Foundry](how-to-create-and-deploy-an-xrc20-token-using-foundry.md#set-up-foundry)
+ * [Installing Foundry For MacOS / Linux:](how-to-create-and-deploy-an-xrc20-token-using-foundry.md#installing-foundry-for-macos--linux)
+ * [Installing Foundry For Windows:](how-to-create-and-deploy-an-xrc20-token-using-foundry.md#installing-foundry-for-windows)
+* [environment SetUp](how-to-create-and-deploy-an-xrc20-token-using-foundry.md#environment-setup)
+* [Smart Contract Development](how-to-create-and-deploy-an-xrc20-token-using-foundry.md#smart-contract-development)
+* [Testing Our Smart Contract](how-to-create-and-deploy-an-xrc20-token-using-foundry.md#testing-our-smart-contract)
+ * [Create your test contract](how-to-create-and-deploy-an-xrc20-token-using-foundry.md#create-your-test-contract)
+* [Deploying Our Smart Contract To The Blockchain](how-to-create-and-deploy-an-xrc20-token-using-foundry.md#deploying-our-smart-contract-to-the-blockchain)
+ * [Deploying Our Contract](how-to-create-and-deploy-an-xrc20-token-using-foundry.md#deploying-our-contract)
+* [Veryfing Contracts on the Block Explorer](how-to-create-and-deploy-an-xrc20-token-using-foundry.md#veryfing-contracts-on-the-block-explorer)
+
+## 📰 Overview

-
[Foundry](https://book.getfoundry.sh/) is a smart contract development toolchain.
Foundry manages your dependencies, compiles your project, runs tests, deploys, and lets you interact with the chain from the command-line and via Solidity scripts.
-### What you will learn
+#### What you will learn
+
In this tutorial, you will learn how to set up Foundry and use it to build, test and deploy a XRC20 Royalty Token on both the XDC Network mainnet and XDC Apothem testnet.
-### What you will do
-- Install and setup Foundry
-- Create an XRC20 Royalty token
-- Compile the Contract
-- Deploy the Contract
-- Interact with the XRC20 Royalty token
-- Check the deployment status on [XDC Mainnet](https://explorer.xinfin.network/) and [XDC Testnet](https://apothem.blocksscan.io/)
-
-# The Tools We're Using
-- [Foundry](https://book.getfoundry.sh/) : a fast Solidity development toolkit that enables developers to write their tests in Solidity.
-- [Solmate](https://github.com/Rari-Capital/solmate) : a library that contains gas-optimized contracts such as ERC20, ERC721, and more.
-- [Visual Studio Code](https://code.visualstudio.com/) : a source-code editor made by Microsoft with the Electron Framework, for Windows, Linux and macOS.
-- [XDC Testnet explorer](https://explorer.xinfin.network/)
-- [Testnet XDC Faucet](https://faucet.apothem.network/) : a faucet that gives 1000 XDC for test.
-- [XDCPay](https://chrome.google.com/webstore/detail/xdcpay/bocpokimicclpaiekenaeelehdjllofo) : is an extension for accessing XDC's XDPoS enabled distributed applications, or "Dapps" in your browser.
-
-# Set up Foundry
+#### What you will do
+
+* Install and setup Foundry
+* Create an XRC20 Royalty token
+* Compile the Contract
+* Deploy the Contract
+* Interact with the XRC20 Royalty token
+* Check the deployment status on [XDC Mainnet](https://explorer.xinfin.network/) and [XDC Testnet](https://apothem.blocksscan.io/)
+
+## The Tools We're Using
+
+* [Foundry](https://book.getfoundry.sh/) : a fast Solidity development toolkit that enables developers to write their tests in Solidity.
+* [Solmate](https://github.com/Rari-Capital/solmate) : a library that contains gas-optimized contracts such as ERC20, ERC721, and more.
+* [Visual Studio Code](https://code.visualstudio.com/) : a source-code editor made by Microsoft with the Electron Framework, for Windows, Linux and macOS.
+* [XDC Testnet explorer](https://explorer.xinfin.network/)
+* [Testnet XDC Faucet](https://faucet.apothem.network/) : a faucet that gives 1000 XDC for test.
+* [XDCPay](https://chrome.google.com/webstore/detail/xdcpay/bocpokimicclpaiekenaeelehdjllofo) : is an extension for accessing XDC's XDPoS enabled distributed applications, or "Dapps" in your browser.
+
+## Set up Foundry
+
Before we can start writing some code, we need to set up our environment. We're going to be writing our contracts and testing them in Foundry.
-### Installing Foundry For MacOS / Linux:
+#### Installing Foundry For MacOS / Linux:
Open-up terminal and type in the command:
@@ -61,77 +66,95 @@ curl -L https://foundry.paradigm.xyz | bash
```
Afterward type:
+
```bash
foundryup
```
+
Foundry should now be installed and ready to go!
-### Installing Foundry For Windows:
+#### Installing Foundry For Windows:
If using Windows, you need to install Foundry from the source. First, install [Rust](https://rustup.rs/) with the [official documentation](https://book.getfoundry.sh/getting-started/installation).
Then, open the command prompt and type in the command:
+
```bash
cargo install --git https://github.com/foundry-rs/foundry foundry-cli anvil --bins --locked
```
+
To update from source, run the same command again.
-# environment SetUp
+## environment SetUp
Now that we've installed Foundry, it's time to set up our folder where we will write our smart contract. From the same terminal window that you installed Foundry, type the following commands:
1. Make our folder where will we initialize our project. Then navigate into that folder with the following commands:
+
```bash
mkdir XRC20_Royalty && cd XRC20_Royalty
```
-2. Initialize our Foundry project within our XRC20_Royalty folder:
+
+1. Initialize our Foundry project within our XRC20\_Royalty folder:
+
```bash
forge init
```
-3. Install Solmate into our Foundry project:
+
+1. Install Solmate into our Foundry project:
+
```bash
forge install rari-capital/solmate
```
-4. Create a remappings.txt file for the Solmate library we just added:
+
+1. Create a remappings.txt file for the Solmate library we just added:
+
```bash
touch remappings.txt
```
-5. Open up your project in your IDE. For this tutorial, we’ll be using VSCode with this Solidity plugin:
+
+1. Open up your project in your IDE. For this tutorial, we’ll be using VSCode with this Solidity plugin:
+
```bash
code .
```
+
Here’s what our IDE looks like.

+1. Add these lines to remappings.txt so we can easily call the Solmate library in our contract:
-6. Add these lines to remappings.txt so we can easily call the Solmate library in our contract:
```bash
solmate/=lib/solmate/src/
forge-std=lib/forge-std/src/
```
+
Now that our environment and libraries are set up, we'll move into developing our smart contract!
-# Smart Contract Development
+## Smart Contract Development
We will make a contract that passes tokens to the original contract creator whenever a token is transferred between wallets!
1. In your IDE, navigate to `src/Counter.sol` and rename the file to `RoyaltyToken.sol`.
-
2. Import the Solmate ERC20 library in `RoyaltyToken.sol` and change the name of the contract. Under `pragma solidity ^0.8.14;`, add the following lines of code:
+
```bash
import { ERC20 } from "solmate/tokens/ERC20.sol";
contract RoyaltyToken is ERC20 {}
```
-3. Add in our state variables for the royalties. In the contract, add an address `royaltyAddress` variable and uint256 `royaltyFeePercentage` variable:
+
+1. Add in our state variables for the royalties. In the contract, add an address `royaltyAddress` variable and uint256 `royaltyFeePercentage` variable:
+
```bash
contract RoyaltyToken is ERC20 {
address public royaltyAddress;
uint256 public royaltyFeePercentage;
}
```
-4. Make a constructor for the token. A constructor is what creates our token from the imported Solmate template.
+
+1. Make a constructor for the token. A constructor is what creates our token from the imported Solmate template.
Add the following variables to the constructor:
@@ -139,15 +162,12 @@ Add the following variables to the constructor:
2. `string memory _token`
3. `uint8 _decimals`
4. `uint256 _royaltyFeePercentage`
-5. `uint256 _initialSupply`
-Directly after we’ve added these variables and closed the `()`, add `ERC20(_name, _symbol, _decimals)`.
+5. `uint256 _initialSupply` Directly after we’ve added these variables and closed the `()`, add `ERC20(_name, _symbol, _decimals)`.
After that add brackets `{}` and inside the brackets set the following variables:
-Set `royaltyAddress` variable as the wallet address of the creator of the contract: `royaltyAddress = msg.sender;`
-The `RoyaltyFeePercentage` as the constructor variable: `royaltyFeePercentage = _royaltyFeePercentage;`
-Mint the tokens to the creator of the contract and pass in the `_initialSupply` variable: `_mint(msg.sender, _initialSupply);`
-Our constructor should now look like the following:
+Set `royaltyAddress` variable as the wallet address of the creator of the contract: `royaltyAddress = msg.sender;` The `RoyaltyFeePercentage` as the constructor variable: `royaltyFeePercentage = _royaltyFeePercentage;` Mint the tokens to the creator of the contract and pass in the `_initialSupply` variable: `_mint(msg.sender, _initialSupply);` Our constructor should now look like the following:
+
```bash
contract RoyaltyToken is ERC20 {
address public royaltyAddress;
@@ -166,7 +186,9 @@ contract RoyaltyToken is ERC20 {
}
}
```
-5. Next, override the transfer function.
+
+1. Next, override the transfer function.
+
```bash
function transfer(address to, uint256 amount) public virtual returns (bool) {
balanceOf[msg.sender] -= amount;
@@ -181,7 +203,7 @@ function transfer(address to, uint256 amount) public virtual returns (bool) {
return true;
}
-```
+```
Our contract now looks like this:
@@ -221,16 +243,15 @@ contract RoyaltyToken is ERC20 {
}
}
```
+
Add override after virtual in the function declaration:
+`function transfer(address to, uint256 amount) public virtual override returns (bool) { ... }` Inside of the `transfer` function, create a uint256 called `royaltyAmount` and set it equal to the amount in the function parameters multiplied by the `royaltyFeePercentage` divided by `100`. This calculates the royalty amount that we will be sending to our `royaltyAddress`.
-`function transfer(address to, uint256 amount) public virtual override returns (bool) {
-...
-} `
-Inside of the `transfer` function, create a uint256 called `royaltyAmount` and set it equal to the amount in the function parameters multiplied by the `royaltyFeePercentage` divided by `100`. This calculates the royalty amount that we will be sending to our `royaltyAddress`.
```bash
uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
```
+
```bash
function transfer(address to, uint256 amount) public virtual returns (bool) {
uint256 royaltyAmount = amount * royaltyFeePercentage / 100;
@@ -247,6 +268,7 @@ function transfer(address to, uint256 amount) public virtual returns (bool) {
return true;
}
```
+
In the `unchecked {}` for the `balanceOf[to]`, subtract the amount by the `royaltyAmount` and add an additional `balanceOf[royaltyAddress]` where we add the `royaltyAmount`:
```bash
@@ -268,6 +290,7 @@ function transfer(address to, uint256 amount) public virtual returns (bool) {
return true;
}
```
+
Add an additional emit Transfer where we send the royaltyAddress the royaltyAmount. Additionally, subtract the original emit Transfer amount by the royaltyAmount:
```bash
@@ -293,7 +316,8 @@ function transfer(address to, uint256 amount) public virtual override returns (b
return true;
}
```
-6. Our contract is now finished! In total it should look like this:
+
+1. Our contract is now finished! In total it should look like this:
```bash
// SPDX-License-Identifier: UNLICENSED
@@ -349,21 +373,17 @@ contract RoyaltyToken is ERC20 {
}
```
-# Testing Our Smart Contract
+## Testing Our Smart Contract
+
Thanks to Foundry, we can test our new `RoyaltyToken.sol` contract in Solidity!
Set up your test contract
1. In your IDE, head to `test/Counter.t.sol` and rename the file to `RoyaltyToken.t.sol`.
-
2. Delete everything in the original body of `RoyaltyToken.t.sol`.
-
3. Add our solidity version to the top: `pragma solidity ^0.8.14;`.
-
4. Import the RoyaltyToken from `royaltyToken.sol`. Add `import {RoyaltyToken} from "src//RoyaltyToken.sol";` to the top of your contract.
-
5. Import forge testing tools: `import "forge-std/Test.sol";`.
-
6. Make a new contract called `RoyaltyTokenTest` and set it to a `Test`. Our contract should look like this.
```bash
@@ -375,7 +395,9 @@ import "forge-std/Test.sol";
contract RoyaltyTokenTest is Test {}
```
-### Create your test contract
+
+#### Create your test contract
+
1. Create your `RoyaltyToken`, `RoyaltyFeePercentage`, and `InitialSupply` arguments. For this test, we will be using `2%` for the fee and `10,000` initial tokens:
```bash
@@ -391,7 +413,9 @@ contract RoyaltyTokenTest is Test {
uint256 public initialSupply = 10 ** 4;
}
```
-2. Create a `setUp()` function that constructs our `RoyaltyToken`.
+
+1. Create a `setUp()` function that constructs our `RoyaltyToken`.
+
```bash
pragma solidity ^0.8.14;
@@ -410,7 +434,9 @@ contract RoyaltyTokenTest is Test {
}
```
-3. Create a `testTransfer()` function that makes two dummy addresses and transfers funds between them. We will transfer 1,000 of the 10,000 tokens we created to an address. We're then going to check whether the address received 980 of those 1,000 tokens and whether our original contract address received the other 20. Afterward, we will initiate a transfer of 100 tokens between the newly created address and another wallet. We'll then check whether all 3 of the wallets have the correct amounts.
+
+1. Create a `testTransfer()` function that makes two dummy addresses and transfers funds between them. We will transfer 1,000 of the 10,000 tokens we created to an address. We're then going to check whether the address received 980 of those 1,000 tokens and whether our original contract address received the other 20. Afterward, we will initiate a transfer of 100 tokens between the newly created address and another wallet. We'll then check whether all 3 of the wallets have the correct amounts.
+
```bash
function testTransfer() public {
address alice = address(1);
@@ -429,7 +455,9 @@ function testTransfer() public {
assertEq(token.balanceOf(address(this)), 9022);
}
```
-4. Our entire contract should look like this:
+
+1. Our entire contract should look like this:
+
```bash
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.14;
@@ -466,78 +494,74 @@ contract RoyaltyTokenTest is Test {
}
}
```
-5. Now, let’s compile our contract. Open up that terminal window we used earlier and type the command `forge build` .
+
+1. Now, let’s compile our contract. Open up that terminal window we used earlier and type the command `forge build` .
+
```bash
forge build
```
-`Compiling...
-[⠰] Compiling 19 files with 0.8.14
-[⠒] Solc 0.8.14 finished in 2.00s
-Compiler run successful`
+`Compiling... [⠰] Compiling 19 files with 0.8.14 [⠒] Solc 0.8.14 finished in 2.00s Compiler run successful`
Our smart contract is finished and is correctly compiling! Now let's test our smart contract to make sure it's actually doing what we want it to do.
-6. Open up terminal and run `forge test`. This runs our tests and helps us understand whether or not they passed.
+1. Open up terminal and run `forge test`. This runs our tests and helps us understand whether or not they passed.
+
```bash
forge test
```
-`Compiling...
-No files changed, compilation skipped
+\`Compiling... No files changed, compilation skipped
-Running 1 test for test/RoyaltyToken.t.sol:RoyaltyTokenTest
-[PASS] testTransfer() (gas: 78242)
-Test result: ok. 1 passed; 0 failed; finished in 1.45ms`
+Running 1 test for test/RoyaltyToken.t.sol:RoyaltyTokenTest \[PASS] testTransfer() (gas: 78242) Test result: ok. 1 passed; 0 failed; finished in 1.45ms\`
If all goes well, you've just successfully made a smart contract in foundry, overrode the original transfer function, and ran some successful tests! Now, it's time to deploy the contract.
-# Deploying Our Smart Contract To The Blockchain
+## Deploying Our Smart Contract To The Blockchain
+
It's time for us to deploy our smart contract to the blockchain.
1. Open up terminal and run `cast wallet new` - Create a new random keypair.
-```bash
+
+```bash
cast wallet new
```
-`Successfully created new keypair.
-Address: 0x80B75825D86a005453A08cD1a6Bd44C24d73A41d
-Private Key: 0x4159ae5d34bb48367f9773c48de0e0effb2082681a69cd95f4e613246720af24`
+`Successfully created new keypair. Address: 0x80B75825D86a005453A08cD1a6Bd44C24d73A41d Private Key: 0x4159ae5d34bb48367f9773c48de0e0effb2082681a69cd95f4e613246720af24`
-2. Now Copy the address and go to XDC faucet for [test XDC](https://faucet.apothem.network/), And replace `0x` by xdc.Click on request 1000 XDC.
+1. Now Copy the address and go to XDC faucet for [test XDC](https://faucet.apothem.network/), And replace `0x` by xdc.Click on request 1000 XDC.

We've got everything we need to deploy our contract to the blockchain now.
-### Deploying Our Contract
+#### Deploying Our Contract
+
Head back to your terminal window to complete deployment.
-1. Open up the terminal and type the following command, replacing [PASTE YOUR PRIVATE KEY HERE]
+1. Open up the terminal and type the following command, replacing \[PASTE YOUR PRIVATE KEY HERE]
+
```bash
forge create --rpc-url https://erpc.apothem.network --private-key [PASTE YOUR PRIVATE KEY HERE] src/RoyaltyToken.sol:RoyaltyToken --constructor-args "RoyaltyToken" "ROYT" 18 2 10000000000000000000000 --legacy
```
-`Compiling...
-No files changed, compilation skipped
-Deployer: 0x80B75825D86a005453A08cD1a6Bd44C24d73A41d
-Deployed to: 0x27f4D21150640df0856fF6CB5d57eB4447CC59AD
-Transaction hash: 0x89f0edbf4755e93b8d25857e5a0fa0f7cae414cefac42e6ec9cb02930a932d41`
-
+`Compiling... No files changed, compilation skipped Deployer: 0x80B75825D86a005453A08cD1a6Bd44C24d73A41d Deployed to: 0x27f4D21150640df0856fF6CB5d57eB4447CC59AD Transaction hash: 0x89f0edbf4755e93b8d25857e5a0fa0f7cae414cefac42e6ec9cb02930a932d41`
We can now see that our contract is deployed to the blockchain. If I copy the address in Deployed to, we can view the contract on [explorer](https://apothem.blocksscan.io/address/xdc27f4D21150640df0856fF6CB5d57eB4447CC59AD#transactions).

-# Veryfing Contracts on the Block Explorer
+## 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 [Apothem Block Explorer](https://apothem.blocksscan.io/address/xdc27f4D21150640df0856fF6CB5d57eB4447CC59AD#transactions).
-1. Flatten our smart contract, Open up the terminal and type the following command
+
+1. Flatten our smart contract, Open up the terminal and type the following command
+
```bash
forge flatten --output src/Contract.flattened.sol src/RoyaltyToken.sol
```
-`Flattened file written at src/Contract.flattened.sol`
-Now open the `Contract.flattened.sol` file and copy all source code, go to the [block explorer](https://apothem.blocksscan.io/address/xdc27f4D21150640df0856fF6CB5d57eB4447CC59AD#transactions) and click on Verify and Publish.
-
+
+`Flattened file written at src/Contract.flattened.sol` Now open the `Contract.flattened.sol` file and copy all source code, go to the [block explorer](https://apothem.blocksscan.io/address/xdc27f4D21150640df0856fF6CB5d57eB4447CC59AD#transactions) and click on Verify and Publish. 

@@ -547,54 +571,8 @@ Now open the `Contract.flattened.sol` file and copy all source code, go to the [
If everything is correctly filled out, your contract page on the block explorer should display a new tab called Contract.
----
-For more information about XDC Network, Please Visit [XDC Network Documention](https://docs.xdc.org/).
-For more information about Foundry, Please Visit [Foundry Book](https://book.getfoundry.sh/).
-XDC Network [Disocrd](https://discord.gg/RBRx2HvbMr).
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+***
+For more information about XDC Network, Please Visit [XDC Network Documention](https://docs.xdc.org/).\
+For more information about Foundry, Please Visit [Foundry Book](https://book.getfoundry.sh/).\
+XDC Network [Disocrd](https://discord.gg/RBRx2HvbMr).\
diff --git a/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md b/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md
index af6f44d8..59a238c6 100644
--- a/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md
+++ b/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md
@@ -1,7 +1,6 @@
---
id: xrc20-token-hardhat-typescript
title: XRC20 using TypeScript and Hardhat
-description: "Use TypeScript and Hardhat to deploy an XRC20 Token."
keywords:
- docs
- apothem
@@ -9,83 +8,82 @@ keywords:
- XRC20
- hardhat
- typescript
+description: Use TypeScript and Hardhat to deploy an XRC20 Token.
---
-# 🧭 Table of contents
-
-- [🧭 Table of contents](#-table-of-contents)
-- [📰 Overview](#-overview)
- - [What you will learn](#what-you-will-learn)
- - [What you will do](#what-you-will-do)
- - [📰 About XRC20 Tokens](#-about-xrc20-tokens)
-- [⚒ Starting a new Hardhat Project](#-starting-a-new-hardhat-project)
- - [⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat](#-configuring-xdc-mainnet-and-apothem-testnet-on-hardhat)
- - [⚒ Adding Testnet XDC to Development Wallet](#-adding-testnet-xdc-to-development-wallet)
-- [💵 Writing your first XRC20 Token](#-writing-our-first-xrc20-token)
- - [💵 Constants](#-constants)
- - [💵 Events](#-events)
- - [💵 Methods](#-methods)
- - [💵 Compiling and Deploying](#-compiling-and-deploying)
-- [🔍 Veryfing Contracts on the Block Explorer](#-veryfing-contracts-on-the-block-explorer)
- - [🔍 Interacting with your contract on the Block Explorer](#-interacting-with-your-contract-on-the-block-explorer)
-
-# 📰 Overview
-
-
-
-
+# How to Create and Deploy an XRC20 Token Using Hardhat and TypeScript
+
+## 🧭 Table of contents
+
+* [🧭 Table of contents](how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md#-table-of-contents)
+* [📰 Overview](how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md#-overview)
+ * [What you will learn](how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md#what-you-will-learn)
+ * [What you will do](how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md#what-you-will-do)
+ * [📰 About XRC20 Tokens](how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md#-about-xrc20-tokens)
+* [⚒ Starting a new Hardhat Project](how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md#-starting-a-new-hardhat-project)
+ * [⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat](how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md#-configuring-xdc-mainnet-and-apothem-testnet-on-hardhat)
+ * [⚒ Adding Testnet XDC to Development Wallet](how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md#-adding-testnet-xdc-to-development-wallet)
+* [💵 Writing your first XRC20 Token](how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md#-writing-our-first-xrc20-token)
+ * [💵 Constants](how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md#-constants)
+ * [💵 Events](how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md#-events)
+ * [💵 Methods](how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md#-methods)
+ * [💵 Compiling and Deploying](how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md#-compiling-and-deploying)
+* [🔍 Veryfing Contracts on the Block Explorer](how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md#-veryfing-contracts-on-the-block-explorer)
+ * [🔍 Interacting with your contract on the Block Explorer](how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md#-interacting-with-your-contract-on-the-block-explorer)
+
+## 📰 Overview
+
+
[Hardhat](https://hardhat.org/) is a development environment to compile, deploy, test, and debug your Ethereum software. Get Solidity stack traces & console.log.
[TypeScript](https://www.typescriptlang.org/) is a strongly typed programming language that builds on TypeScript.
-### What you will learn
+#### What you will learn
In this tutorial, you will learn how to set up Hardhat 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
+#### What you will do
-- Install and setup Hardhat
-- Create an XRC20 token
-- Compile the XRC20 token
-- Deploy the XRC20 token
-- Interact with the XRC20 token
-- Check the deployment status on [xinfin.network](https://xinfin.network/#stats)
+* Install and setup Hardhat
+* Create an XRC20 token
+* Compile the XRC20 token
+* Deploy the XRC20 token
+* Interact with the XRC20 token
+* Check the deployment status on [xinfin.network](https://xinfin.network/#stats)
-## 📰 About XRC20 Tokens
+### 📰 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:
-- `totalSupply()`
-- `balanceOf(address account)`
-- `allowance(address owner, address spender)`
-- `transfer(address recipient, uint amount)`
-- `approve(address spender, uint amount)`
-- `transferFrom(address sender, address recipient, uint amount)`
+* `totalSupply()`
+* `balanceOf(address account)`
+* `allowance(address owner, address spender)`
+* `transfer(address recipient, uint amount)`
+* `approve(address spender, uint amount)`
+* `transferFrom(address sender, address recipient, uint amount)`
These are the minimum required methods that allow an asset on the XDC Network to be called an XRC20 token. Also, a 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)`
+* `Approval(address indexed tokenOwner, address indexed spender, uint tokens)`
+* `Transfer(address indexed from, address indexed to, uint tokens)`
Events come in handy in the exhaustive labor of indexing state changes, and they are essential for 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.
In addition, a few contract constants that are public that are also very important to have are:
-- `name`
-- `symbol`
-- `decimals`
+* `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.
-# ⚒ Starting a new Hardhat Project
+## ⚒ Starting a new Hardhat Project
There are a few technical requirements before we start. Please install the following:
-- [Node.js v8+ LTS and npm](https://nodejs.org/en/) (comes with Node)
-- [Git](https://git-scm.com/)
+* [Node.js v8+ LTS and npm](https://nodejs.org/en/) (comes with Node)
+* [Git](https://git-scm.com/)
Next, set up your folder. As we are creating a project called `XRC20`, create a new `XRC20` folder by running the following on terminal:
@@ -109,14 +107,11 @@ Ok to proceed? (y)
The following message should log on your console:
-
-
-
-
+
Press `↓` and `ENTER` to get started with a new TypeScript Hardhat Project. You will then be presented with the following options:
-```sh
+```
✔ Hardhat project root: · /Users/cr/XRC20
✔ Do you want to add a .gitignore? (Y/n) · y
✔ Help us improve Hardhat with anonymous crash reports & basic usage data? (Y/n) · n
@@ -126,17 +121,15 @@ Press `↓` and `ENTER` to get started with a new TypeScript Hardhat Project. Yo
The standard Hardhat project comes with a pre-created `Lock.sol` contract and `deploy.ts` script. You should clean up your working environment before moving forward:
-```sh
+```
rm -f ./contracts/Lock.sol ./scripts/deploy.ts ./test/Lock.ts
```
Your folder files will look like this:
-
-
-
+
-## ⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat
+### ⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat
In order to get started deploying new contracts on XDC Mainnet and/or Apothem, we need to install a new dependency called `dotenv` that will be used in the `hardhat.config.ts` file:
@@ -157,6 +150,7 @@ XINFIN_NETWORK_URL=https://erpc.xinfin.network
APOTHEM_NETWORK_URL=https://erpc.apothem.network
PRIVATE_KEY=202e3c9d30bbeca38d6578659919d4c3dc989ae18c16756690877fdc4dfa607f
```
+
🚨 **Do not use the Private Key in the example above in production or you can risk losing your assets!** 🚨
Finally, we can configure the `hardhat.config.ts` file for both Apothem and XinFin Networks by writting:
@@ -185,16 +179,17 @@ const config: HardhatUserConfig = {
export default config;
```
-## ⚒ Adding Testnet XDC to Development Wallet
+### ⚒ Adding Testnet XDC to Development Wallet
Now check your Signer's address on Hardhat by accessing the Hardhat console:
-```sh
+```
npx hardhat console --network xinfin
```
+
If you get an error that hardhat is not installed locally and are running on a Windows OS, you will need to execute:
-```sh
+```
npm install --save-dev @nomicfoundation/hardhat-toolbox
```
@@ -213,21 +208,18 @@ This account is on the Ethereum standard format starting with `0x`, but you can
With this account in hand, we can head to the [Apothem Faucet](https://faucet.apothem.network/) and claim some TXDC for development purposes:
-
-
-
+
-# 💵 Writing our first XRC20 Token
+## 💵 Writing our first XRC20 Token
-The source code for the XRC20 token used in this tutorial is available here: [XRC20 Contract Folder](./XRC20/contracts/XRC20.sol). But we will address all `Events`, `Methods`, and `Constants` mentioned in the section [📰 About XRC20 Tokens](#-about-xrc20-tokens).
+The source code for the XRC20 token used in this tutorial is available here: [XRC20 Contract Folder](XRC20/contracts/XRC20.sol). But we will address all `Events`, `Methods`, and `Constants` mentioned in the section [📰 About XRC20 Tokens](how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md#-about-xrc20-tokens).
Start by creating the `XRC20.sol` file:
-```sh
+```
touch ./contracts/XRC20.sol
```
-
Write the shell of your smart contract as shown here:
```solidity
@@ -244,7 +236,7 @@ contract XRC20Token {
}
```
-## 💵 Constants
+### 💵 Constants
Inside `contract XRC20Token`, you will 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 will also have two mapping variables, `balances` and `allowances`, which are key/value variables that maps user balances and approved spending allowances to other users:
@@ -273,9 +265,9 @@ contract XRC20Token {
}
```
-## 💵 Events
+### 💵 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, but Solidity has a _maximum of 3 indexed variable_ limitation for events. Here is how you'll write both `Approval` and `Transfer` events:
+As mentioned in [📰 About XRC20 Tokens](how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md#-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, but Solidity has a _maximum of 3 indexed variable_ limitation for events. Here is how you'll write both `Approval` and `Transfer` events:
```solidity
// SPDX-License-Identifier: MIT
@@ -308,9 +300,9 @@ contract XRC20Token {
}
```
-## 💵 Methods
+### 💵 Methods
-You'll 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 used only once, when the contract is deployed, where we can attach information such as the token name, decimals and/or initial token supply:
+You'll need to create the six methods mentioned in [📰 About XRC20 Tokens](how-to-create-and-deploy-an-xrc20-token-using-hardhat-and-typescript.md#-about-xrc20-tokens) (`totalSupply`, `balanceOf`, `allowance`, `transfer`, `approve` and `transferFrom`) and a `constructor` that is a function used only once, when the contract is deployed, where we can attach information such as the token name, decimals and/or initial token supply:
```solidity
// SPDX-License-Identifier: MIT
@@ -387,17 +379,17 @@ contract XRC20Token {
Now, you have implemented everything necessary to make your token compliant with the XRC20 Standard. Of course, there are more features that you 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
+### 💵 Compiling and Deploying
Now you can compile your `XRC20.sol` by running:
-```sh
+```
npx hardhat compile
```
If everything is correctly configured and there are no errors, you will see the following message on your console:
-```sh
+```
Generating typings for: 1 artifacts in dir: typechain-types for target: ethers-v5
Successfully generated 6 typings!
Compiled 1 Solidity file successfully
@@ -405,13 +397,11 @@ Compiled 1 Solidity file successfully
Your folder should look like this:
-
-
-
+
In order to deploy your newly-compiled contract artifacts to the blockchain, you'll need to create a deployment script into the script folder:
-```sh
+```
touch ./scripts/deploy.ts
```
@@ -440,80 +430,69 @@ main().catch((error) => {
If the deployment script has no errors, you can go ahead and run the following command for deployment of the XDC Mainnet:
-```sh
+```
npx hardhat run scripts/deploy.ts --network xinfin
```
Or this command, for deployment of the XDC Apothem Testnet:
-```sh
+```
npx hardhat run scripts/deploy.ts --network apothem
```
+
In either case, you must 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:
-```sh
+```
Token Successfully Deployed!
Token address: 0xbC5bA2B6e2f74EC1e8e5A310a42F65D185691Af2
```
-# 🔍 Veryfing Contracts on the Block Explorer
+## 🔍 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/).
Now grab the `XRC20.sol` address from the previous step. This address is in the Ethereum standard, but you can simply swap the `0x` prefix for `xdc`. After this prefix swap, search for our newly deployed contract on [XinFin Block Explorer](https://explorer.xinfin.network/):
-
-
-
+
Click on the `Verify And Publish` option.
You will be redirected to the contract verification page where you'll need to fill out:
-- Contract Name: XRC20Token
-- Compiler: Check your `hardhat-config.ts` file for Compiler Version
-- Contract Code: Just paste everything from your `XRC20.sol` file
+* Contract Name: _XRC20Token_
+* Compiler: _Check your_ `hardhat-config.ts` _file for Compiler Version_
+* Contract Code: _Just paste everything from your_ `XRC20.sol` _file_
Once everything is filled out, press Submit!
-
-
-
+
If everything is correctly filled out, your contract page on the block explorer should display a new tab called `Contract`:
-
-
-
+
-## 🔍 Interacting with your contract 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.
Now head to the `Contract` tab on the explorer, choose `Write Contract`, and click in `Connect to Web3` to connect your XDCPay wallet.
-
-
-
+
Try transfering `500 MTK` tokens that you have just created to a new wallet `xdc0431d52fe37f3839895018272dfa3ba189fce07e`. Fill out the `recipient` field with the new wallet address, and fill out the `amout` field with `500 * 10 ^ 18`. Remember that your token has 18 decimals. When you write numbers to the blockchain you must to account for the decimals as the virtual machine does not understand floating numbers the way humans do:
-
-
-
+
After clicking in `Write`, you'll need to confirm the transaction on the XDCPay wallet:
-
-
-
+
You can check your successful transaction on the [Block Explorer!](https://explorer.xinfin.network/txs/0xa365a7edea3af9ed22c6dffb2f24987f1941f21dbd4d9bbb13b11022439de96a#overview)
----
+***
-For more information about Hardhat, Please Visit [Hardhat Documentation](https://hardhat.org/tutorial).
-For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).
-Resources used during the deployment of the XRC20 Token can be found at [XRC20 Contract Folder](./XRC20).
+For more information about Hardhat, Please Visit [Hardhat Documentation](https://hardhat.org/tutorial).\
+For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).\
+Resources used during the deployment of the XRC20 Token can be found at [XRC20 Contract Folder](XRC20/).
diff --git a/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-hardhat.md b/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-hardhat.md
index 62e43e11..e35a81c9 100644
--- a/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-hardhat.md
+++ b/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-hardhat.md
@@ -1,86 +1,86 @@
---
id: xrc20-token-hardhat
title: XRC20 using Hardhat
-description: "Use Hardhat to deploy an XRC20 Token."
keywords:
- docs
- apothem
- token
- XRC20
- hardhat
+description: Use Hardhat to deploy an XRC20 Token.
---
-# 🧭 Table of contents
-
-- [🧭 Table of contents](#-table-of-contents)
-- [📰 Overview](#-overview)
- - [What you will learn](#what-you-will-learn)
- - [What you will do](#what-you-will-do)
- - [📰 About XRC20 Tokens](#-about-xrc20-tokens)
-- [⚒ Starting a new Hardhat Project](#-starting-a-new-hardhat-project)
- - [⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat](#-configuring-xdc-mainnet-and-apothem-testnet-on-hardhat)
- - [⚒ Adding Testnet XDC to Development Wallet](#-adding-testnet-xdc-to-development-wallet)
-- [💵 Writing your first XRC20 Token](#-writing-our-first-xrc20-token)
- - [💵 Constants](#-constants)
- - [💵 Events](#-events)
- - [💵 Methods](#-methods)
- - [💵 Compiling and Deploying](#-compiling-and-deploying)
-- [🔍 Veryfing Contracts on the Block Explorer](#-veryfing-contracts-on-the-block-explorer)
- - [🔍 Interacting with your contract on the Block Explorer](#-interacting-with-your-contract-on-the-block-explorer)
-
-# 📰 Overview
-
-
-
-
+# How To Create and Deploy an XRC20 Token Using Hardhat
+
+## 🧭 Table of contents
+
+* [🧭 Table of contents](how-to-create-and-deploy-an-xrc20-token-using-hardhat.md#-table-of-contents)
+* [📰 Overview](how-to-create-and-deploy-an-xrc20-token-using-hardhat.md#-overview)
+ * [What you will learn](how-to-create-and-deploy-an-xrc20-token-using-hardhat.md#what-you-will-learn)
+ * [What you will do](how-to-create-and-deploy-an-xrc20-token-using-hardhat.md#what-you-will-do)
+ * [📰 About XRC20 Tokens](how-to-create-and-deploy-an-xrc20-token-using-hardhat.md#-about-xrc20-tokens)
+* [⚒ Starting a new Hardhat Project](how-to-create-and-deploy-an-xrc20-token-using-hardhat.md#-starting-a-new-hardhat-project)
+ * [⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat](how-to-create-and-deploy-an-xrc20-token-using-hardhat.md#-configuring-xdc-mainnet-and-apothem-testnet-on-hardhat)
+ * [⚒ Adding Testnet XDC to Development Wallet](how-to-create-and-deploy-an-xrc20-token-using-hardhat.md#-adding-testnet-xdc-to-development-wallet)
+* [💵 Writing your first XRC20 Token](how-to-create-and-deploy-an-xrc20-token-using-hardhat.md#-writing-our-first-xrc20-token)
+ * [💵 Constants](how-to-create-and-deploy-an-xrc20-token-using-hardhat.md#-constants)
+ * [💵 Events](how-to-create-and-deploy-an-xrc20-token-using-hardhat.md#-events)
+ * [💵 Methods](how-to-create-and-deploy-an-xrc20-token-using-hardhat.md#-methods)
+ * [💵 Compiling and Deploying](how-to-create-and-deploy-an-xrc20-token-using-hardhat.md#-compiling-and-deploying)
+* [🔍 Veryfing Contracts on the Block Explorer](how-to-create-and-deploy-an-xrc20-token-using-hardhat.md#-veryfing-contracts-on-the-block-explorer)
+ * [🔍 Interacting with your contract on the Block Explorer](how-to-create-and-deploy-an-xrc20-token-using-hardhat.md#-interacting-with-your-contract-on-the-block-explorer)
+
+## 📰 Overview
+
+
[Hardhat](https://hardhat.org/) is a development environment to compile, deploy, test, and debug your Ethereum software. Get Solidity stack traces & console.log.
-### What you will learn
+#### What you will learn
+
In this tutorial, you will learn how to set up Hardhat 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 Hardhat
-- Create an XRC20 token
-- Compile the XRC20 token
-- Deploy the XRC20 token
-- Interact with the XRC20 token
-- Check the deployment status on [xinfin.network](https://xinfin.network/#stats)
+#### What you will do
+
+* Install and setup Hardhat
+* Create an XRC20 token
+* Compile the XRC20 token
+* Deploy the XRC20 token
+* Interact with the XRC20 token
+* Check the deployment status on [xinfin.network](https://xinfin.network/#stats)
-## 📰 About XRC20 Tokens
+### 📰 About XRC20 Tokens
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)`
-- `allowance(address owner, address spender)`
-- `transfer(address recipient, uint amount)`
-- `approve(address spender, uint amount)`
-- `transferFrom(address sender, address recipient, uint amount)`
+* `totalSupply()`
+* `balanceOf(address account)`
+* `allowance(address owner, address spender)`
+* `transfer(address recipient, uint amount)`
+* `approve(address spender, uint amount)`
+* `transferFrom(address sender, address recipient, uint amount)`
These are the minimum required methods that allow an asset on the XDC Network to be called an XRC20 token. Also, a 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)`
-
+* `Approval(address indexed tokenOwner, address indexed spender, uint tokens)`
+* `Transfer(address indexed from, address indexed to, uint tokens)`
+
Events come in handy in the exhaustive process 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.
Several contract constants that are public that are also very important to have are:
-- `name`
-- `symbol`
-- `decimals`
+* `name`
+* `symbol`
+* `decimals`
Without these public constants, it would be impossible to label tokens on block explorers, for example. In this tutorial, you will deploy a XRC20 token that have all the `Methods`, `Events` and `Constants` mentioned above.
-# ⚒ Starting a new Hardhat Project
+## ⚒ Starting a new Hardhat Project
There are a few technical requirements before we start. Please install the following:
-- [Node.js v8+ LTS and npm](https://nodejs.org/en/) (comes with Node)
-- [Git](https://git-scm.com/)
+* [Node.js v8+ LTS and npm](https://nodejs.org/en/) (comes with Node)
+* [Git](https://git-scm.com/)
You can start by setting up your folder. As we are creating a project called `XRC20`, you should create a new `XRC20` folder by running the following on terminal:
@@ -104,14 +104,11 @@ Ok to proceed? (y)
The following message should log on your console:
-
-
-
-
+
Press `ENTER` to get started with a new JavaScript Hardhat Project. Then you will be presented with the following options:
-```sh
+```
? Hardhat project root: ‣ /home/taurinos/xdc_comm/docs/how-to/XRC20/Hardhat/XRC20
// Press ENTER or y
@@ -124,17 +121,15 @@ Press `ENTER` to get started with a new JavaScript Hardhat Project. Then you wil
The standard Hardhat project comes with a pre-created `Lock.sol` contract and `deploy.js` script. YOu should clean up your working environment before moving forward:
-```sh
+```
rm -rf ./contracts/Lock.sol ./scripts/deploy.js ./test/Lock.js
```
Your folder files will look like this:
-
-
-
+
-## ⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat
+### ⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat
In order to get started deploying new contracts on XDC Mainnet and/or Apothem, you'll need to install a new dependency called `dotenv` that will be used in the `hardhat.config.js` file:
@@ -155,6 +150,7 @@ XINFIN_NETWORK_URL=https://erpc.xinfin.network
APOTHEM_NETWORK_URL=https://erpc.apothem.network
PRIVATE_KEY=202e3c9d30bbeca38d6578659919d4c3dc989ae18c16756690877fdc4dfa607f
```
+
🚨 **Do not use the Private Key in the example above in production or you can risk losing your assets!** 🚨
Finally, you can configure the `hardhat.config.js` file for both Apothem and XDC Networks by writting:
@@ -178,16 +174,17 @@ module.exports = {
};
```
-## ⚒ Adding Testnet XDC to Development Wallet
+### ⚒ Adding Testnet XDC to Development Wallet
Check your Signer's Address on Hardhat by accessing the Hardhat console:
-```sh
+```
npx hardhat console --network xinfin
```
+
If you get an error that hardhat is not installed locally and are running on a Windows OS, you will need to execute:
-```sh
+```
npm install --save-dev @nomicfoundation/hardhat-toolbox
```
@@ -206,21 +203,18 @@ This account is on the Ethereum standard format starting with `0x`, but you can
With this account in hand, we can head to the [Apothem Faucet](https://faucet.apothem.network/) and claim some TXDC for development purposes:
-
-
-
+
-# 💵 Writing our first XRC20 Token
+## 💵 Writing our first XRC20 Token
-The source code for the XRC20 token used in this tutorial is available here: [XRC20 Contract Folder](./../../how-to/XRC20/Hardhat/XRC20/contracts/XRC20.sol). But we will address all `Events`, `Methods` and `Constants` mentioned in the section [📰 About XRC20 Tokens](#-about-xrc20-tokens).
+The source code for the XRC20 token used in this tutorial is available here: [XRC20 Contract Folder](../../how-to/XRC20/Hardhat/XRC20/contracts/XRC20.sol). But we will address all `Events`, `Methods` and `Constants` mentioned in the section [📰 About XRC20 Tokens](how-to-create-and-deploy-an-xrc20-token-using-hardhat.md#-about-xrc20-tokens).
Start by creating the `XRC20.sol` file:
-```sh
+```
touch ./contracts/XRC20.sol
```
-
Next, write the shell of our smart contract by writing:
```solidity
@@ -237,7 +231,7 @@ contract XRC20Token {
}
```
-## 💵 Constants
+### 💵 Constants
Inside our `contract XRC20Token`, you will instantiate `name`, `symbol` and `decimals` as public variables, a private `_totalSupply` that will be used on our `totalSupply()` method later on. You'll also instantiate two mapping variables, `balances` and `allowances`, that are key/value variables that maps user balances and approved spending allowances to other users:
@@ -266,9 +260,9 @@ contract XRC20Token {
}
```
-## 💵 Events
+### 💵 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 that are tied to an on-chain event, but Solidity has a _maximum of 3 indexed variable_ limitation for events. You can write both `Approval` and `Transfer` events:
+As mentioned in [📰 About XRC20 Tokens](how-to-create-and-deploy-an-xrc20-token-using-hardhat.md#-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 that are tied to an on-chain event, but Solidity has a _maximum of 3 indexed variable_ limitation for events. You can write both `Approval` and `Transfer` events:
```solidity
// SPDX-License-Identifier: MIT
@@ -301,9 +295,9 @@ contract XRC20Token {
}
```
-## 💵 Methods
+### 💵 Methods
-You'll 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`. This is a function called only once when the contract is deployed, where you can attach information such as the token name, decimals and/or initial token supply:
+You'll need to create the six methods mentioned in [📰 About XRC20 Tokens](how-to-create-and-deploy-an-xrc20-token-using-hardhat.md#-about-xrc20-tokens) (`totalSupply`, `balanceOf`, `allowance`, `transfer`, `approve` and `transferFrom`) as well as a `constructor`. This is a function called only once when the contract is deployed, where you can attach information such as the token name, decimals and/or initial token supply:
```solidity
// SPDX-License-Identifier: MIT
@@ -380,30 +374,28 @@ contract XRC20Token {
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
+### 💵 Compiling and Deploying
You can now compile your `XRC20.sol` by running:
-```sh
+```
npx hardhat compile
```
If everything is correctly configured and there is no errors, you should see the following message on your console:
-```sh
+```
Downloading compiler 0.8.16
Compiled 1 Solidity files successfully
```
And your folder should look like this:
-
-
-
+
In order to deploy our newly compiled contract artifacts to the blockchain, you'll need to create a deployment script into the script folder:
-```sh
+```
touch ./scripts/deploy.js
```
@@ -431,81 +423,69 @@ main()
If the deployment script have no errors, you can go ahead and run the command for deployment of the XDC Mainnet:
-```sh
+```
npx hardhat run scripts/deploy.js --network xinfin
```
Or this command for deployment on the XDC Apothem Testnet:
-```sh
+```
npx hardhat run scripts/deploy.js --network apothem
```
+
In either case, you 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:
-```sh
+```
Token Successfully Deployed!
Token address: 0xbC5bA2B6e2f74EC1e8e5A310a42F65D185691Af2
```
-# 🔍 Veryfing Contracts on the Block Explorer
+## 🔍 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/).
Simply grab the `XRC20.sol` address from the previous step: 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/):
-
-
-
+
Click on the `Verify And Publish` option.
You will be redirected to the contract verification page where we need to fill out:
-- Contract Name: XRC20Token
-- Compiler: Check your `hardhat-config.js` file for Compiler Version
-- Contract Code: Just paste everything from your `XRC20.sol` file
+* Contract Name: _XRC20Token_
+* Compiler: _Check your_ `hardhat-config.js` _file for Compiler Version_
+* Contract Code: _Just paste everything from your_ `XRC20.sol` _file_
Once everything is filled out, press Submit!
-
-
-
+
If everything is correctly filled out, your contract page on the block explorer should display a new tab called `Contract`:
-
-
-
+
-## 🔍 Interacting with your contract 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.
Go to the `Contract` tab on the explorer, choose `Write Contract` and click in `Connect to Web3` to connect your XDCPay wallet.
-
-
-
+
Next, try transfering `500 MTK` tokens that we have just created to a new wallet `xdc0431d52fe37f3839895018272dfa3ba189fce07e`. Fill out the `recipient` field with the new wallet address, and fill out the `amout` field with `500 * 10 ^ 18`. Remember that your token have 18 decimals, and we have to account for the decimals because the Virtual Machine does not understand floating numbers like we humans do:
-
-
-
+
After clicking in `Write`, you'll need to confirm the transaction on the XDCPay wallet:
-
-
-
+
You can check our successful transaction on the [Block Explorer!](https://explorer.xinfin.network/txs/0xa365a7edea3af9ed22c6dffb2f24987f1941f21dbd4d9bbb13b11022439de96a#overview)
----
-
-For more information about Hardhat, Please Visit [Hardhat Documentation](https://hardhat.org/tutorial).
-For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).
-Resources used during the deployment of the XRC20 Token can be found at [XRC20 Contract Folder](./XRC20).
+***
+For more information about Hardhat, Please Visit [Hardhat Documentation](https://hardhat.org/tutorial).\
+For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).\
+Resources used during the deployment of the XRC20 Token can be found at [XRC20 Contract Folder](XRC20/).
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 24c23177..cb598a1f 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
@@ -1,82 +1,85 @@
---
id: xrc20-token-truffle
title: XRC20 using Truffle
-description: "Use Truffle to deploy an XRC20 Token."
keywords:
- docs
- apothem
- token
- XRC20
- truffle
+description: Use Truffle to deploy an XRC20 Token.
---
-# 🧭 Table of contents
-
-- [🧭 Table of contents](#-table-of-contents)
-- [📰 Overview](#-overview)
- - [What you will learn](#what-you-will-learn)
- - [What you will do](#what-you-will-do)
- - [📰 About XRC20 Tokens](#-about-xrc20-tokens)
-- [🚀 Setting up the development environment](#-setting-up-the-development-environment)
- - [⚒ 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 your first XRC20 Token](#-writing-our-first-xrc20-token)
- - [💵 Constants](#-constants)
- - [💵 Events](#-events)
- - [💵 Methods](#-methods)
- - [💵 Compiling and Deploying](#-compiling-and-deploying)
-- [🔍 Veryfing Contracts on the Block Explorer](#-veryfing-contracts-on-the-block-explorer)
- - [🔍 Interacting with your contract on the Block Explorer](#-interacting-with-your-contract-on-the-block-explorer)
-
-# 📰 Overview
+# How To Create and Deploy an XRC20 Token Using Truffle
+
+## 🧭 Table of contents
+
+* [🧭 Table of contents](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#-table-of-contents)
+* [📰 Overview](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#-overview)
+ * [What you will learn](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#what-you-will-learn)
+ * [What you will do](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#what-you-will-do)
+ * [📰 About XRC20 Tokens](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#-about-xrc20-tokens)
+* [🚀 Setting up the development environment](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#-setting-up-the-development-environment)
+ * [⚒ Starting a new Truffle Project](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#-starting-a-new-truffle-project)
+ * [⚒ Configuring XDC Mainnet and Apothem Testnet on Truffle](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#-configuring-xdc-mainnet-and-apothem-testnet-on-truffle)
+ * [⚒ Adding Testnet XDC to Development Wallet](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#-adding-testnet-xdc-to-development-wallet)
+* [💵 Writing your first XRC20 Token](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#-writing-our-first-xrc20-token)
+ * [💵 Constants](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#-constants)
+ * [💵 Events](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#-events)
+ * [💵 Methods](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#-methods)
+ * [💵 Compiling and Deploying](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#-compiling-and-deploying)
+* [🔍 Veryfing Contracts on the Block Explorer](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#-veryfing-contracts-on-the-block-explorer)
+ * [🔍 Interacting with your contract on the Block Explorer](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#-interacting-with-your-contract-on-the-block-explorer)
+
+## 📰 Overview
+
[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
+#### 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.
-### What you will do
-- Install and setup Truffle
-- Create an XRC20 token
-- Compile the XRC20 token
-- Deploy the XRC20 token
-- Interact with the XRC20 token
-- Check the deployment status on [xinfin.network](https://xinfin.network/#stats)
+#### What you will do
+
+* Install and setup Truffle
+* Create an XRC20 token
+* Compile the XRC20 token
+* Deploy the XRC20 token
+* Interact with the XRC20 token
+* Check the deployment status on [xinfin.network](https://xinfin.network/#stats)
-## 📰 About XRC20 Tokens
+### 📰 About XRC20 Tokens
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)`
-- `allowance(address owner, address spender)`
-- `transfer(address recipient, uint amount)`
-- `approve(address spender, uint amount)`
-- `transferFrom(address sender, address recipient, uint amount)`
+* `totalSupply()`
+* `balanceOf(address account)`
+* `allowance(address owner, address spender)`
+* `transfer(address recipient, uint amount)`
+* `approve(address spender, uint amount)`
+* `transferFrom(address sender, address recipient, uint amount)`
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)`
-
+* `Approval(address indexed tokenOwner, address indexed spender, uint tokens)`
+* `Transfer(address indexed from, address indexed to, uint tokens)`
+
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.
Several contract constants are public and very important to have:
-- `name`
-- `symbol`
-- `decimals`
+* `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.
-# 🚀 Setting up the development environment
+## 🚀 Setting up the development environment
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/)
+* [Node.js v8+ LTS and npm](https://nodejs.org/en/) (comes with Node)
+* [Git](https://git-scm.com/)
Once you have installed those, you only need one command to install Truffle:
@@ -84,7 +87,7 @@ Once you have installed those, you only need one command to install Truffle:
npm install -g truffle
```
-To verify that Truffle is installed properly, type **`truffle version`** on a terminal. You should see something like:
+To verify that Truffle is installed properly, type **`truffle version`** on a terminal. You should see something like:
```bash
Truffle v5.5.27 (core: 5.5.27)
@@ -96,7 +99,7 @@ Web3.js v1.7.4
If you see an error instead, make sure that your npm modules are added to your path.
-## ⚒ Starting a new Truffle Project
+### ⚒ Starting a new Truffle Project
Start by setting up our folder. As we are creating a project called `XRC20`, create a new `XRC20` folder by running on terminal:
@@ -123,31 +126,29 @@ http://trufflesuite.com/docs
Your folder files will look like this:
-
-
-
-
+
-## ⚒ Configuring XDC Mainnet and Apothem Testnet on Truffle
+### ⚒ Configuring XDC Mainnet and Apothem Testnet on Truffle
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 will likely 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
```
Initialize your package manager on your folder and install the required dependencies:
-```sh
+```
yarn init -y
yarn add @truffle/hdwallet-provider dotenv
```
You will also need a **24-Word Mnemonic Phrase**. To configure your wallet, create a new `.env` file and write your mnemonic by running:
-```sh
+```
touch .env
echo MNEMONIC=arm derive cupboard decade course garlic journey blast tribe describe curve obey >> .env
```
@@ -158,7 +159,6 @@ Remember to change the **24-Word Mnemonic** above for your own mnemonic. The con
MNEMONIC=arm derive cupboard decade course garlic journey blast tribe describe curve obey
```
-
🚨 **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!** 🚨
Finally, you can configure the `truffle-config.js` file for both Apothem and XinFin Networks by writting:
@@ -202,17 +202,17 @@ module.exports = {
};
```
-## ⚒ Adding Testnet XDC to Development Wallet
+### ⚒ Adding Testnet XDC to Development Wallet
It is possible to list all XDC addresses bound to your mnemonic on truffle by accessing the truffle console:
-```sh
+```
truffle console --network xinfin
```
Once the truffle console CLI opens, you can run:
-```sh
+```
truffle(xinfin)> accounts
```
@@ -237,17 +237,15 @@ These accounts are on the Ethereum standard format starting with `0x`, but we ca
With this account, you can head to the [Apothem Faucet](https://faucet.apothem.network/) and claim some TXDC for development purposes:
-
-
-
+
-# 💵 Writing our first XRC20 Token
+## 💵 Writing our first XRC20 Token
-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).
+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](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#-about-xrc20-tokens).
You can start by creating the `XRC20.sol` file:
-```sh
+```
touch ./contracts/XRC20.sol
```
@@ -267,7 +265,7 @@ contract XRC20Token {
}
```
-## 💵 Constants
+### 💵 Constants
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:
@@ -296,9 +294,9 @@ contract XRC20Token {
}
```
-## 💵 Events
+### 💵 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:
+As mentioned in [📰 About XRC20 Tokens](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#-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
@@ -331,9 +329,9 @@ contract XRC20Token {
}
```
-## 💵 Methods
+### 💵 Methods
-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:
+We need to create the six methods mentioned in [📰 About XRC20 Tokens](how-to-create-and-deploy-an-xrc20-token-using-truffle.md#-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
@@ -410,17 +408,17 @@ contract XRC20Token {
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
+### 💵 Compiling and Deploying
We can compile our `MyToken.sol` by running:
-```sh
+```
truffle compile
```
If everything is correctly configured and there are no errors, you will see the following message on your console:
-```sh
+```
Compiling your contracts...
===========================
> Compiling ./contracts/MyToken.sol
@@ -431,13 +429,11 @@ Compiling your contracts...
Your folder should look like this:
-
-
-
+
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
```
@@ -458,13 +454,13 @@ module.exports = function (deployer) {
If the migration script have no errors, you can run the following command for deployment on the XDC mainnet:
-```sh
+```
truffle migrate --network xinfin
```
Or the following commard for deployment on the XDC Apothem Testnet:
-```sh
+```
truffle migrate --network apothem
```
@@ -472,7 +468,7 @@ In either case, you'll need to have enough funds to pay for gas fees on the addr
If the deployment is sucessful, the console will log the following message after migrations complete processing:
-```sh
+```
1_token_migration.js
====================
@@ -500,19 +496,19 @@ Summary
> Final cost: 0.0002804765 ETH
```
-# 🔍 Veryfing Contracts on the Block Explorer
+## 🔍 Veryfing Contracts on the Block Explorer
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/).
You can check the address that your contract is deployed to by running:
-```sh
+```
truffle networks
```
If you have a contract deployed, the console should log something like this:
-```sh
+```
Network: apothem (id: 51)
No contracts deployed.
@@ -522,57 +518,44 @@ Network: xinfin (id: 50)
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/):
-
-
-
+
And click in the `Verify And Publish` Option.
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
-- Contract Code: Just paste everything from your `MyToken.sol` file
+* Contract Name: _XRC20Token_
+* Compiler: _Check your_ `truffle-config.js` _file for Compiler Version_
+* Contract Code: _Just paste everything from your_ `MyToken.sol` _file_
Once everything is filled out, press Submit!
-
-
-
+
If everything is correctly filled out, your contract page on the block explorer will display a new tab called `Contract`:
-
-
-
+
-## 🔍 Interacting with your contract on the Block Explorer
+### 🔍 Interacting with your contract on the Block Explorer
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.
-
-
-
+
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:
-
-
-
+
After clicking `Write`, you need to confirm the transaction on the XDCPay wallet:
-
-
-
+
You can check your successful transaction on the [Block Explorer!](https://explorer.xinfin.network/txs/0xa365a7edea3af9ed22c6dffb2f24987f1941f21dbd4d9bbb13b11022439de96a#overview)
----
-
-For more information about Truffle Suite, Please Visit [Truffle Suite Documentation](https://trufflesuite.com/docs/truffle/).
-For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).
-Resources used during the deployment of the XRC20 Token can be found at [XRC20 Contract Folder](./XRC20).
+***
+For more information about Truffle Suite, Please Visit [Truffle Suite Documentation](https://trufflesuite.com/docs/truffle/).\
+For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).\
+Resources used during the deployment of the XRC20 Token can be found at [XRC20 Contract Folder](XRC20/).
diff --git a/learn/how-to-articles/how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md b/learn/how-to-articles/how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md
index f0580304..ddf6bcdd 100644
--- a/learn/how-to-articles/how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md
+++ b/learn/how-to-articles/how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md
@@ -1,87 +1,89 @@
---
id: xrc721-token-hardhat
title: XRC721 using Hardhat
-description: "Use Hardhat to deploy an XRC721 Token."
keywords:
- docs
- apothem
- token
- XRC721
- hardhat
+description: Use Hardhat to deploy an XRC721 Token.
---
-# 🧭 Table of contents
-
-- [🧭 Table of contents](#-table-of-contents)
-- [📰 Overview](#-overview)
- - [What you will learn](#what-you-will-learn)
- - [What you will do](#what-you-will-do)
- - [📰 About XRC721 Tokens](#-about-xrc721-tokens)
-- [⚒ Starting a new Hardhat Project](#-starting-a-new-hardhat-project)
- - [⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat](#-configuring-xdc-mainnet-and-apothem-testnet-on-hardhat)
- - [⚒ Adding Testnet XDC to Development Wallet](#-adding-testnet-xdc-to-development-wallet)
-- [💵 Writing your first XRC721 Token](#-writing-our-first-xrc721-token)
- - [💵 Events](#-events)
- - [💵 Methods](#-methods)
- - [💵 XRC165](#-xrc165)
- - [💵 Enabling minting](#-enabling-minting)
- - [💵 Compiling and Deploying](#-compiling-and-deploying)
-- [🔍 Veryfing Contracts on the Block Explorer](#-veryfing-contracts-on-the-block-explorer)
-
-# 📰 Overview
-
-
-
-
+# How to Create and Deploy an XRC721 NFT Using Hardhat
+
+## 🧭 Table of contents
+
+* [🧭 Table of contents](how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md#-table-of-contents)
+* [📰 Overview](how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md#-overview)
+ * [What you will learn](how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md#what-you-will-learn)
+ * [What you will do](how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md#what-you-will-do)
+ * [📰 About XRC721 Tokens](how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md#-about-xrc721-tokens)
+* [⚒ Starting a new Hardhat Project](how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md#-starting-a-new-hardhat-project)
+ * [⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat](how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md#-configuring-xdc-mainnet-and-apothem-testnet-on-hardhat)
+ * [⚒ Adding Testnet XDC to Development Wallet](how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md#-adding-testnet-xdc-to-development-wallet)
+* [💵 Writing your first XRC721 Token](how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md#-writing-our-first-xrc721-token)
+ * [💵 Events](how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md#-events)
+ * [💵 Methods](how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md#-methods)
+ * [💵 XRC165](how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md#-xrc165)
+ * [💵 Enabling minting](how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md#-enabling-minting)
+ * [💵 Compiling and Deploying](how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md#-compiling-and-deploying)
+* [🔍 Veryfing Contracts on the Block Explorer](how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md#-veryfing-contracts-on-the-block-explorer)
+
+## 📰 Overview
+
+
[Hardhat](https://hardhat.org/) is a development environment to compile, deploy, test, and debug your Ethereum software. Get Solidity stack traces & console.log.
-### What you will learn
+#### What you will learn
+
In this tutorial, you will learn how to set up Hardhat and use it to build, test, and deploy a XRC721 token on both the XDC Network mainnet and XDC Apothem testnet.
-### What you will do
-- Install and setup Hardhat
-- Create an XRC721 token
-- Compile the XRC721 token
-- Deploy the XRC721 token
-- Interact with the XRC721 token
-- Check the deployment status on [xinfin.network](https://xinfin.network/#stats)
+#### What you will do
+
+* Install and setup Hardhat
+* Create an XRC721 token
+* Compile the XRC721 token
+* Deploy the XRC721 token
+* Interact with the XRC721 token
+* Check the deployment status on [xinfin.network](https://xinfin.network/#stats)
-## 📰 About XRC721 Tokens
+### 📰 About XRC721 Tokens
XRC721 is an open standard that defines an interface for non-fungible tokens on XDC blockchain:
-- `balanceOf(address _owner) external view returns (uint256)`
-- `ownerOf(uint256 _tokenId) external view returns (address)`
-- `safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable`
-- `safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable`
-- `transferFrom(address _from, address _to, uint256 _tokenId) external payable`
-- `approve(address _approved, uint256 _tokenId) external payable`
-- `setApprovalForAll(address _operator, bool _approved) external`
-- `getApproved(uint256 _tokenId) external view returns (address)`
-- `isApprovedForAll(address _owner, address _operator) external view returns (bool)`
+* `balanceOf(address _owner) external view returns (uint256)`
+* `ownerOf(uint256 _tokenId) external view returns (address)`
+* `safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable`
+* `safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable`
+* `transferFrom(address _from, address _to, uint256 _tokenId) external payable`
+* `approve(address _approved, uint256 _tokenId) external payable`
+* `setApprovalForAll(address _operator, bool _approved) external`
+* `getApproved(uint256 _tokenId) external view returns (address)`
+* `isApprovedForAll(address _owner, address _operator) external view returns (bool)`
These are the minimum required methods that allow an asset on the XDC network to be called an XRC721 token. Also, a XRC721 token must be able to emit the following `Events` on the blockchain:
-- `Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId)`
-- `Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId)`
-- `ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved)`
+* `Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId)`
+* `Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId)`
+* `ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved)`
Events are helpers that come in handy in the exhaustive process of indexing state changes, and they are essential for 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.
-XRC721 also includes **optional** metadata parameters:
+XRC721 also includes **optional** metadata parameters:
-- `name`
-- `symbol`
+* `name`
+* `symbol`
This allows your smart contract to be interrogated for its name and for details about the assets that your NFTs represent.
-# ⚒ Starting a new Hardhat Project
+## ⚒ Starting a new Hardhat Project
There are a few technical requirements before we start. Please install the following:
-- [Node.js v8+ LTS and npm](https://nodejs.org/en/) (comes with Node)
-- [Git](https://git-scm.com/)
+* [Node.js v8+ LTS and npm](https://nodejs.org/en/) (comes with Node)
+* [Git](https://git-scm.com/)
Start by setting up tour folder. As we are creating a project called `XRC721`, create a new `XRC721` folder by running the following on terminal:
@@ -105,14 +107,11 @@ Ok to proceed? (y)
The following message should log on your console:
-
-
-
-
+
Press `ENTER` to get started with a new JavaScript Hardhat Project. Then you will be presented with the following options:
-```sh
+```
? Hardhat project root: ‣ /home/taurinos/xdc_comm/docs/how-to/XRC721/Hardhat/XRC721
// Press ENTER or y
@@ -125,17 +124,15 @@ Press `ENTER` to get started with a new JavaScript Hardhat Project. Then you wil
The standard Hardhat project comes with a pre-created `Lock.sol` contract and `deploy.js` script. It's best to clean up your working environment before moving forward:
-```sh
+```
rm -rf ./contracts/Lock.sol ./scripts/deploy.js ./test/Lock.js
```
Your folder files will look like this:
-
-
-
+
-## ⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat
+### ⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat
In order to get started deploying new contracts on XDC Mainnet and/or Apothem, you'll need to install a new dependency called `dotenv` that will be used in the `hardhat.config.js` file:
@@ -156,6 +153,7 @@ XINFIN_NETWORK_URL=https://erpc.xinfin.network
APOTHEM_NETWORK_URL=https://erpc.apothem.network
PRIVATE_KEY=202e3c9d30bbeca38d6578659919d4c3dc989ae18c16756690877fdc4dfa607f
```
+
🚨 **Do not use the Private Key in the example above or you can risk losing your assets!** 🚨
Finally, you can configure the `hardhat.config.js` file for both Apothem and XinFin Networks by writing:
@@ -179,16 +177,17 @@ module.exports = {
};
```
-## ⚒ Adding Testnet XDC to Development Wallet
+### ⚒ Adding Testnet XDC to Development Wallet
You should check your Signer's Address on Hardhat by accessing the Hardhat console:
-```sh
+```
npx hardhat console --network xinfin
```
+
If you get an error that Hardhat is not installed locally, and you are using a Windows OS, you will need to execute:
-```sh
+```
npm install --save-dev @nomicfoundation/hardhat-toolbox
```
@@ -207,22 +206,21 @@ This account is on the Ethereum standard format starting with `0x`, but we can s
With this account in hand, you can head to the [Apothem Faucet](https://faucet.apothem.network/) and claim some TXDC for development purposes:
-
-
-
+
-# 💵 Writing our first XRC721 Token
+## 💵 Writing our first XRC721 Token
-The source code for the XRC721 Token used in this tutorial is available here: [XRC721 Contract Folder](./XRC721/contracts/XRC721.sol). But we will address all `Events`, `Methods` and `Constants` mentioned in the section [📰 About XRC721 Tokens](#-about-xrc721-tokens).
+The source code for the XRC721 Token used in this tutorial is available here: [XRC721 Contract Folder](XRC721/contracts/XRC721.sol). But we will address all `Events`, `Methods` and `Constants` mentioned in the section [📰 About XRC721 Tokens](how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md#-about-xrc721-tokens).
Start by creating the `XRC721.sol` file:
-```sh
+```
touch ./contracts/XRC721.sol
```
You will have to use OpenZeppelin contracts, so please make sure it is installed using the following command:
-```sh
+
+```
npm install @openzeppelin/contracts
```
@@ -246,9 +244,9 @@ contract XRC721 is ERC721 {
Thanks to OpenZeppelin, we don't have to implement all the code ourself. It's still a good excerize to go through the basic parts of XRC721 contract as explained below
-## 💵 Events
+### 💵 Events
-As mentioned in [📰 About XRC721 Tokens](#-about-xrc721-tokens), events are an important part of a smart contract logic. Events have `indexed` 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 Solidity has a _maximum of 3 indexed variable_ limitation for events. XRC721 has three basic events: `Transfer`, `Approval` and `ApprovalForAll`.
+As mentioned in [📰 About XRC721 Tokens](how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md#-about-xrc721-tokens), events are an important part of a smart contract logic. Events have `indexed` 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 Solidity has a _maximum of 3 indexed variable_ limitation for events. XRC721 has three basic events: `Transfer`, `Approval` and `ApprovalForAll`.
```solidity
interface XRC721 {
@@ -269,9 +267,9 @@ interface XRC721 {
}
```
-## 💵 Methods
+### 💵 Methods
-You must create the six methods mentioned in [📰 About XRC721 Tokens](#-about-xrc721-tokens) (`ownerOf`, `balanceOf`, `safeTransferFrom`, `transferFrom`, `approve`, `setApprovalForAll`, `isApprovedForAll` and `getApproved`) and a `constructor`. This function is only called once, when the contract is deployed, where it contains information such as the token name, decimals and/or initial token supply:
+You must create the six methods mentioned in [📰 About XRC721 Tokens](how-to-create-and-deploy-an-xrc721-nft-using-hardhat.md#-about-xrc721-tokens) (`ownerOf`, `balanceOf`, `safeTransferFrom`, `transferFrom`, `approve`, `setApprovalForAll`, `isApprovedForAll` and `getApproved`) and a `constructor`. This function is only called once, when the contract is deployed, where it contains information such as the token name, decimals and/or initial token supply:
```solidity
// SPDX-License-Identifier: MIT
@@ -395,7 +393,7 @@ interface XRC721 {
}
```
-## 💵 XRC165
+### 💵 XRC165
We didn't mention it before, but XRC721 also requires implimentation of a XRC165 standard. Thanks to OpenZeppelin we don't have to implement it, but it is really simple. There is only one method, `supportsInterface`, and it goes as follows:
@@ -420,7 +418,7 @@ interface IXRC165 {
}
```
-## 💵 Enabling minting
+### 💵 Enabling minting
Now that you have a XRC721 contract, how can you mint an NFT with it? With the `mintToken` method, that's how! Each time `mintToken` is called, it will create new unique token assign to `tokenOwner`.
@@ -452,24 +450,24 @@ contract XRC721 is ERC721 {
}
```
-## 💵 Compiling and Deploying
+### 💵 Compiling and Deploying
You can now compile your `XRC721.sol` by running:
-```sh
+```
npx hardhat compile
```
If everything is correctly configured and there are no errors, you should see the following message on your console:
-```sh
+```
Downloading compiler 0.8.16
Compiled 1 Solidity files successfully
```
In order to deploy our newly compiled contract artifacts to the blockchain, we need to create a deployment script into the script folder:
-```sh
+```
touch ./scripts/deploy.js
```
@@ -503,13 +501,13 @@ main()
If the deployment script have no errors, you can run the following command for deployment on the XDC mainnet:
-```sh
+```
npx hardhat run scripts/deploy.js --network xinfin
```
Or this command, for deployment on the XDC Apothem Testnet:
-```sh
+```
npx hardhat run scripts/deploy.js --network apothem
```
@@ -517,48 +515,39 @@ In either case, you need to have enough funds to pay for gas fees on the address
If the deployment is successful, the console will log the following message after migrations complete processing:
-```sh
+```
Token Successfully Deployed!
Token address: 0xbC5bA2B6e2f74EC1e8e5A310a42F65D185691Af2
```
Find out how your freshly minted NFT looks on [Apothem Block Explorer](https://explorer.apothem.network/)
-
-
-
+ 
-# 🔍 Veryfing Contracts on the Block Explorer
+## 🔍 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/).
Simply grab the `XRC721.sol` address from the previous step: 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/):
-
-
-
+
Click in the `Verify And Publish` Option.
You will be redirected to the contract verification page where you will need to fill out:
-- Contract Name: XRC721
-- Compiler: Check your `hardhat-config.js` file for Compiler Version
-- Contract Code: Just paste everything from your `XRC721.sol` file
+* Contract Name: _XRC721_
+* Compiler: _Check your_ `hardhat-config.js` _file for Compiler Version_
+* Contract Code: _Just paste everything from your_ `XRC721.sol` _file_
Once everything is filled out, press Submit!
-
-
-
+
If everything is correctly filled out, your contract page on the block explorer will display a new tab called `Contract`:
-
-
-
-
-For more information about Hardhat, Please Visit [Hardhat Documentation](https://hardhat.org/tutorial).
-For more information about the XDC Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).
-Resources used during the deployment of the XRC721 Token can be found at [XRC721 Contract Folder](./XRC721).
+
+For more information about Hardhat, Please Visit [Hardhat Documentation](https://hardhat.org/tutorial).\
+For more information about the XDC Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).\
+Resources used during the deployment of the XRC721 Token can be found at [XRC721 Contract Folder](XRC721/).
diff --git a/learn/how-to-articles/how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-truffle.md b/learn/how-to-articles/how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-truffle.md
index 301b6447..a9975f93 100644
--- a/learn/how-to-articles/how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-truffle.md
+++ b/learn/how-to-articles/how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-truffle.md
@@ -1,46 +1,51 @@
---
id: truffle-example
title: Using Truffle Example
-description: "Use Truffle to deploy a Smart Contract."
keywords:
- docs
- apothem
- smart
- contract
- truffle
+description: Use Truffle to deploy a Smart Contract.
---
-# 🧭 Table of contents
-
-- [🧭 Table of contents](#-table-of-contents)
-- [📰 Overview](#-overview)
-- [🚀 Setting up the development environment](#-setting-up-the-development-environment)
- - [⚒️ 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 your first Smart Contract](#-writing-our-first-smart-contract)
- - [🍕 Compiling](#-compiling)
- - [🍕 Deploying](#-deploying)
- - [🍕 Interacting with your contract using Truffle Console](#-interacting-with-your-contract-using-truffle-console)
-- [🔍 Veryfing Contracts on the Block Explorer](#-veryfing-contracts-on-the-block-explorer)
-
-# 📰 Overview
+# How To deploy your first smart contract on the XDC Network using Truffle
+
+## 🧭 Table of contents
+
+* [🧭 Table of contents](how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-truffle.md#-table-of-contents)
+* [📰 Overview](how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-truffle.md#-overview)
+* [🚀 Setting up the development environment](how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-truffle.md#-setting-up-the-development-environment)
+ * [⚒️ Starting a new Truffle Project](how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-truffle.md#-starting-a-new-truffle-project)
+ * [⚒️ Configuring XDC Mainnet and Apothem Testnet on Truffle](how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-truffle.md#-configuring-xdc-mainnet-and-apothem-testnet-on-truffle)
+ * [⚒️ Adding Testnet XDC to Development Wallet](how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-truffle.md#-adding-testnet-xdc-to-development-wallet)
+* [🍕 Writing your first Smart Contract](how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-truffle.md#-writing-our-first-smart-contract)
+ * [🍕 Compiling](how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-truffle.md#-compiling)
+ * [🍕 Deploying](how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-truffle.md#-deploying)
+ * [🍕 Interacting with your contract using Truffle Console](how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-truffle.md#-interacting-with-your-contract-using-truffle-console)
+* [🔍 Veryfing Contracts on the Block Explorer](how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-truffle.md#-veryfing-contracts-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 leveraging an Ethereum Virtual Machine.
-### What you will learn
+#### What you will learn
+
This guide aims at teaching how to create a smart contract using Truffle and deploying it on the XDC Network.
-### What you will do
-- Install and set up Truffle
-- Deploy a contract on the XDC Network
-- Check the deployment status on [xinfin.network](https://xinfin.network/#stats).
+#### What you will do
+
+* Install and set up Truffle
+* Deploy a contract on the XDC Network
+* Check the deployment status on [xinfin.network](https://xinfin.network/#stats).
-# 🚀 Setting up the development environment
+## 🚀 Setting up the development environment
There are a few technical requirements before we start. Please install the following:
-- [Node.js v8+ LTS and npm](https://nodejs.org/en/) (comes with Node)
-- [Git](https://git-scm.com/)
+* [Node.js v8+ LTS and npm](https://nodejs.org/en/) (comes with Node)
+* [Git](https://git-scm.com/)
Once you have installed those, you only need one command to install Truffle:
@@ -48,7 +53,7 @@ Once you have installed those, you only need one command to install Truffle:
npm install -g truffle
```
-To verify that Truffle is installed properly, type **`truffle version`** on a terminal. You should see something like:
+To verify that Truffle is installed properly, type **`truffle version`** on a terminal. You should see something like:
```bash
Truffle v5.5.27 (core: 5.5.27)
@@ -60,7 +65,7 @@ Web3.js v1.7.4
If you see an error instead, make sure that your npm modules are added to your path.
-## ⚒ Starting a new Truffle Project
+### ⚒ Starting a new Truffle Project
You can start by setting up your folder. In this example, we are creating a project called `Pizza`. Create your new `Pizza` folder by running the following on terminal:
@@ -87,30 +92,28 @@ http://trufflesuite.com/docs
Your folder files will look like this:
-
-
-
+
-## ⚒ Configuring XDC Mainnet and Apothem Testnet on Truffle
+### ⚒ Configuring XDC Mainnet and Apothem Testnet on Truffle
In order to get started deploying new contracts on the XDC Mainnet and/or Apothem, you will 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 might need to install it first. You can skip this step if you already have yarn installed.
-```sh
+```
npm install --global yarn
```
Initialize your package manager in your folder and install the required dependencies:
-```sh
+```
yarn init -y
yarn add @truffle/hdwallet-provider dotenv
```
You will also need a **24-Word Mnemonic Phrase**. To configure your wallet, create a new `.env` file and write your mnemonic by running:
-```sh
+```
touch .env
echo MNEMONIC=arm derive cupboard decade course garlic journey blast tribe describe curve obey >> .env
```
@@ -121,7 +124,6 @@ Remember to change the **24-Word Mnemonic** above for your own mnemonic. The con
MNEMONIC=arm derive cupboard decade course garlic journey blast tribe describe curve obey
```
-
🚨 **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 the XDC Network by writing:
@@ -165,17 +167,17 @@ module.exports = {
};
```
-## ⚒ Adding Testnet XDC to Development Wallet
+### ⚒ Adding Testnet XDC to Development Wallet
It is possible to list all XDC addresses bound to your mnemonic on Truffle by accessing the Truffle console:
-```sh
+```
truffle console --network xinfin
```
Once the truffle console CLI opens, you can run:
-```sh
+```
truffle(xinfin)> accounts
```
@@ -200,21 +202,19 @@ These accounts are on the Ethereum standard format starting with `0x`, but we ca
With this account, we can head to the [Apothem Faucet](https://faucet.apothem.network/) and claim some TXDC for development purposes:
-
-
-
+
-# 🍕 Writing our first Smart Contract
+## 🍕 Writing our first Smart Contract
Lets create a simple `Pizza.sol` contract on Solidity, the Pizza contract should have:
- - a `constructor` where the deployer can define the pizza size,
- - a `eatSlice` method to consume slices available,
- - a `bakeNewPizza` method to refill all slices only if the previous pizza have been entirely eaten! 😋
+* a `constructor` where the deployer can define the pizza size,
+* a `eatSlice` method to consume slices available,
+* a `bakeNewPizza` method to refill all slices only if the previous pizza have been entirely eaten! 😋
You can start by creating the `Pizza.sol` file:
-```sh
+```
touch ./contracts/Pizza.sol
```
@@ -246,17 +246,17 @@ contract Pizza {
}
```
-## 🍕 Compiling
+### 🍕 Compiling
Next, try compiling the `Pizza.sol` contract by running:
-```sh
+```
truffle compile
```
If everything is correctly configured and there are no errors, you will see the following message on your console:
-```sh
+```
Compiling your contracts...
===========================
> Compiling ./contracts/Pizza.sol
@@ -267,15 +267,13 @@ Compiling your contracts...
And your folder should look like this:
-
-
-
+
-## 🍕 Deploying
+### 🍕 Deploying
In order to deploy our newly-compiled contract artifacts to the blockchain, we need to create a deployment script in the migrations folder.
-```sh
+```
touch ./migrations/1_pizza_migration.js
```
@@ -294,13 +292,13 @@ module.exports = function (deployer) {
If the migration script has no errors, you can run the command:
-```sh
+```
truffle migrate --network xinfin
```
for deployment on XDC mainet. Or you can run:
-```sh
+```
truffle migrate --network apothem
```
@@ -308,7 +306,7 @@ for deployment on the XDC Apothem Testnet. In either case, you must have enough
If the deployment is sucessful, the console should log the following message after migrations complete processing:
-```sh
+```
1_pizza_migration.js
====================
@@ -336,13 +334,13 @@ Summary
> Final cost: 0.0000880535 ETH
```
-## 🍕 Interacting with your contract using Truffle Console
+### 🍕 Interacting with your contract using Truffle Console
Another amazing tool that allow us to try out our contracts straight from our development environment is the `truffle console` CLI.
To start interacting with you smart contracts you can run:
-```sh
+```
truffle console --network xinfin
```
@@ -368,7 +366,7 @@ truffle(xinfin)> instance.eatSlice()
It should log a transaction confirmation (or rejection) object like this:
-```sh
+```
{
tx: '0x0153f15932d79ad7ac0b26df299defa1b55aded33284928b3e441d9fea5c3de7',
receipt: {
@@ -392,19 +390,19 @@ It should log a transaction confirmation (or rejection) object like this:
This transaction is immediately reflected in the corresponding block explorer, [as seen here!](https://explorer.xinfin.network/txs/0x0153f15932d79ad7ac0b26df299defa1b55aded33284928b3e441d9fea5c3de7)
-# 🔍 Veryfing Contracts on the Block Explorer
+## 🔍 Veryfing Contracts on the Block Explorer
Once you have successfully deployed your smart contract to the blockchain, you may want to verify your contract on [XinFin Block Explorer](https://explorer.xinfin.network/).
First lets check the address our contract is deployed to by running:
-```sh
+```
truffle networks
```
If you have a contract already deployed, the console should log something like this:
-```sh
+```
Network: apothem (id: 51)
No contracts deployed.
@@ -414,45 +412,30 @@ Network: xinfin (id: 50)
If your `Pizza` contract is deployed on the XDC Mainnet at `0xF899E5C79ccfa144fc76261Ad9A9F0300708FF24`. You can search for our newly deployed contract on [XinFin Block Explorer](https://explorer.xinfin.network/):
-
-
-
+
-Click in the `Verify And Publish` option.
+Click in the `Verify And Publish` option.
You will be redirected to the contract verification page where we need to fill out:
-- Contract Name: Pizza
-- Compiler: Check your `truffle-config.js` file for Compiler Version
-- Contract Code: Just paste everything from your `Pizza.sol` file
+* Contract Name: _Pizza_
+* Compiler: _Check your_ `truffle-config.js` _file for Compiler Version_
+* Contract Code: _Just paste everything from your_ `Pizza.sol` _file_
Once everything is filled out, press Submit!
-
-
-
+
If everything is correctly filled out, your contract page on the block explorer should display a new tab called `Contract`:
-
-
-
+
On this page you can read from, write to, or simply read the information tied to your smart contract on the blockchain:
-
-
-
-
-
----
-
-For more information about Truffle Suite, Please Visit [Truffle Suite Documentation](https://trufflesuite.com/docs/truffle/).
-For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).
-Resources used during the deployment of the Pizza smart contract can be found at [The Pizza Contract Folder](./Pizza).
-
-
-
-
+
+***
+For more information about Truffle Suite, Please Visit [Truffle Suite Documentation](https://trufflesuite.com/docs/truffle/).\
+For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).\
+Resources used during the deployment of the Pizza smart contract can be found at [The Pizza Contract Folder](Pizza/).
diff --git a/learn/how-to-articles/how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md b/learn/how-to-articles/how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md
index 5d4ce87d..a585b34a 100644
--- a/learn/how-to-articles/how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md
+++ b/learn/how-to-articles/how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md
@@ -1,44 +1,45 @@
-# 🧭 Table of contents
-
-- [🧭 Table of contents](#-table-of-contents)
-- [📰 Overview](#-overview)
- - [What you will learn](#what-you-will-learn)
- - [What you will do](#what-you-will-do)
-- [🚀 Setting up the development environment](#-setting-up-the-development-environment)
- - [⚒ Starting a new Truffle Project](#-starting-a-new-truffle-project)
-- [📝 Writing your first Smart Contract](#-writing-our-first-smart-contract)
- - [🍕 Compiling](#-compiling)
- - [Creating a .env file](#creating-a-env-file)
- - [🔀 Migrating from Ethereum to XDC network](#-migrating-from-ethereum-to-xdc-network)
- - [🍕 Deploying](#-deploying)
- - [🍕 Interacting with your contract using Truffle Console](#-interacting-with-your-contract-using-truffle-console)
-- [🔍 Veryfing Contracts on the Block Explorer](#-veryfing-contracts-on-the-block-explorer)
-
-
-# 📰 Overview
+# How to Migrate a dApp from Ethereum to the XDC Network Using Truffle
+
+## 🧭 Table of contents
+
+* [🧭 Table of contents](how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md#-table-of-contents)
+* [📰 Overview](how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md#-overview)
+ * [What you will learn](how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md#what-you-will-learn)
+ * [What you will do](how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md#what-you-will-do)
+* [🚀 Setting up the development environment](how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md#-setting-up-the-development-environment)
+ * [⚒ Starting a new Truffle Project](how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md#-starting-a-new-truffle-project)
+* [📝 Writing your first Smart Contract](how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md#-writing-our-first-smart-contract)
+ * [🍕 Compiling](how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md#-compiling)
+ * [Creating a .env file](how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md#creating-a-env-file)
+ * [🔀 Migrating from Ethereum to XDC network](how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md#-migrating-from-ethereum-to-xdc-network)
+ * [🍕 Deploying](how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md#-deploying)
+ * [🍕 Interacting with your contract using Truffle Console](how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md#-interacting-with-your-contract-using-truffle-console)
+* [🔍 Veryfing Contracts on the Block Explorer](how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle.md#-veryfing-contracts-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 leveraging an Ethereum Virtual Machine.
dApps use truffle and hardhat to work with decentralized networks like Ethereum and XDC.
-### What you will learn
+#### What you will learn
This guide aims at teaching on how to migrate a dApp from ethereum to the XDC network using truffle.
-### What you will do
+#### What you will do
-- Install and set up Truffle
-- Create a Truffle project
-- Write a smart contract
-- Compile and migrate the smart contract from the Ethereum Network to the XDC Network
-- Check the deployment status on [xinfin.network](https://xinfin.network/#stats).
+* Install and set up Truffle
+* Create a Truffle project
+* Write a smart contract
+* Compile and migrate the smart contract from the Ethereum Network to the XDC Network
+* Check the deployment status on [xinfin.network](https://xinfin.network/#stats).
-# 🚀 Setting up the development environment
+## 🚀 Setting up the development environment
There are a few technical requirements before you start. Please install the following:
-- [Node.js v8+ LTS and npm](https://nodejs.org/en/) (comes with Node)
-- [Git](https://git-scm.com/)
+* [Node.js v8+ LTS and npm](https://nodejs.org/en/) (comes with Node)
+* [Git](https://git-scm.com/)
Once you have those installed, you only need one command to install Truffle:
@@ -46,7 +47,7 @@ Once you have those installed, you only need one command to install Truffle:
npm install -g truffle
```
-To verify that Truffle is installed properly, type **`truffle version`** on a terminal. You should see something like:
+To verify that Truffle is installed properly, type **`truffle version`** on a terminal. You should see something like:
```bash
Truffle v5.5.27 (core: 5.5.27)
@@ -58,7 +59,7 @@ Web3.js v1.7.4
If you see an error instead, make sure that your npm modules are added to your path.
-## ⚒ Starting a new Truffle Project
+### ⚒ Starting a new Truffle Project
Start by setting up your folder. As we are creating a project called `Pizza`, create a new `Pizza` folder by running this on terminal:
@@ -85,18 +86,15 @@ http://trufflesuite.com/docs
And your folder files will look like this:
-
-
+
-
-
-# 📝 Writing our first Smart Contract
+## 📝 Writing our first Smart Contract
Lets create a simple `Pizza.sol` in the `contracts folder`. The Pizza contract should have:
-- a `constructor` where the deployer can define the pizza size,
-- a `eatSlice` method to consume slices available,
-- a `bakeNewPizza` method to refill all slices only if the previous pizza have been entirely eaten! 😋
+* a `constructor` where the deployer can define the pizza size,
+* a `eatSlice` method to consume slices available,
+* a `bakeNewPizza` method to refill all slices only if the previous pizza have been entirely eaten! 😋
Write the following code to `Pizza.sol`:
@@ -126,17 +124,17 @@ contract Pizza {
}
```
-## 🍕 Compiling
+### 🍕 Compiling
Now try compiling the `Pizza.sol` contract by running:
-```sh
+```
truffle compile
```
If everything is correctly configured and there are no errors, you should see the following message on your console:
-```sh
+```
Compiling your contracts...
===========================
> Compiling ./contracts/Pizza.sol
@@ -147,10 +145,7 @@ Compiling your contracts...
Your folder should look like this:
-
-
-
-
+
> If you see an error while compiling on a Mac, you can use `sudo truffle compile`
@@ -158,15 +153,15 @@ In order to get started deploying new contracts on XDC Mainnet and/or Apothem(te
If you never used `yarn` before, you might need to install it first. ‼️You can skip this step if you already have yarn installed‼️.
-```sh
+```
npm install --global yarn
```
-## Creating a .env file
+### Creating a .env file
Initialize your package manager on your folder and install the required dependencies through your terminal:
-```sh
+```
npm init -y
npm add @truffle/hdwallet-provider dotenv
```
@@ -181,7 +176,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!** 🚨
-## 🔀 Migrating from Ethereum to XDC network
+### 🔀 Migrating from Ethereum to XDC network
For this step we need to change the `truffle-config.js` file.
@@ -270,7 +265,7 @@ module.exports = {
};
```
-## 🍕 Deploying
+### 🍕 Deploying
In order to deploy our newly compiled contract artifacts to the blockchain, you'll have to create a deployment script in the migrations folder.
@@ -293,13 +288,13 @@ If the migration script have no errors, we can go ahead and run the command.
For deployment on XDC testnet:
-```sh
+```
truffle migrate --network xinfin
```
For deployment on XDC testnet:
-```sh
+```
truffle migrate --network apothem
```
@@ -307,7 +302,7 @@ For deployment on the XDC Apothem Testnet. In either case, you need to have enou
If the deployment is sucessful, the console should log the following message after migrations complete processing:
-```sh
+```
1_pizza_migration.js
====================
@@ -335,13 +330,13 @@ Summary
> Final cost: 0.0000881365 ETH
```
-## 🍕 Interacting with your contract using Truffle Console
+### 🍕 Interacting with your contract using Truffle Console
-The `truffle console` CLI is another amazing tool that allows us to try out our contracts straight from our development environment.
+The `truffle console` CLI is another amazing tool that allows us to try out our contracts straight from our development environment.
To start interacting with you smart contracts you can start running:
-```sh
+```
truffle console --network xinfin
```
@@ -367,7 +362,7 @@ truffle(xinfin) > instance.eatSlice();
It should log a transaction confirmation (Or rejection) object like the following:
-```sh
+```
{
tx: '0x27ee33417f2f471bda1beaaaff57c5c71ce3edcbacec99de677b04e0863a0f29',
receipt: {
@@ -391,19 +386,19 @@ It should log a transaction confirmation (Or rejection) object like the followin
This transaction is immediately reflected in the corresponding block explorer, [as seen here!](https://explorer.xinfin.network/txs/0x27ee33417f2f471bda1beaaaff57c5c71ce3edcbacec99de677b04e0863a0f29#overview)
-# 🔍 Veryfing Contracts on the Block Explorer
+## 🔍 Veryfing Contracts on the Block Explorer
Once you have successfully deployed your smart contract to the blockchain, may find it interesting to verify your contract on [XinFin Block Explorer](https://explorer.xinfin.network/).
First lets check the address our contract is deployed to by running:
-```sh
+```
truffle networks
```
If you have a contract already deployed, the console should log something like this:
-```sh
+```
Network: apothem (id: 51)
No contracts deployed.
@@ -413,44 +408,30 @@ Network: xinfin (id: 50)
There is a `Pizza` contract deployed on XDC Mainnet at the `0x4FA229354CdF9c49FD2752e3869150C24c6A80c7`. You can search for this newly deployed contract on [XinFin Block Explorer](https://explorer.xinfin.network/):
-
-
-
-
-
+
Click in the `Verify And Publish` Option.
We will be redirected to the Contract verification page where we need to fill out:
-- Contract Name: Pizza
-- Compiler: Check your `truffle-config.js` file for Compiler Version
-- Contract Code: Just paste everything from your `Pizza.sol` file
+* Contract Name: _Pizza_
+* Compiler: _Check your_ `truffle-config.js` _file for Compiler Version_
+* Contract Code: _Just paste everything from your_ `Pizza.sol` _file_
Once everything is filled out, press Submit!
-
-
-
-
+
If everything is correctly filled out, your contract page on the block explorer should display a new tab called `Contract`:
-
-
-
-
+
In this page you can read from, write to, or simply read the information tied to your smart contract on the blockchain:
-
-
-
-
-
+
----
+***
-For more information about Truffle Suite, Please Visit [Truffle Suite Documentation](https://trufflesuite.com/docs/truffle/).
-For more information about XDC Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.community/).
+For more information about Truffle Suite, Please Visit [Truffle Suite Documentation](https://trufflesuite.com/docs/truffle/).\
+For more information about XDC Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.community/).\
Resources used during the deployment of the Pizza Smart Contract can be found at [The Pizza Contract Folder](https://github.com/XDC-Community/docs/tree/main/how-to/Pizza).
diff --git a/learn/how-to-articles/how-to-send-an-xrc20-transaction-on-the-xdc-network-using-ethers.js.md b/learn/how-to-articles/how-to-send-an-xrc20-transaction-on-the-xdc-network-using-ethers.js.md
index a1abb05b..4f47c6a4 100644
--- a/learn/how-to-articles/how-to-send-an-xrc20-transaction-on-the-xdc-network-using-ethers.js.md
+++ b/learn/how-to-articles/how-to-send-an-xrc20-transaction-on-the-xdc-network-using-ethers.js.md
@@ -1,78 +1,81 @@
---
id: xrc20-token-ethers.js
title: Sending XRC20 Tokens on the XDC Network Using Ethers.js
-description: "Use Ethers.js to send XRC20 tokens over the XDC network"
keywords:
- docs
- apothem
- token
- XRC20
- ethers.js
+description: Use Ethers.js to send XRC20 tokens over the XDC network
---
-# 🧭 Table of contents
-
-- [🧭 Table of contents](#-table-of-contents)
-- [📰 Overview](#-overview)
- - [What you will learn](#what-you-will-learn)
- - [What you will do](#what-you-will-do)
- - [📰 About XRC20 Tokens](#-about-xrc20-tokens)
-- [🚀 Setting up the development environment](#-setting-up-the-development-environment)
- - [⚒ Starting a new NPM Project and Installing Dependencies](#-starting-a-new-npm-project-and-installing-dependencies)
- - [💵 Transacting an XRC20 token contract on the XDC Network with ethers](#-transacting-an-xrc20-token-contract-on-the-xdc-network-with-ethers)
- - [💵 Add funds to wallet using Apothem Faucet](#-add-funds-to-wallet-using-apothem-faucet)
- - [💵 What is an XDC transaction](#-what-is-an-xdc-transaction)
- - [💵 Setting up env file](#-setting-up-env-file)
- - [💵 Using ethers to transact XRC20](#-using-ethers-to-transact-xrc20)
- - [🔍 Verifying transaction via Apothem network explorer](#-verifying-transaction-via-apothem-network-explorer)
-
-# 📰 Overview
+# How to Send an XRC20 Transaction on the XDC Network Using ethers.js
+
+## 🧭 Table of contents
+
+* [🧭 Table of contents](how-to-send-an-xrc20-transaction-on-the-xdc-network-using-ethers.js.md#-table-of-contents)
+* [📰 Overview](how-to-send-an-xrc20-transaction-on-the-xdc-network-using-ethers.js.md#-overview)
+ * [What you will learn](how-to-send-an-xrc20-transaction-on-the-xdc-network-using-ethers.js.md#what-you-will-learn)
+ * [What you will do](how-to-send-an-xrc20-transaction-on-the-xdc-network-using-ethers.js.md#what-you-will-do)
+ * [📰 About XRC20 Tokens](how-to-send-an-xrc20-transaction-on-the-xdc-network-using-ethers.js.md#-about-xrc20-tokens)
+* [🚀 Setting up the development environment](how-to-send-an-xrc20-transaction-on-the-xdc-network-using-ethers.js.md#-setting-up-the-development-environment)
+ * [⚒ Starting a new NPM Project and Installing Dependencies](how-to-send-an-xrc20-transaction-on-the-xdc-network-using-ethers.js.md#-starting-a-new-npm-project-and-installing-dependencies)
+ * [💵 Transacting an XRC20 token contract on the XDC Network with ethers](how-to-send-an-xrc20-transaction-on-the-xdc-network-using-ethers.js.md#-transacting-an-xrc20-token-contract-on-the-xdc-network-with-ethers)
+ * [💵 Add funds to wallet using Apothem Faucet](how-to-send-an-xrc20-transaction-on-the-xdc-network-using-ethers.js.md#-add-funds-to-wallet-using-apothem-faucet)
+ * [💵 What is an XDC transaction](how-to-send-an-xrc20-transaction-on-the-xdc-network-using-ethers.js.md#-what-is-an-xdc-transaction)
+ * [💵 Setting up env file](how-to-send-an-xrc20-transaction-on-the-xdc-network-using-ethers.js.md#-setting-up-env-file)
+ * [💵 Using ethers to transact XRC20](how-to-send-an-xrc20-transaction-on-the-xdc-network-using-ethers.js.md#-using-ethers-to-transact-xrc20)
+ * [🔍 Verifying transaction via Apothem network explorer](how-to-send-an-xrc20-transaction-on-the-xdc-network-using-ethers.js.md#-verifying-transaction-via-apothem-network-explorer)
+
+## 📰 Overview
+
[Ethers.js](https://github.com/ethers-io/ethers.js/) is a library written in Javascript which simplifies blockchain interactions.
-### What you will learn
+#### What you will learn
+
In this tutorial, you will learn how to import ethers.js, transact an XRC20 token, and set gas prices appropriately.
-### What you will do
-- Import ethers.js
-- Transfer an XRC20 token
-- Verify Transaction
+#### What you will do
+
+* Import ethers.js
+* Transfer an XRC20 token
+* Verify Transaction
-## 📰 About XRC20 Tokens
+### 📰 About XRC20 Tokens
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)`
-- `allowance(address owner, address spender)`
-- `transfer(address recipient, uint amount)`
-- `approve(address spender, uint amount)`
-- `transferFrom(address sender, address recipient, uint amount)`
+* `totalSupply()`
+* `balanceOf(address account)`
+* `allowance(address owner, address spender)`
+* `transfer(address recipient, uint amount)`
+* `approve(address spender, uint amount)`
+* `transferFrom(address sender, address recipient, uint amount)`
These are the minimum required methods that allow an asset on the XDC network to be called an XRC20 token. Also, a 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)`
-
+* `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.
Last but not least, a few contract constants that are public that are also very important to have are:
-- `name`
-- `symbol`
-- `decimals`
+* `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.
-# 🚀 Setting up the development environment
+## 🚀 Setting up the development environment
There are a few technical requirements before you start. Please install the following:
-- [Node.js v8+ LTS and npm](https://nodejs.org/en/) (comes with Node)
-- [Git](https://git-scm.com/)
+* [Node.js v8+ LTS and npm](https://nodejs.org/en/) (comes with Node)
+* [Git](https://git-scm.com/)
-## ⚒ Starting a new NPM Project and Installing Dependencies
+### ⚒ Starting a new NPM Project and Installing Dependencies
Start by setting up your folder. As we are creating a project called `XRC20`, you should create a new `XRC20` folder by running on terminal.
@@ -81,34 +84,38 @@ mkdir XRC20 && cd XRC20
```
Initialize the new project in that folder:
-```sh
+
+```
npm init
```
+
> Tip: to generate project without any questions you can use `npm init -y`
Install the necessary dependencies:
-```sh
+
+```
npm install ethers dotenv
```
-## 💵 Transacting an XRC20 token contract on the XDC Network with ethers
+
+### 💵 Transacting an XRC20 token contract on the XDC Network with ethers
Before sending actual transactions, we have to do some preparations.
-## 💵 Add funds to wallet using Apothem Faucet
-Go to https://faucet.apothem.network/ and paste your address and press `Request 1000 XDC`
-
+### 💵 Add funds to wallet using Apothem Faucet
+
+Go to https://faucet.apothem.network/ and paste your address and press `Request 1000 XDC` 
If you don't have an XDC address yet, you can create new wallet using [XDCPay](https://chrome.google.com/webstore/detail/xdcpay/bocpokimicclpaiekenaeelehdjllofo)
-## 💵 What is an XDC transaction
+### 💵 What is an XDC transaction
An XDC transaction is a set of instructions one account sends to another. Transactions can be used to transfer native XDC token or for interactions with smart contracts.
-## 💵 Setting up env file
+### 💵 Setting up env file
You can use `.env.example` as a template.
-Your `.env` file should look like this:
+Your `.env` file should look like this:
```
XINFIN_NETWORK_URL=https://erpc.xinfin.network
@@ -120,22 +127,17 @@ XRC20_TOKEN_ADDRESS=0xyourtokenaddress
> Tip: never commit files containing your seed phrase or private key to a git
-❕ Keep in mind that you need to replace `xdc` prefix in your token address with `0x`.
-So token address `xdcfc1b5137a6c8dffcf816857463afbb4672d462f3` will become `0xfc1b5137a6c8dffcf816857463afbb4672d462f3`.
+❕ Keep in mind that you need to replace `xdc` prefix in your token address with `0x`. So token address `xdcfc1b5137a6c8dffcf816857463afbb4672d462f3` will become `0xfc1b5137a6c8dffcf816857463afbb4672d462f3`.
If you don't have any XRC20 tokens, you can follow one of those tutorials to create one:
-- [Create XRC20 token using Hardhat](https://github.com/XDC-Community/docs/blob/main/how-to/XRC20/Hardhat/how-to.md)
-- [Create XRC20 token using Remix](https://github.com/XDC-Community/docs/blob/main/how-to/XRC20/Remix/how-to.md)
-- [Create XRC20 token using Truffle](https://github.com/XDC-Community/docs/blob/main/how-to/XRC20/Truffle/how-to.md)
+* [Create XRC20 token using Hardhat](../../how-to/XRC20/Hardhat/how-to.md)
+* [Create XRC20 token using Remix](../../how-to/XRC20/Remix/how-to.md)
+* [Create XRC20 token using Truffle](../../how-to/XRC20/Truffle/how-to.md)
-If you don't know what private key is or how to get it, this is how you can copy your private key from XDCPay
-
-
-
-
+If you don't know what private key is or how to get it, this is how you can copy your private key from XDCPay    
-## 💵 Using ethers to transact XRC20
+### 💵 Using ethers to transact XRC20
Create a file named `send_token.js` in your project with following content:
@@ -174,7 +176,7 @@ Now lets go through each line:
const XRC20ABI = require('./XRC20.json')
```
-In order to interact with the contract, you need to provide an `ABI` or application binary interface. This is basically just list of functions and events which explains how to interact with smart contract. You can copy `ABI` from here [XRC20 ABI](./example-xrc20-transfer/XRC20.json)
+In order to interact with the contract, you need to provide an `ABI` or application binary interface. This is basically just list of functions and events which explains how to interact with smart contract. You can copy `ABI` from here [XRC20 ABI](example-xrc20-transfer/XRC20.json)
```javascript
const testnetProvider = new ethers.providers.JsonRpcProvider(process.env.APOTHEM_NETWORK_URL)
@@ -224,7 +226,7 @@ console.log(receipt.hash)
Now lets run it!
-```sh
+```
node send_token.js
```
@@ -234,25 +236,20 @@ Next, wait few seconds and you should see something like this:
0xabf5957a25f943dfb1b71c6d9fc041c7c419b6440af4661f8aab21fc185bd134
```
-## 🔍 Verifying transaction via Apothem network explorer
+### 🔍 Verifying transaction via Apothem network explorer
-After running our script, you should have received a transaction hash. You can use this hash to check transaction on a blockchain.
-To do this, go to https://explorer.apothem.network and paste your transaction hash in search field.
+After running our script, you should have received a transaction hash. You can use this hash to check transaction on a blockchain. To do this, go to https://explorer.apothem.network and paste your transaction hash in search field.
-You should see the following:
-
+You should see the following: 
-Here, you can see that your transaction ended with success:
-
+Here, you can see that your transaction ended with success: 
-This is how much you ended up paying for our transaction:
-
+This is how much you ended up paying for our transaction: 
-And here is how much tokens we sent:
-
+And here is how much tokens we sent: 
----
+***
-For more information about ether.js check out [ethers.js github repo](https://github.com/ethers-io/ethers.js/) and [ethers.js documentation website](https://docs.ethers.io/v5/).
-For more information about the XDC Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).
-You can find resources used for this tutorial here [example-xrc20-transfer](./example-xrc20-transfer).
+For more information about ether.js check out [ethers.js github repo](https://github.com/ethers-io/ethers.js/) and [ethers.js documentation website](https://docs.ethers.io/v5/).\
+For more information about the XDC Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).\
+You can find resources used for this tutorial here [example-xrc20-transfer](example-xrc20-transfer/).
diff --git a/learn/how-to-articles/how-to-use-truffle-and-ganache-to-create-defi-app.md b/learn/how-to-articles/how-to-use-truffle-and-ganache-to-create-defi-app.md
index b5fc022c..2616c516 100644
--- a/learn/how-to-articles/how-to-use-truffle-and-ganache-to-create-defi-app.md
+++ b/learn/how-to-articles/how-to-use-truffle-and-ganache-to-create-defi-app.md
@@ -1,59 +1,63 @@
---
id: defi-app-truffle
title: DeFi App using Truffle and Ganache
-description: "Use Truffle and Ganache to create DeFi App"
keywords:
- docs
- apothem
- token
- DeFi
- truffle
+description: Use Truffle and Ganache to create DeFi App
---
-# 🧭 Table of contents
-
-- [🧭 Table of contents](#-table-of-contents)
-- [📰 Overview](#-overview)
- - [What you will learn](#what-you-will-learn)
- - [What you will do](#what-you-will-do)
- - [📰 About DeFi](#-about-defi)
-- [🚀 Setting up the development environment](#-setting-up-the-development-environment)
- - [⚒ 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)
-- [💵 Creating your first DeFi App](#-creating-our-first-defi-app)
- - [💵 Create and Deploy XRC20 Token](#-create-and-deploy-xrc20-token)
- - [💵 Create FarmToken contract](#-create-farmtoken-contract)
- - [💵 Compiling and Deploying](#-compiling-and-deploying)
- - [💵 Testing FarmToken contract](#-testing-farmtoken-contract)
- - [💵 Deploying on a live network](#-deploying-on-a-live-network)
-- [🔍 Veryfing Contracts on the Block Explorer](#-veryfing-contracts-on-the-block-explorer)
-
-# 📰 Overview
+# How To Use Truffle and Ganache to Create DeFi App
+
+## 🧭 Table of contents
+
+* [🧭 Table of contents](how-to-use-truffle-and-ganache-to-create-defi-app.md#-table-of-contents)
+* [📰 Overview](how-to-use-truffle-and-ganache-to-create-defi-app.md#-overview)
+ * [What you will learn](how-to-use-truffle-and-ganache-to-create-defi-app.md#what-you-will-learn)
+ * [What you will do](how-to-use-truffle-and-ganache-to-create-defi-app.md#what-you-will-do)
+ * [📰 About DeFi](how-to-use-truffle-and-ganache-to-create-defi-app.md#-about-defi)
+* [🚀 Setting up the development environment](how-to-use-truffle-and-ganache-to-create-defi-app.md#-setting-up-the-development-environment)
+ * [⚒ Starting a new Truffle Project](how-to-use-truffle-and-ganache-to-create-defi-app.md#-starting-a-new-truffle-project)
+ * [⚒ Configuring XDC Mainnet and Apothem Testnet on Truffle](how-to-use-truffle-and-ganache-to-create-defi-app.md#-configuring-xdc-mainnet-and-apothem-testnet-on-truffle)
+ * [⚒ Adding Testnet XDC to Development Wallet](how-to-use-truffle-and-ganache-to-create-defi-app.md#-adding-testnet-xdc-to-development-wallet)
+* [💵 Creating your first DeFi App](how-to-use-truffle-and-ganache-to-create-defi-app.md#-creating-our-first-defi-app)
+ * [💵 Create and Deploy XRC20 Token](how-to-use-truffle-and-ganache-to-create-defi-app.md#-create-and-deploy-xrc20-token)
+ * [💵 Create FarmToken contract](how-to-use-truffle-and-ganache-to-create-defi-app.md#-create-farmtoken-contract)
+ * [💵 Compiling and Deploying](how-to-use-truffle-and-ganache-to-create-defi-app.md#-compiling-and-deploying)
+ * [💵 Testing FarmToken contract](how-to-use-truffle-and-ganache-to-create-defi-app.md#-testing-farmtoken-contract)
+ * [💵 Deploying on a live network](how-to-use-truffle-and-ganache-to-create-defi-app.md#-deploying-on-a-live-network)
+* [🔍 Veryfing Contracts on the Block Explorer](how-to-use-truffle-and-ganache-to-create-defi-app.md#-veryfing-contracts-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 leveraging an Ethereum Virtual Machine. [Ganache](https://trufflesuite.com/ganache/) is a tool to create a local blockchain for testing your smart contracts. It simulates all the features of a real blockchain network but costs you nothing to deploy and test your code.
-### What you will learn
+#### What you will learn
+
In this tutorial, we will build a DeFi Application with Solidity where users can deposit an XRC20 token to the smart contract and it will mint and transfer Farm Tokens to them. The users can later withdraw their XRC20 tokens by burning their Farm Token with a smart contract, and the XRC20 tokens will be transferred back to them.
-### What you will do
+#### What you will do
-- Install and setup Truffle and Ganache
-- Create a Truffle project
-- Create an XRC20 Token
-- Compile an XRC20 Token
-- Deploy an XRC20 Token
-- Create FarmToken Smart Contract
+* Install and setup Truffle and Ganache
+* Create a Truffle project
+* Create an XRC20 Token
+* Compile an XRC20 Token
+* Deploy an XRC20 Token
+* Create FarmToken Smart Contract
-## 📰 About DeFi
+### 📰 About DeFi
Decentralized finance, or **DeFi**, is a term which describes blockchain-based financial services. DeFi provides virtually any financial service on a blockchain in a permissionless way. You can borrow, lend, stake, trade, and more using DeFi services.
-# 🚀 Setting up the development environment
+## 🚀 Setting up the development environment
There are a few technical requirements before we start. Please install the following:
-- [Node.js v8+ LTS and npm](https://nodejs.org/en/) (comes with Node)
-- [Git](https://git-scm.com/)
+* [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:
@@ -61,7 +65,7 @@ Once we have those installed, we only need one command to install Truffle:
npm install -g truffle
```
-To verify that Truffle is installed properly, type **`truffle version`** on a terminal. You should see something like:
+To verify that Truffle is installed properly, type **`truffle version`** on a terminal. You should see something like:
```bash
Truffle v5.5.27 (core: 5.5.27)
@@ -73,7 +77,7 @@ Web3.js v1.7.4
If you see an error instead, make sure that your npm modules are added to your path.
-## ⚒ Starting a new Truffle Project
+### ⚒ Starting a new Truffle Project
You will start by setting up tour folder. In this example, we are creating a project called `FarmToken`. You can create a new `FarmToken` folder by running on the following on terminal:
@@ -100,31 +104,29 @@ http://trufflesuite.com/docs
Your folder files will look like this:
-
-
-
+
-
-## ⚒ Configuring XDC Mainnet and Apothem Testnet on Truffle
+### ⚒ Configuring XDC Mainnet and Apothem Testnet on Truffle
In order to get started deploying new contracts on XDC Mainnet and/or Apothem, you'll 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 might need to install it first.\
+‼️You can skip this step if you already have yarn installed‼️
-```sh
+```
npm install --global yarn
```
Initialize your package manager on your folder and install the required dependencies:
-```sh
+```
yarn init -y
yarn add @truffle/hdwallet-provider dotenv
```
You will also need a **24-Word Mnemonic Phrase**. To configure your wallet, create a new `.env` file and write your mnemonic by running:
-```sh
+```
touch .env
echo MNEMONIC=arm derive cupboard decade course garlic journey blast tribe describe curve obey >> .env
```
@@ -135,7 +137,6 @@ Remember to change the **24-Word Mnemonic** above for your own mnemonic. The con
MNEMONIC=arm derive cupboard decade course garlic journey blast tribe describe curve obey
```
-
🚨 **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!** 🚨
Lastly, you can configure the `truffle-config.js` file for both Apothem and XinFin Networks by writting:
@@ -179,17 +180,17 @@ module.exports = {
};
```
-## ⚒ Adding Testnet XDC to Development Wallet
+### ⚒ Adding Testnet XDC to Development Wallet
It is possible to list all XDC addresses bound to your mnemonic on truffle by accessing the truffle console:
-```sh
+```
truffle console --network xinfin
```
Once the truffle console CLI opens, you can run:
-```sh
+```
truffle(xinfin)> accounts
```
@@ -214,31 +215,29 @@ These accounts use the Ethereum standard format starting with `0x`, but we can s
With this account in hand, you can head to the [Apothem Faucet](https://faucet.apothem.network/) and claim some TXDC for development purposes:
-
-
-
+
-# 💵 Creating our first DeFi App
+## 💵 Creating our first DeFi App
-The source code for the DeFi App used in this tutorial is available here: [FarmToken Contract](https://github.com/XDC-Community/docs/blob/main/how-to/DeFi/Truffle/FarmToken/contracts/FarmToken.sol) and [MyToken Contract](https://github.com/XDC-Community/docs/blob/main/how-to/DeFi/Truffle/FarmToken/contracts/MyToken.sol).
+The source code for the DeFi App used in this tutorial is available here: [FarmToken Contract](../../how-to/DeFi/Truffle/FarmToken/contracts/FarmToken.sol) and [MyToken Contract](../../how-to/DeFi/Truffle/FarmToken/contracts/MyToken.sol).
-## 💵 Create and Deploy XRC20 Token
+### 💵 Create and Deploy XRC20 Token
Before creating FarmToken contract, you should first create a new XRC20 token. This is going to be a quick guide, but if you want an in-depth understanding of the `XRC20` standard, please visit the following tutorials:
-- [Create XRC20 token using Hardhat](https://docs.xdc.community/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-hardhat)
-- [Create XRC20 token using Remix](https://docs.xdc.community/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-remix)
-- [Create XRC20 token using Truffle](https://docs.xdc.community/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-truffle)
+* [Create XRC20 token using Hardhat](https://docs.xdc.community/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-hardhat)
+* [Create XRC20 token using Remix](https://docs.xdc.community/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-remix)
+* [Create XRC20 token using Truffle](https://docs.xdc.community/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-truffle)
We will need to install OpenZeppelin in order to not writing all code by ourself
-```sh
+```
yarn add @openzeppelin/contracts
```
or using `npm`
-```sh
+```
npm install @openzeppelin/contracts
```
@@ -256,7 +255,7 @@ contract XRC20Token is ERC20 {
}
```
-## 💵 Create FarmToken contract
+### 💵 Create FarmToken contract
Create another smart contract called `FarmToken.sol`.
@@ -307,17 +306,17 @@ contract FarmToken is ERC20 {
`FarmToken` is a XRC20 token, but with 3 custom commands. `balance` shows how much of `MyToken` our `FarmToken` holds. `deposit` transfers `MyToken` from our account to `FarmToken` and gives us respective amount of `FarmToken`. `withdraw` burns our `FarmToken` and returns back `MyToken` to us. The latter prevents you from having both same amounts of `FarmToken` and `MyToken`, as you can hold only one of them.
-## 💵 Compiling and Deploying
+### 💵 Compiling and Deploying
We can compile our smart contracts (`FarmToken.sol` and `MyToken.sol`) by running:
-```sh
+```
truffle compile
```
If everything is correctly configured and there are no errors, you should see the following message on your console:
-```sh
+```
Compiling your contracts...
===========================
> Compiling ./contracts/FarmToken.sol
@@ -335,11 +334,11 @@ Compiling your contracts...
And your folder should look like this:
-
+
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_defi_migration.js
```
@@ -365,19 +364,19 @@ module.exports = async function (deployer) {
}
```
-Now, you can run it on a ganache local network. First, open the Ganache app and choose the `Quickstart` option to start your local blockchain network.
+Now, you can run it on a ganache local network. First, open the Ganache app and choose the `Quickstart` option to start your local blockchain network.
-
+
Next, deploy contracts by running:
-```sh
+```
truffle migrate
```
If everything is fine, you'll have an output like this:
-```sh
+```
Starting migrations...
======================
> Network name: 'ganache'
@@ -428,21 +427,20 @@ Summary
> Final cost: 0.06297366 ETH
```
-This is what you will see from Ganache app.
-
+This is what you will see from Ganache app. 
-
-
-
-## 💵 Testing FarmToken contract
+
+### 💵 Testing FarmToken contract
Create a `scripts` folder where we will put our files for testing.
+
```bash
mkdir scripts
```
Next, you can create your first script to check balance of `FarmToken`. Create file `getMyTokenBalance.js` and paste:
+
```javascript
const MyToken = artifacts.require("XRC20Token")
const FarmToken = artifacts.require("FarmToken")
@@ -458,13 +456,14 @@ module.exports = async function (callback) {
After that, you can run a script to check our `FarmToken` balance: `truffle exec ./scripts/getMyTokenBalance.js`
-```sh
+```
Using network 'ganache'.
0
```
We now need a script to deposit our tokens in the `FarmToken` contract. Create a file `depositMyToken.js`
+
```javascript
const MyToken = artifacts.require("XRC20Token")
const FarmToken = artifacts.require("FarmToken")
@@ -555,11 +554,11 @@ module.exports = async function (callback) {
It's time to deposit some tokens.
-```sh
+```
truffle exec ./scripts/depositMyToken.js
```
-```sh
+```
Using network 'ganache'.
Amount of MyToken FarmToken is allowed to transfer on our behalf Before: 0
@@ -581,7 +580,7 @@ Balance FarmToken After TokenFarm 0
Check your balance again using `truffle exec ./scripts/getMyTokenBalance.js`
-```sh
+```
Using network 'ganache'.
100
@@ -590,6 +589,7 @@ Using network 'ganache'.
Everything should be working as intended.
Finally, you can check if we can withdraw your tokens by creating a file called `withdrawMyToken.js`:
+
```javascript
const MyToken = artifacts.require("XRC20Token")
const FarmToken = artifacts.require("FarmToken")
@@ -659,11 +659,11 @@ module.exports = async function (callback) {
Now, you can run it:
-```sh
+```
truffle exec ./scripts/withdrawMyToken.js
```
-```sh
+```
Using network 'ganache'.
*** My Token ***
@@ -681,21 +681,21 @@ Balance FarmToken After accounts[0] 0
Balance FarmToken After TokenFarm 0
```
-## 💵 Deploying on a live network
+### 💵 Deploying on a live network
Finally, you can deploy everything on a XDC Apothem Testnet.
-```sh
+```
truffle migrate --network apothem
```
If you want to deploy it on XDC mainet, change network to `xinfin`.
-```sh
+```
truffle migrate --network xinfin
```
-# 🔍 Veryfing Contracts on the Block Explorer
+## 🔍 Veryfing Contracts on the Block Explorer
Once you have successfully deployed your smart contract to the blockchain, you might want to verify your contract on [XinFin Block Explorer](https://explorer.xinfin.network/).
@@ -721,35 +721,28 @@ Next, open `MyToken_flat.sol` and remove every line which starts with `// SPDX-L
Now, lets grab the `MyToken.sol` address from the deploying step: 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/):
-
-
-
+
Click on the `Verify And Publish` Option.
You will be redirected to the contract verification page where we need to fill out:
-- Contract Name: XRC20Token
-- Compiler: Check your `truffle-config.js` file for Compiler Version
-- Contract Code: Just paste everything from your `MyToken_flat.sol` file
+* Contract Name: _XRC20Token_
+* Compiler: _Check your_ `truffle-config.js` _file for Compiler Version_
+* Contract Code: _Just paste everything from your_ `MyToken_flat.sol` _file_
Once everything is filled out, press Submit!
-
-
-
+
If everything was filled out correctly, your contract page on the block explorer should display a new tab called `Contract`:
-
-
-
+
Repeat those steps if you want to verify `FarmToken.sol`, except this time `Contract Name` will be `FarmToken` and source code will be from `FarmToken_flat.sol`
----
+***
-For more information about Truffle Suite, Please Visit [Truffle Suite Documentation](https://trufflesuite.com/docs/truffle/).
-For more information about XDC Network, Please Visit [XDC Community Documentation on GitBook](https://docs.xdc.community/).
+For more information about Truffle Suite, Please Visit [Truffle Suite Documentation](https://trufflesuite.com/docs/truffle/).\
+For more information about XDC Network, Please Visit [XDC Community Documentation on GitBook](https://docs.xdc.community/).\
Resources used during the deployment of the DeFi App can be found at [FarmToken Contract Folder](https://github.com/XDC-Community/docs/tree/main/how-to/DeFi/Truffle/FarmToken/contracts).
-
diff --git a/run-a-node/masternode/one-click-installer-masternode-macos.md b/run-a-node/masternode/one-click-installer-masternode-macos.md
index 3fce1c9d..ce6d309d 100644
--- a/run-a-node/masternode/one-click-installer-masternode-macos.md
+++ b/run-a-node/masternode/one-click-installer-masternode-macos.md
@@ -40,7 +40,7 @@ If the lock at the bottom left is locked
+
7\. Once it starts syncing, you will notice the "Peers" number going up and "Blocks" going up. If prompted by your MacOS to "allow incoming connections to XinFin Network" click "Allow." You will see the application generate your account.
diff --git a/subnets/README.md b/subnets/README.md
new file mode 100644
index 00000000..1eb666f7
--- /dev/null
+++ b/subnets/README.md
@@ -0,0 +1,174 @@
+---
+description: >-
+ subnets allow for applications to run local versions of their application for
+ privacy or compliance needs while also maintaining an internal means of
+ decentralization, and high availability.
+---
+
+# Subnets
+
+### XinFin DPoS
+
+#### Build a XDC01 DPoS Based BlockChain network in few steps...!
+
+Here’s how you built a XDC01 blockchain network, in this repository you will get a step-by-step guidance on setting up a hassle free XDC01 blockchain without knowing blockchain knowledge.
+
+## Description
+
+XDC subnets allowf for applications to run local along side the public main network
+
+
+
+
+
+
+
+
+
+**Prerequisite**
+
+**Operating System**: Ubuntu 16.04 64-bit or higher
+
+**Hardware**:
+
+| Hardware | Minimum | Desired |
+| ------------ | ------- | ------- |
+| **CPU's**: | 2 | 4 |
+| **Memory**: | 4 GB | 16 GB |
+| **Storage**: | 100 GB | 500 GB |
+
+### Network Ports
+
+Following network ports need to be open for the nodes to communicate
+
+| Port | Type | Definition |
+| :----------: | :-----: | ---------- |
+| 30301-3030\* | TCP/UDP | XDC Enode |
+| 8545-854\* | TCP | RPC |
+| 9545-954\* | TCP | WebSocket |
+
+**Delete Old Data**
+
+```
+ bash reset.sh
+```
+
+## Set up script
+
+For managing a multi server node set up you will need to modify Local\_DPoS\_Stup/run.sh file to allow for the encode bootkey provided by each othe bootnodes and list them in order separated by a comma consisting of these attributes
+
+ 1\. local the run.sh script to modify deployment details
+
+```bash
+cd Local_DPoS_Stup/run.sh
+```
+
+2. add each Enode bootkey broadcasting on port: 3030\* each on a different port acending from port 30301
+3. assign the modifires to the suffix of the command
+
+```bash
+${PROJECT_DIR}/build/bin/$Bin_NAME --bootnodes
+"snode://"
+ --syncmode "full"
+ --datadir ./nodes/1
+ --networkid "${networkid}"
+ --port 30303
+ --rpc
+ --rpccorsdomain "*"
+ --ws
+ --wsaddr="0.0.0.0"
+ --wsorigins "*"
+ --wsport 8555
+ --rpcaddr 0.0.0.0
+ --rpcport 8545
+ --rpcvhosts "*"
+ --unlock "${wallet1}"
+ --password ./.pwd
+ --mine
+ --gasprice "${GASPRICE}"
+ --targetgaslimit "420000000"
+ --verbosity ${VERBOSITY}
+ --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3,XDPoS
+ --ethstats "XinFin-MasterNode-01:xinfin_xdpos_hybrid_network_stats@stats.xinfin.network:3000" &
+
+```
+
+## Full command
+
+{% code overflow="wrap" %}
+```bash
+${PROJECT_DIR}/build/bin/$Bin_NAME --bootnodes "enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@78.129.229.96:30301,enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@5.152.223.199:30301,enode://d757f1a21828c9c426e26df39176053302209e3dd05e7a6c0e0eae57739e233c0fa970c9b98e010cee4817e6233c3ad3eef461cef3e731c485ed4bc08de7d0ac@37.58.56.228:30303 --syncmode "full" --datadir ./nodes/1 --networkid "${networkid}" --port 30303 --rpc --rpccorsdomain "*" --ws --wsaddr="0.0.0.0" --wsorigins "*" --wsport 8555 --rpcaddr 0.0.0.0 --rpcport 8545 --rpcvhosts "*" --unlock "${wallet1}" --password ./.pwd --mine --gasprice "${GASPRICE}" --targetgaslimit "420000000" --verbosity ${VERBOSITY} --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3,XDPoS --ethstats "XinFin-MasterNode-01:xinfin_xdpos_hybrid_network_stats@stats.xinfin.network:3000" &
+```
+{% endcode %}
+
+## run.sh
+
+{% code lineNumbers="true" %}
+```bash
+// Local_DPoS_Stup/run.sh
+#!/bin/bash
+_interupt() {
+ echo "Shutdown $child_proc"
+ kill -TERM $child_proc
+ exit
+}
+
+trap _interupt INT TERM
+
+touch .pwd
+export $(cat .env | xargs)
+Bin_NAME=XDC
+
+WORK_DIR=$PWD
+PROJECT_DIR="/root/XinFin/XDPoSChain"
+cd $PROJECT_DIR && make XDC
+cd $WORK_DIR
+
+if [ ! -d ./nodes/1/$Bin_NAME/chaindata ]
+then
+ wallet1=$(${PROJECT_DIR}/build/bin/$Bin_NAME account import --password .pwd --datadir ./nodes/1 <(echo ${PRIVATE_KEY_1}) | awk -v FS="({|})" '{print $2}')
+ wallet2=$(${PROJECT_DIR}/build/bin/$Bin_NAME account import --password .pwd --datadir ./nodes/2 <(echo ${PRIVATE_KEY_2}) | awk -v FS="({|})" '{print $2}')
+ wallet3=$(${PROJECT_DIR}/build/bin/$Bin_NAME account import --password .pwd --datadir ./nodes/3 <(echo ${PRIVATE_KEY_3}) | awk -v FS="({|})" '{print $2}')
+ ${PROJECT_DIR}/build/bin/$Bin_NAME --datadir ./nodes/1 init ./genesis/genesis.json
+ ${PROJECT_DIR}/build/bin/$Bin_NAME --datadir ./nodes/2 init ./genesis/genesis.json
+ ${PROJECT_DIR}/build/bin/$Bin_NAME --datadir ./nodes/3 init ./genesis/genesis.json
+else
+ wallet1=$(${PROJECT_DIR}/build/bin/$Bin_NAME account list --datadir ./nodes/1 | head -n 1 | awk -v FS="({|})" '{print $2}')
+ wallet2=$(${PROJECT_DIR}/build/bin/$Bin_NAME account list --datadir ./nodes/2 | head -n 1 | awk -v FS="({|})" '{print $2}')
+ wallet3=$(${PROJECT_DIR}/build/bin/$Bin_NAME account list --datadir ./nodes/3 | head -n 1 | awk -v FS="({|})" '{print $2}')
+fi
+
+VERBOSITY=3
+GASPRICE="1"
+networkid=50
+
+
+echo Starting the bootnode ...
+${PROJECT_DIR}/build/bin/bootnode -nodekey ./bootnode.key --addr 0.0.0.0:30301 &
+child_proc=$!
+
+echo Starting the nodes ...
+${PROJECT_DIR}/build/bin/$Bin_NAME --bootnodes "enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@78.129.229.96:30301,enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@5.152.223.199:30301,enode://d757f1a21828c9c426e26df39176053302209e3dd05e7a6c0e0eae57739e233c0fa970c9b98e010cee4817e6233c3ad3eef461cef3e731c485ed4bc08de7d0ac@37.58.56.228:30303,enode://d757f1a21828c9c426e26df39176053302209e3dd05e7a6c0e0eae57739e233c0fa970c9b98e010cee4817e6233c3ad3eef461cef3e731c485ed4bc08de7d0ac@37.58.56.228:30304,enode://ef4d512152b875de3fc3990e3e124ae55adea35c49c5df40d0c4bea9327116fcfba70b920a7c164e08f425876025cbcf2519ad5238e57c10ea205e7897926a35@45.76.113.250:30303,enode://bcda483330dc0845f521ad611bcdc8cb147a7a8008c022dba20da2ab52ae46fd6d04f3cb9b7da4e94cf81d2c61065e008a13b5f05f3b69795b0dbdd2a14bb48d@209.222.30.63:30303,enode://2edc16258f6f2e18b105362df5af89889b5dbb7b098f266c39ba1b6200e9dfa76b8fd3bc0cdefce089d9e285772ae69d549e6807b23341ac975d0c085b936f1b@139.180.131.100:30303,enode://95fc2505216570bce1f75de47289d5cdcd35eba61a3e2d89fe1690dbdc60e22d8a12fe12c54c77d87f7b56035aa9ef2021387906ac3f5b3814cd90267b64f02e@149.28.135.114:30303,enode://5fcb6aa25e9e4184f278f842581507e4180851e861a59e1a02cf62f2927ee073ba921b5cba10301043f41ed494860f0ccc7508f1058c25f8ebcd56e9f8da018b@149.28.140.203:30303,enode://3a792327abf09be1b78db697c33de653d21bb702eaf6e292899c31a59f0b9535753a34d41f088416bc3f90d25c35ecd6b79d0015c36cf10f9a27c89ecd1f7fa4@149.28.140.232:30303,enode://26def7887241597a30314a77b1a32f156bdcc92eee198b086ae7c4dc26b986a9be6d078b09e93a1f963b083885020e1edfbf6b053dcebbdd090f6dfb289b59f0@149.28.142.223:30303,enode://f35e4ff8bfca2b37297dae0524146c2e4ef20c5d95be48cabe0072334bcf77a9385bad27b9630ee5ba4de451076c2123ad06113f21e3f78387a0e6fde7ec1b0b@45.77.183.160:30303,enode://44f8256e0285d1a94a73187116772522dcf53ef3affcac171cf01ffb00ec613ba1960f1309cc9353207a8f1211e645016c6e30b9669190aac8386c78545b84b1@198.13.34.190:30303,enode://95fc2505216570bce1f75de47289d5cdcd35eba61a3e2d89fe1690dbdc60e22d8a12fe12c54c77d87f7b56035aa9ef2021387906ac3f5b3814cd90267b64f02e@139.180.218.68:30303,enode://5701cfd1d03a04a3a17076e50983397ff634ff7f00693f62f6d4d94107796b74b8e10b8ad6efbf1499ae0c6263e84594d30986c79242a37b1c9d27cddb57cdc5@207.148.71.42:30303,enode://b0bd514f1b0892ab26c1d8be59510406f7d700c74cd3cd03d3f8d0fc21b784bb2fb7bde3afacf435928ca9506decf73bd15af5a64bd5dd113b26fc91605ce397@45.77.181.79:30303,enode://95fc2505216570bce1f75de47289d5cdcd35eba61a3e2d89fe1690dbdc60e22d8a12fe12c54c77d87f7b56035aa9ef2021387906ac3f5b3814cd90267b64f02e@139.180.135.153:30303,enode://297167bcccf50a94fd2b9a1f1a372228526a95066030295ee8842e0bcaf798da751974a8b08caa9fb9764d2b2d50e64ec5a90a8b942a2a9d6b1db9d5995de3ff@139.180.143.152:30303,enode://95fc2505216570bce1f75de47289d5cdcd35eba61a3e2d89fe1690dbdc60e22d8a12fe12c54c77d87f7b56035aa9ef2021387906ac3f5b3814cd90267b64f02e@45.77.244.187:30303,enode://95fc2505216570bce1f75de47289d5cdcd35eba61a3e2d89fe1690dbdc60e22d8a12fe12c54c77d87f7b56035aa9ef2021387906ac3f5b3814cd90267b64f02e@45.76.153.161:30303,enode://3a914391c6f6ff0af000b5e614df1074c2a2db2575d6c4d02c3d96bc00ed52ba4281df45b065cbc253c2a02d0bc34272520e772ee9880b28ef107e91b86166d8@109.169.55.28:30303,enode://2953c5ea2a2829a242123e14538b137be858602da1e68beb8c7f7ec797d9d42cf4f0c76b62e98c4d5578e0eeefa42a501fdfec7079e8db206d89d037a09cde3a@109.169.55.28:30304,enode://80dee88ded07fcb0ed1f4a9db4c60c0bd0592d44656571822b479047653b0c30d84e68c83057db048d2120cd7d504fd6a70a89161c31aaf98e65cfba4a77a528@109.169.55.28:30305,enode://7e495d7e1be1fc47d62f8510249435fb3b6f279880704896cbd78e05027298ed133979a388cc0ecf51fb014a8c68438b45e4a2d82ab1ed9cf86a31e87fed32c5@78.129.229.96:30303,enode://02c155fe4b34293b50d70a10889a57d9f2434fefdf142c6d24d73df9ccff19994cb243b55e87a9349a8f87d827363f74b0b40f44d96925aaaedadb456e38c0c0@78.129.229.96:30304,enode://bc2a722d080b008132ef395763d87f491fb6adc34b5d34b698cfeeadced2d4468ee5dc09f39956b4686c88af9bf26e39bc050feb52c0976238645a0343e6049f@78.129.229.96:30305,enode://560113969268e30a430991e36fcb1a6ea8a2bc16f23bc1dabffd6f8c17649237d58d8cf554e9ce882184abdc9b3a607230123e2bcf819d4ed01ec02acee1c4c2@78.159.100.155:30303,enode://a86d3268c060323572bfeb6df76081e4668ec44cc60ff028c1685a9a683c5d6497c987b5dfade81323d08875066218a1877484396e11f400ce1c2c9bd343c935@78.159.100.155:30304,enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@127.0.0.1:30301,enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@78.129.229.96:30301,enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@5.152.223.199:30301" --syncmode "full" --datadir ./nodes/1 --networkid "${networkid}" --port 30303 --rpc --rpccorsdomain "*" --ws --wsaddr="0.0.0.0" --wsorigins "*" --wsport 8555 --rpcaddr 0.0.0.0 --rpcport 8545 --rpcvhosts "*" --unlock "${wallet1}" --password ./.pwd --mine --gasprice "${GASPRICE}" --targetgaslimit "420000000" --verbosity ${VERBOSITY} --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3,XDPoS --ethstats "XinFin-MasterNode-01:xinfin_xdpos_hybrid_network_stats@stats.xinfin.network:3000" &
+child_proc="$child_proc $!"
+${PROJECT_DIR}/build/bin/$Bin_NAME --bootnodes "enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@78.129.229.96:30301,enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@5.152.223.199:30301,enode://d757f1a21828c9c426e26df39176053302209e3dd05e7a6c0e0eae57739e233c0fa970c9b98e010cee4817e6233c3ad3eef461cef3e731c485ed4bc08de7d0ac@37.58.56.228:30303,enode://d757f1a21828c9c426e26df39176053302209e3dd05e7a6c0e0eae57739e233c0fa970c9b98e010cee4817e6233c3ad3eef461cef3e731c485ed4bc08de7d0ac@37.58.56.228:30304,enode://ef4d512152b875de3fc3990e3e124ae55adea35c49c5df40d0c4bea9327116fcfba70b920a7c164e08f425876025cbcf2519ad5238e57c10ea205e7897926a35@45.76.113.250:30303,enode://bcda483330dc0845f521ad611bcdc8cb147a7a8008c022dba20da2ab52ae46fd6d04f3cb9b7da4e94cf81d2c61065e008a13b5f05f3b69795b0dbdd2a14bb48d@209.222.30.63:30303,enode://2edc16258f6f2e18b105362df5af89889b5dbb7b098f266c39ba1b6200e9dfa76b8fd3bc0cdefce089d9e285772ae69d549e6807b23341ac975d0c085b936f1b@139.180.131.100:30303,enode://95fc2505216570bce1f75de47289d5cdcd35eba61a3e2d89fe1690dbdc60e22d8a12fe12c54c77d87f7b56035aa9ef2021387906ac3f5b3814cd90267b64f02e@149.28.135.114:30303,enode://5fcb6aa25e9e4184f278f842581507e4180851e861a59e1a02cf62f2927ee073ba921b5cba10301043f41ed494860f0ccc7508f1058c25f8ebcd56e9f8da018b@149.28.140.203:30303,enode://3a792327abf09be1b78db697c33de653d21bb702eaf6e292899c31a59f0b9535753a34d41f088416bc3f90d25c35ecd6b79d0015c36cf10f9a27c89ecd1f7fa4@149.28.140.232:30303,enode://26def7887241597a30314a77b1a32f156bdcc92eee198b086ae7c4dc26b986a9be6d078b09e93a1f963b083885020e1edfbf6b053dcebbdd090f6dfb289b59f0@149.28.142.223:30303,enode://f35e4ff8bfca2b37297dae0524146c2e4ef20c5d95be48cabe0072334bcf77a9385bad27b9630ee5ba4de451076c2123ad06113f21e3f78387a0e6fde7ec1b0b@45.77.183.160:30303,enode://44f8256e0285d1a94a73187116772522dcf53ef3affcac171cf01ffb00ec613ba1960f1309cc9353207a8f1211e645016c6e30b9669190aac8386c78545b84b1@198.13.34.190:30303,enode://95fc2505216570bce1f75de47289d5cdcd35eba61a3e2d89fe1690dbdc60e22d8a12fe12c54c77d87f7b56035aa9ef2021387906ac3f5b3814cd90267b64f02e@139.180.218.68:30303,enode://5701cfd1d03a04a3a17076e50983397ff634ff7f00693f62f6d4d94107796b74b8e10b8ad6efbf1499ae0c6263e84594d30986c79242a37b1c9d27cddb57cdc5@207.148.71.42:30303,enode://b0bd514f1b0892ab26c1d8be59510406f7d700c74cd3cd03d3f8d0fc21b784bb2fb7bde3afacf435928ca9506decf73bd15af5a64bd5dd113b26fc91605ce397@45.77.181.79:30303,enode://95fc2505216570bce1f75de47289d5cdcd35eba61a3e2d89fe1690dbdc60e22d8a12fe12c54c77d87f7b56035aa9ef2021387906ac3f5b3814cd90267b64f02e@139.180.135.153:30303,enode://297167bcccf50a94fd2b9a1f1a372228526a95066030295ee8842e0bcaf798da751974a8b08caa9fb9764d2b2d50e64ec5a90a8b942a2a9d6b1db9d5995de3ff@139.180.143.152:30303,enode://95fc2505216570bce1f75de47289d5cdcd35eba61a3e2d89fe1690dbdc60e22d8a12fe12c54c77d87f7b56035aa9ef2021387906ac3f5b3814cd90267b64f02e@45.77.244.187:30303,enode://95fc2505216570bce1f75de47289d5cdcd35eba61a3e2d89fe1690dbdc60e22d8a12fe12c54c77d87f7b56035aa9ef2021387906ac3f5b3814cd90267b64f02e@45.76.153.161:30303,enode://3a914391c6f6ff0af000b5e614df1074c2a2db2575d6c4d02c3d96bc00ed52ba4281df45b065cbc253c2a02d0bc34272520e772ee9880b28ef107e91b86166d8@109.169.55.28:30303,enode://2953c5ea2a2829a242123e14538b137be858602da1e68beb8c7f7ec797d9d42cf4f0c76b62e98c4d5578e0eeefa42a501fdfec7079e8db206d89d037a09cde3a@109.169.55.28:30304,enode://80dee88ded07fcb0ed1f4a9db4c60c0bd0592d44656571822b479047653b0c30d84e68c83057db048d2120cd7d504fd6a70a89161c31aaf98e65cfba4a77a528@109.169.55.28:30305,enode://7e495d7e1be1fc47d62f8510249435fb3b6f279880704896cbd78e05027298ed133979a388cc0ecf51fb014a8c68438b45e4a2d82ab1ed9cf86a31e87fed32c5@78.129.229.96:30303,enode://02c155fe4b34293b50d70a10889a57d9f2434fefdf142c6d24d73df9ccff19994cb243b55e87a9349a8f87d827363f74b0b40f44d96925aaaedadb456e38c0c0@78.129.229.96:30304,enode://bc2a722d080b008132ef395763d87f491fb6adc34b5d34b698cfeeadced2d4468ee5dc09f39956b4686c88af9bf26e39bc050feb52c0976238645a0343e6049f@78.129.229.96:30305,enode://560113969268e30a430991e36fcb1a6ea8a2bc16f23bc1dabffd6f8c17649237d58d8cf554e9ce882184abdc9b3a607230123e2bcf819d4ed01ec02acee1c4c2@78.159.100.155:30303,enode://a86d3268c060323572bfeb6df76081e4668ec44cc60ff028c1685a9a683c5d6497c987b5dfade81323d08875066218a1877484396e11f400ce1c2c9bd343c935@78.159.100.155:30304,enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@127.0.0.1:30301,enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@78.129.229.96:30301,enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@5.152.223.199:30301" --syncmode "full" --datadir ./nodes/2 --networkid "${networkid}" --port 30304 --rpc --rpccorsdomain "*" --ws --wsaddr="0.0.0.0" --wsorigins "*" --wsport 8556 --rpcaddr 0.0.0.0 --rpcport 8546 --rpcvhosts "*" --unlock "${wallet2}" --password ./.pwd --mine --gasprice "${GASPRICE}" --targetgaslimit "420000000" --verbosity ${VERBOSITY} --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3,XDPoS --ethstats "XinFin-MasterNode-02:xinfin_xdpos_hybrid_network_stats@stats.xinfin.network:3000" &
+child_proc="$child_proc $!"
+${PROJECT_DIR}/build/bin/$Bin_NAME --bootnodes "enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@78.129.229.96:30301,enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@5.152.223.199:30301,enode://d757f1a21828c9c426e26df39176053302209e3dd05e7a6c0e0eae57739e233c0fa970c9b98e010cee4817e6233c3ad3eef461cef3e731c485ed4bc08de7d0ac@37.58.56.228:30303,enode://d757f1a21828c9c426e26df39176053302209e3dd05e7a6c0e0eae57739e233c0fa970c9b98e010cee4817e6233c3ad3eef461cef3e731c485ed4bc08de7d0ac@37.58.56.228:30304,enode://ef4d512152b875de3fc3990e3e124ae55adea35c49c5df40d0c4bea9327116fcfba70b920a7c164e08f425876025cbcf2519ad5238e57c10ea205e7897926a35@45.76.113.250:30303,enode://bcda483330dc0845f521ad611bcdc8cb147a7a8008c022dba20da2ab52ae46fd6d04f3cb9b7da4e94cf81d2c61065e008a13b5f05f3b69795b0dbdd2a14bb48d@209.222.30.63:30303,enode://2edc16258f6f2e18b105362df5af89889b5dbb7b098f266c39ba1b6200e9dfa76b8fd3bc0cdefce089d9e285772ae69d549e6807b23341ac975d0c085b936f1b@139.180.131.100:30303,enode://95fc2505216570bce1f75de47289d5cdcd35eba61a3e2d89fe1690dbdc60e22d8a12fe12c54c77d87f7b56035aa9ef2021387906ac3f5b3814cd90267b64f02e@149.28.135.114:30303,enode://5fcb6aa25e9e4184f278f842581507e4180851e861a59e1a02cf62f2927ee073ba921b5cba10301043f41ed494860f0ccc7508f1058c25f8ebcd56e9f8da018b@149.28.140.203:30303,enode://3a792327abf09be1b78db697c33de653d21bb702eaf6e292899c31a59f0b9535753a34d41f088416bc3f90d25c35ecd6b79d0015c36cf10f9a27c89ecd1f7fa4@149.28.140.232:30303,enode://26def7887241597a30314a77b1a32f156bdcc92eee198b086ae7c4dc26b986a9be6d078b09e93a1f963b083885020e1edfbf6b053dcebbdd090f6dfb289b59f0@149.28.142.223:30303,enode://f35e4ff8bfca2b37297dae0524146c2e4ef20c5d95be48cabe0072334bcf77a9385bad27b9630ee5ba4de451076c2123ad06113f21e3f78387a0e6fde7ec1b0b@45.77.183.160:30303,enode://44f8256e0285d1a94a73187116772522dcf53ef3affcac171cf01ffb00ec613ba1960f1309cc9353207a8f1211e645016c6e30b9669190aac8386c78545b84b1@198.13.34.190:30303,enode://95fc2505216570bce1f75de47289d5cdcd35eba61a3e2d89fe1690dbdc60e22d8a12fe12c54c77d87f7b56035aa9ef2021387906ac3f5b3814cd90267b64f02e@139.180.218.68:30303,enode://5701cfd1d03a04a3a17076e50983397ff634ff7f00693f62f6d4d94107796b74b8e10b8ad6efbf1499ae0c6263e84594d30986c79242a37b1c9d27cddb57cdc5@207.148.71.42:30303,enode://b0bd514f1b0892ab26c1d8be59510406f7d700c74cd3cd03d3f8d0fc21b784bb2fb7bde3afacf435928ca9506decf73bd15af5a64bd5dd113b26fc91605ce397@45.77.181.79:30303,enode://95fc2505216570bce1f75de47289d5cdcd35eba61a3e2d89fe1690dbdc60e22d8a12fe12c54c77d87f7b56035aa9ef2021387906ac3f5b3814cd90267b64f02e@139.180.135.153:30303,enode://297167bcccf50a94fd2b9a1f1a372228526a95066030295ee8842e0bcaf798da751974a8b08caa9fb9764d2b2d50e64ec5a90a8b942a2a9d6b1db9d5995de3ff@139.180.143.152:30303,enode://95fc2505216570bce1f75de47289d5cdcd35eba61a3e2d89fe1690dbdc60e22d8a12fe12c54c77d87f7b56035aa9ef2021387906ac3f5b3814cd90267b64f02e@45.77.244.187:30303,enode://95fc2505216570bce1f75de47289d5cdcd35eba61a3e2d89fe1690dbdc60e22d8a12fe12c54c77d87f7b56035aa9ef2021387906ac3f5b3814cd90267b64f02e@45.76.153.161:30303,enode://3a914391c6f6ff0af000b5e614df1074c2a2db2575d6c4d02c3d96bc00ed52ba4281df45b065cbc253c2a02d0bc34272520e772ee9880b28ef107e91b86166d8@109.169.55.28:30303,enode://2953c5ea2a2829a242123e14538b137be858602da1e68beb8c7f7ec797d9d42cf4f0c76b62e98c4d5578e0eeefa42a501fdfec7079e8db206d89d037a09cde3a@109.169.55.28:30304,enode://80dee88ded07fcb0ed1f4a9db4c60c0bd0592d44656571822b479047653b0c30d84e68c83057db048d2120cd7d504fd6a70a89161c31aaf98e65cfba4a77a528@109.169.55.28:30305,enode://7e495d7e1be1fc47d62f8510249435fb3b6f279880704896cbd78e05027298ed133979a388cc0ecf51fb014a8c68438b45e4a2d82ab1ed9cf86a31e87fed32c5@78.129.229.96:30303,enode://02c155fe4b34293b50d70a10889a57d9f2434fefdf142c6d24d73df9ccff19994cb243b55e87a9349a8f87d827363f74b0b40f44d96925aaaedadb456e38c0c0@78.129.229.96:30304,enode://bc2a722d080b008132ef395763d87f491fb6adc34b5d34b698cfeeadced2d4468ee5dc09f39956b4686c88af9bf26e39bc050feb52c0976238645a0343e6049f@78.129.229.96:30305,enode://560113969268e30a430991e36fcb1a6ea8a2bc16f23bc1dabffd6f8c17649237d58d8cf554e9ce882184abdc9b3a607230123e2bcf819d4ed01ec02acee1c4c2@78.159.100.155:30303,enode://a86d3268c060323572bfeb6df76081e4668ec44cc60ff028c1685a9a683c5d6497c987b5dfade81323d08875066218a1877484396e11f400ce1c2c9bd343c935@78.159.100.155:30304,enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@127.0.0.1:30301,enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@78.129.229.96:30301,enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@5.152.223.199:30301" --syncmode "full" --datadir ./nodes/3 --networkid "${networkid}" --port 30305 --rpc --rpccorsdomain "*" --ws --wsaddr="0.0.0.0" --wsorigins "*" --wsport 8557 --rpcaddr 0.0.0.0 --rpcport 8547 --rpcvhosts "*" --unlock "${wallet3}" --password ./.pwd --mine --gasprice "${GASPRICE}" --targetgaslimit "420000000" --verbosity ${VERBOSITY} --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3,XDPoS --ethstats "XinFin-MasterNode-03:xinfin_xdpos_hybrid_network_stats@stats.xinfin.network:3000"
+```
+{% endcode %}
+
+
+
+**Launch the setup script**
+
+```
+ bash run.sh
+```
+
+
+
+
+
+
+
+
+
diff --git a/subnets/deploy-a-subnet.md b/subnets/deploy-a-subnet.md
new file mode 100644
index 00000000..d7910e15
--- /dev/null
+++ b/subnets/deploy-a-subnet.md
@@ -0,0 +1,3 @@
+# Deploy a subnet
+
+####
diff --git a/subnets/requirements.md b/subnets/requirements.md
new file mode 100644
index 00000000..c4a55bf4
--- /dev/null
+++ b/subnets/requirements.md
@@ -0,0 +1,2 @@
+# Requirements
+
From e978e60c7a241e7721a88ff53977a7902d5a046c Mon Sep 17 00:00:00 2001
From: Salomon Morales
Date: Sun, 12 Feb 2023 21:51:43 +0000
Subject: [PATCH 012/115] GITBOOK-142: No subject
---
.gitbook/assets/Node1.JPG | Bin 0 -> 116663 bytes
.gitbook/assets/node1.JPG | Bin 0 -> 88371 bytes
.gitbook/assets/node2.JPG | Bin 0 -> 77706 bytes
.gitbook/assets/node3.JPG | Bin 0 -> 106036 bytes
.gitbook/assets/node4.JPG | Bin 0 -> 33755 bytes
.gitbook/assets/node5.JPG | Bin 0 -> 31910 bytes
SUMMARY.md | 1 +
how-to-stake-an-xdc-masternode.md | 38 ++++++++++++++++++++++++++++++
8 files changed, 39 insertions(+)
create mode 100644 .gitbook/assets/Node1.JPG
create mode 100644 .gitbook/assets/node1.JPG
create mode 100644 .gitbook/assets/node2.JPG
create mode 100644 .gitbook/assets/node3.JPG
create mode 100644 .gitbook/assets/node4.JPG
create mode 100644 .gitbook/assets/node5.JPG
create mode 100644 how-to-stake-an-xdc-masternode.md
diff --git a/.gitbook/assets/Node1.JPG b/.gitbook/assets/Node1.JPG
new file mode 100644
index 0000000000000000000000000000000000000000..2b425dfc360baae0089d351adafda59d0bb34e95
GIT binary patch
literal 116663
zcmeFZ1z23cwl3H>!AWok5Hx|{?vMlz?ldkz8h0llfdqF5)&zGt5L^NThhU92?%Fs6
zZKiYd&YAn(chB56^UZuO8;V`Ky1HtwzwBRYRdGLazYHK!l2eoeprD`t;*dXp`xT;V
zSs%MM0Dy`LfDHfuU<1%m!~m$s7!mS8>7yM09T`VK#tk#Ge%}G~$d91AGyp7Q8Xodl
z5*YwAyU0J-zhi%{KM4Fm;12?S5cq?@9|Zn)L_o{j!P(K-iC)Fo&D_D-9RR?HL;DM(
zAVD&R;yCnw#9I>L{}M;z7X$zj68;(gC%eGT{EgrrcJaSsKl&r{9|Zm&@CSiE2>e0d
zp9t`B^YV#u^NRBD((?$2B7gb00smPV0H6gh2RHzn0glMvgfv^IAn$H}NwWqZSqaki
zfy-d);o&06#pUGAX>R3gVa;jj?8xO~?!v{x$;|~2m-2Bjw**;x&|6sB*f~kC9yYhJ
z(%V@{u<8k@aI3hyw6?WV@N=`)@>A8e^aELnSg}e;;^T<>i269XI9hv{)B89&IJt}Z
zNHF}RbWvpdcQO})q_~^a8&S2M@3I-tFJTbNvS6KfLJw+Bg3%p(QD9WhrX;``w-0{#w13wd;ScwH@pv|AkurRZwL5Un9sG
zklpXWg9qYV|FQD_D;j@ELH0i6_x{mWk>8~Mf8qL5$-f2iAGrR&^=~2YZ)N_|yZ*rS
zZz1q+W&YE<{(lD7Kl!e;6O!b5BiZcz9N;AY3j+fa104$!0}~qy3mb^C@DxO$f;>rpHM$$eoRimz{$Y;^cnkeb}D))j_H`
zcErSI;TG}$hm4$pl8Tvy_31M`Uv~_g#^bHIxt*qbJ*xK2<
zdw6Fi(i*l*T3aL0igX=tba)MFLDth5-5BJQ=1^r0m0M=odMwEc~{94=}t398xtXY0QN8@Gel$
z9fj-P14e+cH#@;UVlQ8n2X9sM-kr6r0Bdx?up)OUOSP)ddjNKF?Cp8OJ>Yxl?bCa}
z2c=$w-+b_rGJ>>OmKIjza>0K?VfsHVNdsQ$P57sv{}M)71wLNTUag2tN*0^f%Y1ll
z*k`{gV~XeQ0lhyEQUefO_r%0z{twzZaT>Cu7@;H@(infj|6&YuI7~HExL&91420z2
zHXLW44goZevBJw+r0h?O6f%;m!W=MY^X~yl$IcG}EL&Q#*2YO{%$CK|bZ$w4wTxn;
zTJ&63jSb~a^bg)Cge6y9G&QEh%=EbeCZ@~2V(CI|LP)nxsWnC=Ls(7e$8HYwMy|F#sK
zwRBJqse%CO8Y2!C-qgEnFJMEWL_Hu*moL}CITgn}A9yP?peGJ;NiS)PB1pF^TuRfo
z!g{T#4%AYB;2~KOJ+SA0s|VTiBWmvfivl?YC&3lLzoPkB1S6gn(*GAHFI45=%S+SV
zE1lgu=X(Gh?&UpztyM7^*`F26Wl7Xg{sbfjr0>dnwmLUK&97DzI#BRMd>}@$IdvXF!YS$
z%@H`mOr2184G%;fp8FjtA-wLJlzbPJTA7^{tB~8Wgdp?KO2AOeo+>a%QvmHWrd1
zi`Mg9s-br_0CVg(dr2*Jt1flQ?yUJr>V*B~5yf{&{p(@6+xQ(4z4QV|cc3%xU~u6!
zkI?N`Z9Ow7)_cHcDAz5$q+kQUI6%5Fie{@nwBa_*_5vD=N4MOjj`*2JxVmcADpGJI
zw-mm^KkX5%tS}HEnj%cPC3RE`-o6KPEp=Z{E+5{^+aRtvR88L@$QPPGS(;v~O#Lp6
zlJoR=FkSzb$AqQUWvgBFJ6P8>-h3cY>+eBh#W2~J<}IDxO_1nXuL)`GNX9C@7-O+=
zsGHPb0tl1ty$OEQ#(pL9mau;+-A8oYPk|4w+D-^w
z=ZX#Iw=$Am^~Wn8YjwEX-MR4%ODZrsuNRgK9w&BGZCRh4oW>^1Uj16f+0H%k4*N2<
z;S;Q^*-E|dx^>!PKX1sAj47VQJ1kMeXx$VQlmsNYhBV#-KKmn!)+)XSz_%fHHLIp;
z-XF%k=HB&|&c*Kj_}oTagQebI0CFhG0owLST|I1lD9rFtQd=QyuU2|UG6vb`!`}}t
z8Lo%*>pBOwwC(}5;tP^|`UAKxR~GE1g$LS;u16)g#LIuo{h*pC75mh9`&M9wL}Pz1
zSZZ0S(t3fr?Mmz(z&K=e`K=i9Zu;GM7{zX1=RLrRf8-Kqn0<%cRKLD-E9>V-;xD>%
zdV2Ko`oQ!aART!RK#SirJ*umfx+eB??r*z{(7CKFA){`=FMButwij6dcitGgp_ki|w-{t_Ll;@PUbQN;>Yb=a+vd=C@3cEVthM4t45`?qUtf%HCv9h$o
z^`{8b>rJCyKkmkZ*GGg+Vor`^#O(NVQLxd%v8_TDw8AI`ok(M3r*
zl6h>8HNIb9Ty4<4w>|cZZs0dMKauD>IghG1e4z{tzRT$i{;_ssbBE4?d>I3&9|fk7
z-yc|`?=h?8)MPN8DD7mtf@UdwPkS@q_ulCP9W)n7bU-ie0be+??g4MZ5hOt3g}{;9
zZaDA9djRJy*Nval?Yob3-OdbpOsTYuHzu^v?S3b5ZDl-6JpGto6KIcA8nes9#WL9c|BlgaJN}Ar7U6?
z1Z8hsy$8H?0Vlvwl_G{@6>d&VlBGW})!
z24FG6GaZa71ew}u#c!w<*M{-h|4WkG%-B?Ox`Kh=r5uM-Q
z<0|m(3WixTZg^7CCq@w>+DKiR((R1W0-j&F<<~W&KzG?Ay=I?tKBn+8bHfKtIm6F6
z6b~GqTUN{615#|=6Zf_Wp~ZS*9J<9Pw6QN|0%UVyBfwP97TJ}CJgQt?m}xtvAabak
zp>N%d!;$3qk<%F*SLN%GYDDpm?w5=6=+yafry;>K*~O2`$}Z*Y2;aBxH+^sOaFnX&
zWDJ9nixUq|^_Fa9zxJEXx>Y~g82Q-Z?z=^vfIBV3t+XZfo>neUX6>YsO4rkuD|hbt
zMAYWU-P8XbU}8gOxJcHVKG-#-Iak(ridy}JDOsErYwJ>1#Sg13Q>>_COSbJNb;l1Fn!ZMWd~O?N
zgS2~ibU|Aq`cHEs0RIeeaiz*c07|BdFBrKEaQRh%B=X#8rJ6*Ir0?w-b!Bw2!b}M5
zlwjhD=$*Q$=Pcu&d0zbV4rMHMLZOS#v8R5VOfun_AmB42$~{n>86sgf0npHf*8`RGxvXO^sYj8#|pX@yhI1BC5(e~9PSwv!Tglt7Q0s;UMZOsK4
z{4Q=~w(@TY3@>~g@G=82l>f>y|3{oBjeiU%eQKmoB}xTBem}|>;Ijh1$9YgN$X?*sJ47uM7>)Cc^nGr1W*Odl
zWliqfh!E;IP-Gf>IgKf0{vGeL{;2pk!kk|Ic5uYgeB{S}Q%6g8V9A9Qb{AQarh<>*
zwD5u;Ym0JjX$hG!Z5YUv1>7M^qDjfzb{oL8c3XO`QGXAJ4ZRIcHp%Y^iC{~yv
zRTZHCzrC`tD5m^c_HN?(jty7^%sA6aR6OP~_8O?jw;Z#Onn<5H`qc$&zB9z-kb^$t
zq>-zBnG91aX4*O{Ra*6?)LLgV)yl_jk{2mjhfCGEzARDSavFu!c*<26)95d4&x(A?a
z+yho^(Qn+X;O5hXjJ^j
zimolPn3*M@y>6ttHESB~Lo`Q5VPSDvzlh&s%y2}#ZUVgrs>au!oRhf0UfZkDSG@1(
z|5z3Dx!egIVt>Poq5$(fr#X{&iV7z+TvD%VYHF;nPYkFlCo`{!&X0PRX@($u^A?9)
z!gE0Y{-hBY)yaPku!*h{8e(ycvYhbTF+?_x`hszXwbPrXWQ!;wT%H3T)WW~nPk!4`
z!cI1xm)kTYJ&fytazA##1jW}M4;Oi(4uMv}H^LEn<+pUVZg0hu*kh5ac`wrTk)yhX
z_>JBL>F74>!*vRnlXKsyD$!L7FFLU|U^$o#&?ZZ&JFQjI+SpKEm+CP!RANJkHnBo#OBmNW}*heu^Z}`p8m2{z8j|~3(nYySTb{`}C@+f+e
zrWm@Mm#_{cD-22YE>&+u?g287kYwT{_?RDMbWGh~ac-Ba#NC>A2={LKWw+YD=&?GE
zaw~BD=CV)iTzH(j)P>S4iC%hClQZ9BU4yWWb@L!g^Bu*$vX-AjlT?aCy1kNhSyp68
zIP$|%P27W>OajTG2tci@
zjJLnD`I}$fZsqE7yu*P~6&h{Ff{BILl1m<=cRAvH9ijc~XSltiqnH(>$%U60@{^U~
zk+|y#MplgMPo$*VZH~(P!b+?QfLE~40qGCRWa3q4XeGB#Q71_=ihMpQPukczI8AP7
zBvP|8T25dB(xLyMyRc_X1%L`|Qww1mHfgEUQ8?6gXCm}A6cX2?ShBL(;{s0wK%|Ye
zQqPzT6gr@@%c2D!&_tCneW&h6hT^;%
zmU*wnR3#F=|FbHO?oCbv11h?Dvc1GpGG2ENRToV_GFZBB@AQk(bg52%?Fmk74uORq
zq!G-Idt9%w9njMA+%dMgxoGUu9nzDg5Y$j(OI!Hm&C9J!@W;6M)3=ydA`q2vkLJg;
zJz^5PQ)0G^>ZFWDL97!uU{GSZXLb{u_Rcitj39=bBf@hH&Q_DnH5)xSEu?!sYv65@
z9sHy280%9;a7=)X_!zh@g^q#nC(1n_1|cwNM~4@{oOenVPx>=!z2)v$>b;8;im|oz
zo+RVA2Z>g(TJ5|wgG}R0pj1g&3~iDz+pat%K(0laCJv#H4Q(N9^GDqBn2Z;)^QxS+SmTFDy76930>Yy
z5tOPtalRyg-DinIk84{Jf6iG(D>qvT1FWV9Z&`zAkQ&!Jq=x1je3=f|wk_ob36k>~
z_Tt^7pYSoES>o@Cg5~L=O^}0{Ez_?eDZRYOUKM{`>G3Lk2+Com+4m9^U}3gfn2NrT50Ox=8x(l6)OeTE7I|g
zya54`Lv4MIV~{l5E3x5S;&>5lZPfM;zgkF8QC{fJDq)>|N|VPH=aE-Ir9YP)B{`Ur
zyS%`>qmUYr8ThFI?yJCSwAe2K+k(^FCO~;tJ6<)s$VR5<_w0n~vhu|{Q+~BkDTc{4
z-hwAl;%=NWNd5cJ#Myh<^x>rtTqv8+(+2eVs-nP%^KNFB1l*RhRw9tK3td_?jlF$T
zrPXd(Q*@Jd;n*Mru9Omk@cTuR{=8)GnKI!SSC*3;3C0@qv|aKOJf|%K-vi#|Ha!s@
z79X2Aai#EUu&+$kv12T(lwVa1@mzXfBuhbSQPLBvHi5HOQY}~AGuD?AABHW_ZRjYL
zmsM8Ax4OgVlW)7B8S|m+*)BF**Q2LeMRWFCJ9&RfdYnmkepmEewn_5N(xdOx^T4J4
zk{upO^be^rw?S)56W$P3`Z7{887y>S==YFh{i)Eg4ON27^5Obb!sy@??#VBLF0GXr
zHbgN~n9C3}rnRUetWlh?W1(0FalK`Bd@1evM$v^BLF2atbXEPszDBfJvM&5u7wU@4
zqb5+pt56Rx8kA-7*1(?O#UR=PiW{U?<5rcOQEBYZGo#Ac{6TzMcoQ3;roY};FoF03
z@-UC{bn6AN+wRY9y^mdI{BSx+jb9M3dx2hLBvoFBfs|eCY)EkXqEWY|3Uecl2^IdS
zGDQH`<1S-M2CY}l>fS}v&Sy}>9-t&h(XvA-K|L^)&4R+Yk%G#bL6NR12+j4HxF6k*
zq&lkkld`h2)crTm$>$q&QO^<>UMjS2`JM^1Rhn{UkfvmKJJlx?ZoQKs~h_YWUvO4`zdJP_XynD#%8hW
ze9Jpg&Ea-%EfZT+Tr->{nfOiQCmn&*^Mv+Qu|@nH&Ad>6Cg~v6@#fLuBV|A
zP8&3p$^-Hnt}jHL)+Nstmqr>FKNZinP3WeZ&h63)LJu9YJ$UV)!jjoSjJxcXisLL_
zCj=BXZD*Z1(W^q4;&@_w_6$-a9|nr`5EjoV(#=o_b)jeG38`c9#N63&Ja1`}`QA3I
zMHyhsvG2A>NHn(tZ*0kU1Zpv(6{_P)ghLA_I1g&qR?2Stzu7u5v5{Kp68E7D;+^kA
zQH{Tsn?7q+Mt4f9cXe
z9vYR+y+%QUGS_N2Aui?`xT=gV|1+FHI&7C)ZMaX-$aRGE`!kP2{6U-5!68*ejf(vF
zspAm0sLMq)+Qk|!sokYb!olmdD%SV6{_AMRbZX9a|k(9;VW25WaIps%c8J
zJM9;gS$FujVm}pb?eYTi^;8kYwM#h|>0+ELE1LNq;1XL_e4RaHLc2$>#
zAX|@`h!tjk|8Z~k=V@9`=(hkiu+Z_1YtwV;y;DBVjOn9;wnC%bY3HEhxsi{==$xwD
z4KzUlP+P7**P_UU7dy;C`U%3hXjW`~PlX5RG*tvo6%+QlQiSdSP29k4Hc>(Ehn;9>
z6ouP{I>XV-lf?-_m?LDeBXH
zr__96%*WAds*$G2956_~MJH#(O4r)f=HUZIdH87w#dVNpQKjwa?nA?conH*F>!Gw<
zFXMssC{pun`w!QuZRH>8raAd9%iovv)!A>Xcl1#@z2A8;PiX>$9R<9apfRn|dG|Pv
zm}~e$CX2u2bcK5BF+q-_4aYo!p(f;5kx?ar