diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 7dc03b99..00000000 Binary files a/.DS_Store and /dev/null differ 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..a9497da4 --- /dev/null +++ b/.gitbook/assets/.gitignore @@ -0,0 +1,1852 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + XDC_Python_SDK_V1/.gitignore at 66fa7e5dea1afa40be77f29200876e9ab0088403 · XDCFoundation/XDC_Python_SDK_V1 · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + +
+ +
+ + + + + + + +
+ + + + + + +
+ + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + +
+ + + + + + + +Permalink + +
+ +
+
+ + + 66fa7e5dea + + + + +
+
+
+ Switch branches/tags + +
+ + + +
+ +
+ +
+ + +
+ +
+ + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+ +
+ +
+ + +
+ +
+
+
+

Name already in use

+
+
+ +
+
+
+
+ +
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? +
+ +
+
+ + +
+
+ + + + Go to file + +
+ + + + +
+
+
+ + + + + + + + + +
+ +
+
+
 
+
+ +
+
 
+ Cannot retrieve contributors at this time +
+
+ + + + + + + + + +
+ +
+ + +
+ + 50 lines (37 sloc) + + 624 Bytes +
+ +
+ + + + +
+ +
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+ + + +
+
+ + + +
+
+ +
+ +
+
+ + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
# These are some examples of commonly ignored file patterns.
# You should customize this list as applicable to your project.
# Learn more about .gitignore:
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore
+
# Node artifact files
node_modules/
dist/
+
# Compiled Java class files
*.class
+
# Compiled Python bytecode
*.py[cod]
+
# Log files
*.log
+
# Package files
*.jar
+
# Maven
target/
dist/
+
# JetBrains IDE
.idea/
+
# Unit test reports
TEST*.xml
+
# Generated by MacOS
.DS_Store
+
# Generated by Windows
Thumbs.db
+
# Applications
*.app
*.exe
*.war
+
# Large media files
*.mp4
*.tiff
*.avi
*.flv
*.mov
*.wmv
+
+
+ + + +
+ +
+ + + + +
+ + +
+ + +
+
+ + + +
+ +
+ + +
+ +
+ + +
+
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + diff --git a/.gitbook/assets/.gitignore (1) b/.gitbook/assets/.gitignore (1) new file mode 100644 index 00000000..b24d71e2 --- /dev/null +++ b/.gitbook/assets/.gitignore (1) @@ -0,0 +1,50 @@ +# These are some examples of commonly ignored file patterns. +# You should customize this list as applicable to your project. +# Learn more about .gitignore: +# https://www.atlassian.com/git/tutorials/saving-changes/gitignore + +# Node artifact files +node_modules/ +dist/ + +# Compiled Java class files +*.class + +# Compiled Python bytecode +*.py[cod] + +# Log files +*.log + +# Package files +*.jar + +# Maven +target/ +dist/ + +# JetBrains IDE +.idea/ + +# Unit test reports +TEST*.xml + +# Generated by MacOS +.DS_Store + +# Generated by Windows +Thumbs.db + +# Applications +*.app +*.exe +*.war + +# Large media files +*.mp4 +*.tiff +*.avi +*.flv +*.mov +*.wmv + diff --git a/.gitbook/assets/.gitignore (2) b/.gitbook/assets/.gitignore (2) new file mode 100644 index 00000000..97dba2e5 --- /dev/null +++ b/.gitbook/assets/.gitignore (2) @@ -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/LICENSE (1).txt b/.gitbook/assets/LICENSE (1).txt new file mode 100644 index 00000000..b3f85a13 --- /dev/null +++ b/.gitbook/assets/LICENSE (1).txt @@ -0,0 +1,1750 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + XDC_Python_SDK_V1/LICENSE.txt at 66fa7e5dea1afa40be77f29200876e9ab0088403 · XDCFoundation/XDC_Python_SDK_V1 · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + +
+ +
+ + + + + + + +
+ + + + + + +
+ + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + +
+ + + + + + + +Permalink + +
+ +
+
+ + + 66fa7e5dea + + + + +
+
+
+ Switch branches/tags + +
+ + + +
+ +
+ +
+ + +
+ +
+ + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+ +
+ +
+ + +
+ +
+
+
+

Name already in use

+
+
+ +
+
+
+
+ +
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? +
+ +
+
+ + +
+
+ + + + Go to file + +
+ + + + +
+
+
+ + + +
+
+
+ +

+ XDCFoundation/XDC_Python_SDK_V1 + is licensed under the +

+

MIT License

+

A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.

+
+ +
+
+

Permissions

+
    +
  • + + + Commercial use + +
  • +
  • + + + Modification + +
  • +
  • + + + Distribution + +
  • +
  • + + + Private use + +
  • +
+
+
+

Limitations

+
    +
  • + + + Liability + +
  • +
  • + + + Warranty + +
  • +
+
+
+

Conditions

+
    +
  • + + + License and copyright notice + +
  • +
+
+
+
+

+ This is not legal advice. + Learn more about repository licenses. +

+
+ + + + + + + +
+ +
+
+
 
+
+ +
+
 
+ Cannot retrieve contributors at this time +
+
+ + + + + + + + + +
+ +
+ + +
+ + 7 lines (4 sloc) + + 1.04 KB +
+ +
+ + + + +
+ +
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+ + + +
+
+ + + +
+
+ +
+ +
+
+ + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Copyright © 2022 XDC Foundation
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+ + + +
+ +
+ + + + +
+ + +
+ + +
+
+ + + +
+ +
+ + +
+ +
+ + +
+
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + diff --git a/.gitbook/assets/LICENSE.txt b/.gitbook/assets/LICENSE.txt new file mode 100644 index 00000000..7fc64099 --- /dev/null +++ b/.gitbook/assets/LICENSE.txt @@ -0,0 +1,7 @@ +Copyright © 2022 XDC Foundation + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/.gitbook/assets/MANIFEST.in b/.gitbook/assets/MANIFEST.in new file mode 100644 index 00000000..e5bb1bf4 --- /dev/null +++ b/.gitbook/assets/MANIFEST.in @@ -0,0 +1 @@ +global-include *.txt *.py *.md \ No newline at end of file diff --git a/.gitbook/assets/Node1.JPG b/.gitbook/assets/Node1.JPG new file mode 100644 index 00000000..2b425dfc Binary files /dev/null and b/.gitbook/assets/Node1.JPG differ diff --git a/.gitbook/assets/__init__.py b/.gitbook/assets/__init__.py 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/code frequency b/.gitbook/assets/code frequency new file mode 100644 index 00000000..6dce0395 --- /dev/null +++ b/.gitbook/assets/code frequency @@ -0,0 +1,1221 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Code frequency · XDCFoundation/XDC_Python_SDK_V1 · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + +
+ +
+ + + + + + + +
+ + + + + + +
+ + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Insights: XDCFoundation/XDC_Python_SDK_V1

+
+
+ + +
+ +
+
+

Code frequency over the history of + XDCFoundation/XDC_Python_SDK_V1 +

+ + +
+

+ + Additions and + Deletions per week + +

+ +
+
+ + + + +
+

Crunching the latest data, just for you. Hang tight…

+
+
+

We don’t have enough data to show anything useful.

+

It usually takes about a week to populate this graph.

+
+
+

We need at least one non-empty commit with an email to generate this graph.

+
+
+ +
+ +

We tried our best, but the graph wouldn’t load. Try reloading the page.

+ + + +
+
+
+
+ +
+
+ + +
+ +
+ + +
+
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + diff --git a/.gitbook/assets/commit activity b/.gitbook/assets/commit activity new file mode 100644 index 00000000..f659fa40 --- /dev/null +++ b/.gitbook/assets/commit activity @@ -0,0 +1,1209 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Commit Activity · XDCFoundation/XDC_Python_SDK_V1 · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + +
+ +
+ + + + + + + +
+ + + + + + +
+ + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + +
+ + + + + +

Insights: XDCFoundation/XDC_Python_SDK_V1

+
+
+ + +
+ +
+ +
+
+ + + + +
+

Crunching the latest data, just for you. Hang tight…

+
+
+

We don’t have enough data to show anything useful.

+

It usually takes about a week to populate this graph.

+
+
+

We need at least one non-empty commit with an email to generate this graph.

+
+
+ +
+ +

We tried our best, but the graph wouldn’t load. Try reloading the page.

+ + + +
+
+
+
+
+
+ +
+
+ + +
+ +
+ + +
+
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + diff --git a/.gitbook/assets/contributors b/.gitbook/assets/contributors new file mode 100644 index 00000000..618465f6 --- /dev/null +++ b/.gitbook/assets/contributors @@ -0,0 +1,1272 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Contributors to XDCFoundation/XDC_Python_SDK_V1 · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + +
+ +
+ + + + + + + +
+ + + + + + +
+ + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Insights: XDCFoundation/XDC_Python_SDK_V1

+
+
+ + +
+ + +
+
+

Loading contributions…

+ +
+ Contributions: + Commits + +
+ Filter contributions +
+
+ + + +
+
+
+
+

Contributions to main, excluding merge commits and bot accounts

+ +
+ +
+ +
+ +
+
+ + + + +
+

Crunching the latest data, just for you. Hang tight…

+
+
+

We don’t have enough data to show anything useful.

+

It usually takes about a week to populate this graph.

+
+
+

We need at least one non-empty commit with an email to generate this graph.

+
+
+ +
+ +

We tried our best, but the graph wouldn’t load. Try reloading the page.

+ + + +
+
+
+
+ +
+
+ + +
+ +
+ + +
+
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + diff --git a/.gitbook/assets/createAccount.py b/.gitbook/assets/createAccount.py new file mode 100644 index 00000000..c3d01c61 --- /dev/null +++ b/.gitbook/assets/createAccount.py @@ -0,0 +1,9 @@ +from bitcoin import random_key + + + +# Gets private key of wallet to create new account. + +def createAccount(): + privateKey = random_key() + return privateKey \ No newline at end of file diff --git a/.gitbook/assets/daily b/.gitbook/assets/daily new file mode 100644 index 00000000..bf68f189 --- /dev/null +++ b/.gitbook/assets/daily @@ -0,0 +1,1312 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Pulse · XDCFoundation/XDC_Python_SDK_V1 · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + +
+ +
+ + + + + + + +
+ + + + + + +
+ + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Insights: XDCFoundation/XDC_Python_SDK_V1

+
+
+ + +
+ +
+

April 18, 2023 April 19, 2023

+ +
+ Period: + 24 hours + +
+ Filter activity +
+ +
+
+
+
+
+
+

Overview

+
+ +
    +
  • +
    +
    +
    +
    + 0 + Active pull requests +
    +
    + +
    +
    +
    +
    + 0 + Active issues +
    +
    +
  • + +
  • +
      +
    • + + + 0 + + Merged pull requests +
    • +
    • + + + 0 + + Open pull requests +
    • +
    • + + + 0 + + Closed issues +
    • +
    • + + + 0 + + New issues +
    • +
    +
  • +
+
+ +
+ +

There hasn’t been any commit activity on XDCFoundation/XDC_Python_SDK_V1 in the last 24 hours.

+ +

Want to help out?

+

+

+

+ +
+
+ + +
+ +
+
+ + +
+ +
+ + +
+
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + diff --git a/.gitbook/assets/dependencies b/.gitbook/assets/dependencies new file mode 100644 index 00000000..8d61fb96 --- /dev/null +++ b/.gitbook/assets/dependencies @@ -0,0 +1,1255 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Dependencies · XDCFoundation/XDC_Python_SDK_V1 · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + +
+ +
+ + + + + + + +
+ + + + + + +
+ + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Insights: XDCFoundation/XDC_Python_SDK_V1

+
+
+ + +
+ + +
+
+

Dependency graph

+ + +
+ + + + + + +
+
+ + +
+ + + + + +
+ +
+
+
+ +
+
+ + +

No dependencies found.

+

+ To view your dependency graph, your repository must define dependencies in + one of the supported manifest file types, like package.json or Gemfile. +

+

+ +
+
+ +
+
+ + +
+ +
+ + +
+
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + 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/halfweekly b/.gitbook/assets/halfweekly new file mode 100644 index 00000000..8f571a17 --- /dev/null +++ b/.gitbook/assets/halfweekly @@ -0,0 +1,1312 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Pulse · XDCFoundation/XDC_Python_SDK_V1 · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + +
+ +
+ + + + + + + +
+ + + + + + +
+ + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Insights: XDCFoundation/XDC_Python_SDK_V1

+
+
+ + +
+ +
+

April 16, 2023 April 19, 2023

+ +
+ Period: + 3 days + +
+ Filter activity +
+ +
+
+
+
+
+
+

Overview

+
+ +
    +
  • +
    +
    +
    +
    + 0 + Active pull requests +
    +
    + +
    +
    +
    +
    + 0 + Active issues +
    +
    +
  • + +
  • +
      +
    • + + + 0 + + Merged pull requests +
    • +
    • + + + 0 + + Open pull requests +
    • +
    • + + + 0 + + Closed issues +
    • +
    • + + + 0 + + New issues +
    • +
    +
  • +
+
+ +
+ +

There hasn’t been any commit activity on XDCFoundation/XDC_Python_SDK_V1 in the last 3 days.

+ +

Want to help out?

+

+

+

+ +
+
+ + +
+ +
+
+ + +
+ +
+ + +
+
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + diff --git a/.gitbook/assets/image01-ubuntu-release-cycle-securing-masternode.png b/.gitbook/assets/image01-ubuntu-release-cycle-securing-masternode.png new file mode 100644 index 00000000..9dde661b Binary files /dev/null and b/.gitbook/assets/image01-ubuntu-release-cycle-securing-masternode.png differ diff --git a/.gitbook/assets/image02-brute-force-time-securing-masternode.jpg b/.gitbook/assets/image02-brute-force-time-securing-masternode.jpg new file mode 100644 index 00000000..c7c5eba9 Binary files /dev/null and b/.gitbook/assets/image02-brute-force-time-securing-masternode.jpg differ diff --git a/.gitbook/assets/image03-norton-pw-gen-securing-masternode.png b/.gitbook/assets/image03-norton-pw-gen-securing-masternode.png new file mode 100644 index 00000000..e136a875 Binary files /dev/null and b/.gitbook/assets/image03-norton-pw-gen-securing-masternode.png differ diff --git a/.gitbook/assets/image04-andromeda-securing-masternode.jpg b/.gitbook/assets/image04-andromeda-securing-masternode.jpg new file mode 100644 index 00000000..e11e45e6 Binary files /dev/null and b/.gitbook/assets/image04-andromeda-securing-masternode.jpg differ diff --git a/.gitbook/assets/image05-yml-file-securing-masternode.png b/.gitbook/assets/image05-yml-file-securing-masternode.png new file mode 100644 index 00000000..85ef8da4 Binary files /dev/null and b/.gitbook/assets/image05-yml-file-securing-masternode.png differ diff --git a/.gitbook/assets/image06-port22-securing-masternode.png b/.gitbook/assets/image06-port22-securing-masternode.png new file mode 100644 index 00000000..9045dfb8 Binary files /dev/null and b/.gitbook/assets/image06-port22-securing-masternode.png differ diff --git a/.gitbook/assets/image07-new-ssh-port-securing-masternode.png b/.gitbook/assets/image07-new-ssh-port-securing-masternode.png new file mode 100644 index 00000000..29ffaa7b Binary files /dev/null and b/.gitbook/assets/image07-new-ssh-port-securing-masternode.png differ diff --git a/.gitbook/assets/image08-ufw-logo-securing-masternode.png b/.gitbook/assets/image08-ufw-logo-securing-masternode.png new file mode 100644 index 00000000..b292f2fd Binary files /dev/null and b/.gitbook/assets/image08-ufw-logo-securing-masternode.png differ diff --git a/.gitbook/assets/image09-fail2ban-logo-securing-masternode.png b/.gitbook/assets/image09-fail2ban-logo-securing-masternode.png new file mode 100644 index 00000000..b5237603 Binary files /dev/null and b/.gitbook/assets/image09-fail2ban-logo-securing-masternode.png differ diff --git a/.gitbook/assets/image10-fail2ban-sshd-original-securing-masternode.png b/.gitbook/assets/image10-fail2ban-sshd-original-securing-masternode.png new file mode 100644 index 00000000..9324a31d Binary files /dev/null and b/.gitbook/assets/image10-fail2ban-sshd-original-securing-masternode.png differ diff --git a/.gitbook/assets/image11-fail2ban-sshd-new-securing-masternode.png b/.gitbook/assets/image11-fail2ban-sshd-new-securing-masternode.png new file mode 100644 index 00000000..c727ee30 Binary files /dev/null and b/.gitbook/assets/image11-fail2ban-sshd-new-securing-masternode.png differ diff --git a/.gitbook/assets/image14-apothem-yml-file.png b/.gitbook/assets/image14-apothem-yml-file.png new file mode 100644 index 00000000..3e0ac5c5 Binary files /dev/null and b/.gitbook/assets/image14-apothem-yml-file.png differ diff --git a/.gitbook/assets/image15-appendix-header.png b/.gitbook/assets/image15-appendix-header.png new file mode 100644 index 00000000..1c536918 Binary files /dev/null and b/.gitbook/assets/image15-appendix-header.png differ diff --git a/.gitbook/assets/image16-uptime-robot-site.png b/.gitbook/assets/image16-uptime-robot-site.png new file mode 100644 index 00000000..33a9cf64 Binary files /dev/null and b/.gitbook/assets/image16-uptime-robot-site.png differ diff --git a/.gitbook/assets/image17-UTrobot-add-new-monitor-button.png b/.gitbook/assets/image17-UTrobot-add-new-monitor-button.png new file mode 100644 index 00000000..7ef97612 Binary files /dev/null and b/.gitbook/assets/image17-UTrobot-add-new-monitor-button.png differ diff --git a/.gitbook/assets/image18-monitor-type-ping.png b/.gitbook/assets/image18-monitor-type-ping.png new file mode 100644 index 00000000..6764e0a0 Binary files /dev/null and b/.gitbook/assets/image18-monitor-type-ping.png differ diff --git a/.gitbook/assets/image19-friendly-name.png b/.gitbook/assets/image19-friendly-name.png new file mode 100644 index 00000000..a5dc64b4 Binary files /dev/null and b/.gitbook/assets/image19-friendly-name.png differ diff --git a/.gitbook/assets/image20-contacts-to-notify.png b/.gitbook/assets/image20-contacts-to-notify.png new file mode 100644 index 00000000..8cc32040 Binary files /dev/null and b/.gitbook/assets/image20-contacts-to-notify.png differ diff --git a/.gitbook/assets/image21-create-monitor.png b/.gitbook/assets/image21-create-monitor.png new file mode 100644 index 00000000..3299693b Binary files /dev/null and b/.gitbook/assets/image21-create-monitor.png differ diff --git a/.gitbook/assets/image22-locations-and-ips.png b/.gitbook/assets/image22-locations-and-ips.png new file mode 100644 index 00000000..d1186be5 Binary files /dev/null and b/.gitbook/assets/image22-locations-and-ips.png differ diff --git a/.gitbook/assets/image23-whitelisting-file-links.png b/.gitbook/assets/image23-whitelisting-file-links.png new file mode 100644 index 00000000..744afc27 Binary files /dev/null and b/.gitbook/assets/image23-whitelisting-file-links.png differ diff --git a/.gitbook/assets/image24-wget-ip-file.jpg b/.gitbook/assets/image24-wget-ip-file.jpg new file mode 100644 index 00000000..ef5383b7 Binary files /dev/null and b/.gitbook/assets/image24-wget-ip-file.jpg differ diff --git a/.gitbook/assets/image25-whitelisted-ips.png b/.gitbook/assets/image25-whitelisted-ips.png new file mode 100644 index 00000000..adeacb84 Binary files /dev/null and b/.gitbook/assets/image25-whitelisted-ips.png differ diff --git a/.gitbook/assets/image26-test-notification-setup.png b/.gitbook/assets/image26-test-notification-setup.png new file mode 100644 index 00000000..682d13c9 Binary files /dev/null and b/.gitbook/assets/image26-test-notification-setup.png differ diff --git a/.gitbook/assets/image27-nginx-logo.png b/.gitbook/assets/image27-nginx-logo.png new file mode 100644 index 00000000..dd4f62fb Binary files /dev/null and b/.gitbook/assets/image27-nginx-logo.png differ diff --git a/.gitbook/assets/image28-docker-container-ip-address.png b/.gitbook/assets/image28-docker-container-ip-address.png new file mode 100644 index 00000000..7e9470d4 Binary files /dev/null and b/.gitbook/assets/image28-docker-container-ip-address.png differ diff --git a/.gitbook/assets/image29-nginx-config-file-original-on-opening.png b/.gitbook/assets/image29-nginx-config-file-original-on-opening.png new file mode 100644 index 00000000..95b85729 Binary files /dev/null and b/.gitbook/assets/image29-nginx-config-file-original-on-opening.png differ diff --git a/.gitbook/assets/image30-nginx-config-file-modified.png b/.gitbook/assets/image30-nginx-config-file-modified.png new file mode 100644 index 00000000..1483ab97 Binary files /dev/null and b/.gitbook/assets/image30-nginx-config-file-modified.png differ diff --git a/.gitbook/assets/image31-xdc-client-commands.png b/.gitbook/assets/image31-xdc-client-commands.png new file mode 100644 index 00000000..d79857a3 Binary files /dev/null and b/.gitbook/assets/image31-xdc-client-commands.png differ diff --git a/.gitbook/assets/image32-docker-compose-yml-file.png b/.gitbook/assets/image32-docker-compose-yml-file.png new file mode 100644 index 00000000..4acb629d Binary files /dev/null and b/.gitbook/assets/image32-docker-compose-yml-file.png differ 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 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + +
+ +
+ + + + + + + +
+ + + + + + +
+ + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ +
+ + + + + + +
+ + +

No labels! +

+

There aren’t any labels for this repository quite yet. +

+ +
+ + +
+
+ +
+ +
+ + + bug + + +
+ + + bug + + +
+
+ +
+ Something isn't working +
+ +
+
+ + + +
+ + +
+ +
+ + + duplicate + + +
+ + + duplicate + + +
+
+ +
+ This issue or pull request already exists +
+ +
+
+ + + +
+ + +
+ +
+ + + enhancement + + +
+ + + enhancement + + +
+
+ +
+ New feature or request +
+ +
+
+ + + +
+ + +
+ +
+ + + good first issue + + +
+ + + good first issue + + +
+
+ +
+ Good for newcomers +
+ +
+
+ + + +
+ + +
+ +
+ + + help wanted + + +
+ + + help wanted + + +
+
+ +
+ Extra attention is needed +
+ +
+
+ + + +
+ + +
+ +
+ + + invalid + + +
+ + + invalid + + +
+
+ +
+ This doesn't seem right +
+ +
+
+ + + +
+ + +
+ +
+ + + question + + +
+ + + question + + +
+
+ +
+ Further information is requested +
+ +
+
+ + + +
+ + +
+ +
+ + + wontfix + + +
+ + + wontfix + + +
+
+ +
+ This will not be worked on +
+ +
+
+ + + +
+ +
+
+
+ +
+ +
+ + +
+ +
+ + +
+
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + diff --git a/.gitbook/assets/local run.sh b/.gitbook/assets/local run.sh new file mode 100644 index 00000000..32c505ea --- /dev/null +++ b/.gitbook/assets/local run.sh @@ -0,0 +1,45 @@ +#!/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="/home/xinfin/github/xinFinOrg/XDPoS-TestNet-Apothem" +cd $PROJECT_DIR && make all +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" + +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@127.0.0.1:30301" --syncmode "full" --datadir ./nodes/1 --networkid 853 --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 "BlockWorks01:xinfin_network_stats@localhost:3005" & +child_proc="$child_proc $!" +${PROJECT_DIR}/build/bin/$Bin_NAME --bootnodes "enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@127.0.0.1:30301" --syncmode "full" --datadir ./nodes/2 --networkid 853 --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 "BlockWorks02:xinfin_network_stats@localhost:3005" & +child_proc="$child_proc $!" +${PROJECT_DIR}/build/bin/$Bin_NAME --bootnodes "enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@127.0.0.1:30301" --syncmode "full" --datadir ./nodes/3 --networkid 853 --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 "BlockWorks03:xinfin_network_stats@localhost:3005" diff --git a/.gitbook/assets/members b/.gitbook/assets/members new file mode 100644 index 00000000..af7aa588 --- /dev/null +++ b/.gitbook/assets/members @@ -0,0 +1,1217 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Forks · XDCFoundation/XDC_Python_SDK_V1 · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + +
+ +
+ + + + + + + +
+ + + + + + +
+ + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Insights: XDCFoundation/XDC_Python_SDK_V1

+
+
+ + +
+ + + +
+
+ +
+ + + + @CoinClubQuincy + + CoinClubQuincy + / + XDC_Python_SDK_V1 +
+ +
+ + + + + + + @XDCFoundation + + XDCFoundation + / + XDC_Python_SDK_V1 +
+ +
+
+ +
+
+ + +
+ +
+ + +
+
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + diff --git a/.gitbook/assets/milestones b/.gitbook/assets/milestones new file mode 100644 index 00000000..bba1048e --- /dev/null +++ b/.gitbook/assets/milestones @@ -0,0 +1,1271 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Milestones - XinFinOrg/Local_DPoS_Setup · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + +
+ +
+ + + + + + + +
+ + + + + + +
+ + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + diff --git a/.gitbook/assets/monthly b/.gitbook/assets/monthly new file mode 100644 index 00000000..7f71f25b --- /dev/null +++ b/.gitbook/assets/monthly @@ -0,0 +1,1312 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Pulse · XDCFoundation/XDC_Python_SDK_V1 · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + +
+ +
+ + + + + + + +
+ + + + + + +
+ + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Insights: XDCFoundation/XDC_Python_SDK_V1

+
+
+ + +
+ +
+

March 19, 2023 April 19, 2023

+ +
+ Period: + 1 month + +
+ Filter activity +
+ +
+
+
+
+
+
+

Overview

+
+ +
    +
  • +
    +
    +
    +
    + 0 + Active pull requests +
    +
    + +
    +
    +
    +
    + 0 + Active issues +
    +
    +
  • + +
  • +
      +
    • + + + 0 + + Merged pull requests +
    • +
    • + + + 0 + + Open pull requests +
    • +
    • + + + 0 + + Closed issues +
    • +
    • + + + 0 + + New issues +
    • +
    +
  • +
+
+ +
+ +

There hasn’t been any commit activity on XDCFoundation/XDC_Python_SDK_V1 in the last month.

+ +

Want to help out?

+

+

+

+ +
+
+ + +
+ +
+
+ + +
+ +
+ + +
+
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + diff --git a/.gitbook/assets/network b/.gitbook/assets/network new file mode 100644 index 00000000..4054b923 --- /dev/null +++ b/.gitbook/assets/network @@ -0,0 +1,1208 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Network Graph · XDCFoundation/XDC_Python_SDK_V1 · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + + + + +
+ +
+ + + + + + + +
+ + + + + + +
+ + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Insights: XDCFoundation/XDC_Python_SDK_V1

+
+
+ + +
+ +
+
+

Network graph

+ + +

Timeline of the most recent commits to this repository and its network ordered by most recently pushed to.

+
+ +
+ + +

Sorry, your browser doesn’t support the <canvas> element.

+

Please upgrade to the latest Internet Explorer, Chrome or Firefox.

+
+ +
+ + +
+ +
+
+ + +
+ +
+ + +
+
+ +
+ + + + + + + + + + + + + + + + + + +
+ +
+ + + diff --git a/.gitbook/assets/node1 (1).sh b/.gitbook/assets/node1 (1).sh new file mode 100644 index 00000000..7564c44b --- /dev/null +++ b/.gitbook/assets/node1 (1).sh @@ -0,0 +1,45 @@ +#!/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/XDPoS-TestNet-Apothem" +cd $PROJECT_DIR && make all +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" + +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://ec569f5d52cefee5c5405a0c5db720dc7061f3085e0682dd8321413430ddda6a177b85db75b0daf83d2e68760ba3f5beb4ba9e333e7d52072fba4d39b05a0451@109.169.40.129:30301,enode://ec569f5d52cefee5c5405a0c5db720dc7061f3085e0682dd8321413430ddda6a177b85db75b0daf83d2e68760ba3f5beb4ba9e333e7d52072fba4d39b05a0451@5.152.223.199:30303,enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@62.233.65.7:30301,enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@127.0.0.1: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_test_network_stats@stats_testnet.xinfin.network:3000" +# child_proc="$child_proc $!" +# ${PROJECT_DIR}/build/bin/$Bin_NAME --bootnodes "enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@127.0.0.1:30301" --syncmode "full" --datadir ./nodes/2 --networkid 853 --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_network_stats@stats.testnet.xinfin.network:3000" & +# child_proc="$child_proc $!" +# ${PROJECT_DIR}/build/bin/$Bin_NAME --bootnodes "enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@127.0.0.1:30301" --syncmode "full" --datadir ./nodes/3 --networkid 853 --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_network_stats@stats.testnet.xinfin.network:3000" diff --git a/.gitbook/assets/node1.JPG b/.gitbook/assets/node1.JPG new file mode 100644 index 00000000..170850c6 Binary files /dev/null and b/.gitbook/assets/node1.JPG differ diff --git a/.gitbook/assets/node1.sh b/.gitbook/assets/node1.sh new file mode 100644 index 00000000..300c18c0 --- /dev/null +++ b/.gitbook/assets/node1.sh @@ -0,0 +1,30 @@ +#!/bin/bash +_interupt() { + echo "Shutdown $child_proc" + kill -TERM $child_proc + exit +} + +trap _interupt INT TERM + +touch .pwd +export $(cat .env | xargs) +Bin_NAME=gxdc +WORK_DIR=$PWD +PROJECT_DIR="${HOME}/go/src/github.com/ethereum/go-ethereum" +cd $PROJECT_DIR && make $Bin_NAME +cd $WORK_DIR + +wallet1=$(${PROJECT_DIR}/build/bin/$Bin_NAME account list --datadir ./nodes/1 | head -n 1 | awk -v FS="({|})" '{print $2}') + +VERBOSITY=4 +GASPRICE="1" + +echo Starting the bootnode ... +${PROJECT_DIR}/build/bin/bootnode -nodekey ./bootnode.key & +child_proc=$! + +echo Starting the nodes ... +${PROJECT_DIR}/build/bin/$Bin_NAME --bootnodes "enode://7d8ffe6d28f738d8b7c32f11fb6daa6204abae990a842025b0a969aabdda702aca95a821746332c2e618a92736538761b1660aa9defb099bc46b16db28992bc9@127.0.0.1:30301" --syncmode "full" --datadir ./nodes/1 --networkid 89 --port 30303 --rpc --rpccorsdomain "*" --rpcaddr 0.0.0.0 --rpcport 8545 --rpcvhosts "*" --unlock "${wallet1}" --password ./.pwd --mine --gasprice "${GASPRICE}" --targetgaslimit "420000000" --verbosity ${VERBOSITY} & +child_proc="$child_proc $!" +tail -f ./genesis/$Bin_NAMEchain.json diff --git a/.gitbook/assets/node2 (1).sh b/.gitbook/assets/node2 (1).sh new file mode 100644 index 00000000..23e7c011 --- /dev/null +++ b/.gitbook/assets/node2 (1).sh @@ -0,0 +1,30 @@ +#!/bin/bash +_interupt() { + echo "Shutdown $child_proc" + kill -TERM $child_proc + exit +} + +trap _interupt INT TERM + +touch .pwd +export $(cat .env | xargs) +Bin_NAME=gxdc +WORK_DIR=$PWD +PROJECT_DIR="${HOME}/go/src/github.com/ethereum/go-ethereum" +cd $PROJECT_DIR && make $Bin_NAME +cd $WORK_DIR + +wallet2=$(${PROJECT_DIR}/build/bin/$Bin_NAME account list --datadir ./nodes/2 | head -n 1 | awk -v FS="({|})" '{print $2}') + +VERBOSITY=4 +GASPRICE="1" + +echo Starting the bootnode ... +${PROJECT_DIR}/build/bin/bootnode -nodekey ./bootnode.key & +child_proc=$! + +echo Starting the nodes ... +${PROJECT_DIR}/build/bin/$Bin_NAME --bootnodes "enode://7d8ffe6d28f738d8b7c32f11fb6daa6204abae990a842025b0a969aabdda702aca95a821746332c2e618a92736538761b1660aa9defb099bc46b16db28992bc9@127.0.0.1:30301" --syncmode "full" --datadir ./nodes/2 --networkid 89 --port 30304 --rpc --rpccorsdomain "*" --rpcaddr 0.0.0.0 --rpcport 8546 --rpcvhosts "*" --unlock "${wallet2}" --password ./.pwd --mine --gasprice "${GASPRICE}" --targetgaslimit "420000000" --verbosity ${VERBOSITY} & +child_proc="$child_proc $!" +tail -f ./genesis/$Bin_NAMEchain.json diff --git a/.gitbook/assets/node2.JPG b/.gitbook/assets/node2.JPG new file mode 100644 index 00000000..4abb0c07 Binary files /dev/null and b/.gitbook/assets/node2.JPG differ diff --git a/.gitbook/assets/node2.sh b/.gitbook/assets/node2.sh new file mode 100644 index 00000000..2039f321 --- /dev/null +++ b/.gitbook/assets/node2.sh @@ -0,0 +1,45 @@ +#!/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/XDPoS-TestNet-Apothem" +cd $PROJECT_DIR && make all +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" + +# 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@127.0.0.1:30301" --syncmode "full" --datadir ./nodes/1 --networkid 853 --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_network_stats@stats.testnet.xinfin.network:3000" +# # child_proc="$child_proc $!" +${PROJECT_DIR}/build/bin/$Bin_NAME --bootnodes "enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@109.169.40.128:30301" --syncmode "full" --datadir ./nodes/2 --networkid 853 --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_network_stats@stats.testnet.xinfin.network:3000" +# child_proc="$child_proc $!" +# ${PROJECT_DIR}/build/bin/$Bin_NAME --bootnodes "enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@127.0.0.1:30301" --syncmode "full" --datadir ./nodes/3 --networkid 853 --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_network_stats@stats.testnet.xinfin.network:3000" diff --git a/.gitbook/assets/node3 (1).sh b/.gitbook/assets/node3 (1).sh new file mode 100644 index 00000000..734d235b --- /dev/null +++ b/.gitbook/assets/node3 (1).sh @@ -0,0 +1,45 @@ +#!/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/XDPoS-TestNet-Apothem" +cd $PROJECT_DIR && make all +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" + +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@127.0.0.1:30301" --syncmode "full" --datadir ./nodes/1 --networkid 853 --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_network_stats@stats.testnet.xinfin.network:3000" +# child_proc="$child_proc $!" +# ${PROJECT_DIR}/build/bin/$Bin_NAME --bootnodes "enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@127.0.0.1:30301" --syncmode "full" --datadir ./nodes/2 --networkid 853 --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_network_stats@stats.testnet.xinfin.network:3000" & +# child_proc="$child_proc $!" +${PROJECT_DIR}/build/bin/$Bin_NAME --bootnodes "enode://1c20e6b46ce608c1fe739e78611225b94e663535b74a1545b1667eac8ff75ed43216306d123306c10e043f228e42cc53cb2728655019292380313393eaaf6e23@109.169.40.128:30301" --syncmode "full" --datadir ./nodes/3 --networkid 853 --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_network_stats@stats.testnet.xinfin.network:3000" diff --git a/.gitbook/assets/node3.JPG b/.gitbook/assets/node3.JPG new file mode 100644 index 00000000..11b820e0 Binary files /dev/null and b/.gitbook/assets/node3.JPG differ diff --git a/.gitbook/assets/node3.sh b/.gitbook/assets/node3.sh new file mode 100644 index 00000000..c867d00d --- /dev/null +++ b/.gitbook/assets/node3.sh @@ -0,0 +1,30 @@ +#!/bin/bash +_interupt() { + echo "Shutdown $child_proc" + kill -TERM $child_proc + exit +} + +trap _interupt INT TERM + +touch .pwd +export $(cat .env | xargs) +Bin_NAME=gxdc +WORK_DIR=$PWD +PROJECT_DIR="${HOME}/go/src/github.com/ethereum/go-ethereum" +cd $PROJECT_DIR && make $Bin_NAME +cd $WORK_DIR + +wallet3=$(${PROJECT_DIR}/build/bin/$Bin_NAME account list --datadir ./nodes/3 | head -n 1 | awk -v FS="({|})" '{print $2}') + +VERBOSITY=4 +GASPRICE="1" + +echo Starting the bootnode ... +${PROJECT_DIR}/build/bin/bootnode -nodekey ./bootnode.key & +child_proc=$! + +echo Starting the nodes ... +${PROJECT_DIR}/build/bin/$Bin_NAME --bootnodes "enode://7d8ffe6d28f738d8b7c32f11fb6daa6204abae990a842025b0a969aabdda702aca95a821746332c2e618a92736538761b1660aa9defb099bc46b16db28992bc9@127.0.0.1:30301" --syncmode "full" --datadir ./nodes/3 --networkid 89 --port 30305 --rpc --rpccorsdomain "*" --rpcaddr 0.0.0.0 --rpcport 8547 --rpcvhosts "*" --unlock "${wallet3}" --password ./.pwd --mine --gasprice "${GASPRICE}" --targetgaslimit "420000000" --verbosity ${VERBOSITY} & +child_proc="$child_proc $!" +tail -f ./genesis/$Bin_NAMEchain.json diff --git a/.gitbook/assets/node4.JPG b/.gitbook/assets/node4.JPG new file mode 100644 index 00000000..cf4b9b59 Binary files /dev/null and b/.gitbook/assets/node4.JPG differ diff --git a/.gitbook/assets/node4.sh b/.gitbook/assets/node4.sh new file mode 100644 index 00000000..68c5e5c5 --- /dev/null +++ b/.gitbook/assets/node4.sh @@ -0,0 +1,21 @@ +#!/bin/bash +export $(cat .env | xargs) +Bin_NAME=gxdc +WORK_DIR=$PWD +PROJECT_DIR="${HOME}/go/src/github.com/ethereum/go-ethereum" +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 89 --port 30306 --rpc --rpccorsdomain "*" --rpcaddr 0.0.0.0 --rpcport 8548 --rpcvhosts "*" --unlock "${wallet4}" --password ./.pwd --mine --gasprice "${GASPRICE}" --targetgaslimit "420000000" --verbosity ${VERBOSITY} diff --git a/.gitbook/assets/node5.JPG b/.gitbook/assets/node5.JPG new file mode 100644 index 00000000..7287bcc1 Binary files /dev/null and b/.gitbook/assets/node5.JPG differ diff --git a/.gitbook/assets/node5.sh b/.gitbook/assets/node5.sh new file mode 100644 index 00000000..7373ce45 --- /dev/null +++ b/.gitbook/assets/node5.sh @@ -0,0 +1,21 @@ +#!/bin/bash +export $(cat .env | xargs) +Bin_NAME=gxdc +WORK_DIR=$PWD +PROJECT_DIR="${HOME}/go/src/github.com/ethereum/go-ethereum" +cd $PROJECT_DIR && make $Bin_NAME +cd $WORK_DIR + +if [ ! -d ./nodes/5/$Bin_NAME/chaindata ] +then + wallet5=$(${PROJECT_DIR}/build/bin/$Bin_NAME account import --password .pwd --datadir ./nodes/5 <(echo ${PRIVATE_KEY_5}) | awk -v FS="({|})" '{print $2}') + ${PROJECT_DIR}/build/bin/$Bin_NAME --datadir ./nodes/5 init ./genesis/genesis.json +else + wallet5=$(${PROJECT_DIR}/build/bin/$Bin_NAME account list --datadir ./nodes/5 | 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/5 --networkid 89 --port 30307 --rpc --rpccorsdomain "*" --rpcaddr 0.0.0.0 --rpcport 8549 --rpcvhosts "*" --unlock "${wallet5}" --password ./.pwd --mine --gasprice "${GASPRICE}" --targetgaslimit "420000000" --verbosity ${VERBOSITY} diff --git a/.gitbook/assets/node6.JPG b/.gitbook/assets/node6.JPG new file mode 100644 index 00000000..1552507e Binary files /dev/null and b/.gitbook/assets/node6.JPG differ diff --git a/.gitbook/assets/node6.sh b/.gitbook/assets/node6.sh new file mode 100644 index 00000000..3b336f6c --- /dev/null +++ b/.gitbook/assets/node6.sh @@ -0,0 +1,21 @@ +#!/bin/bash +export $(cat .env | xargs) +Bin_NAME=gxdc +WORK_DIR=$PWD +PROJECT_DIR="${HOME}/go/src/github.com/ethereum/go-ethereum" +cd $PROJECT_DIR && make $Bin_NAME +cd $WORK_DIR + +if [ ! -d ./nodes/6/$Bin_NAME/chaindata ] +then + wallet6=$(${PROJECT_DIR}/build/bin/$Bin_NAME account import --password .pwd --datadir ./nodes/6 <(echo ${PRIVATE_KEY_6}) | awk -v FS="({|})" '{print $2}') + ${PROJECT_DIR}/build/bin/$Bin_NAME --datadir ./nodes/6 init ./genesis/genesis.json +else + wallet6=$(${PROJECT_DIR}/build/bin/$Bin_NAME account list --datadir ./nodes/6 | 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/6 --networkid 89 --port 30308 --rpc --rpccorsdomain "*" --rpcaddr 0.0.0.0 --rpcport 8550 --rpcvhosts "*" --unlock "${wallet6}" --password ./.pwd --mine --gasprice "${GASPRICE}" --targetgaslimit "420000000" --verbosity ${VERBOSITY} diff --git a/.gitbook/assets/node7.JPG b/.gitbook/assets/node7.JPG new file mode 100644 index 00000000..04eef9bd Binary files /dev/null and b/.gitbook/assets/node7.JPG differ diff --git a/.gitbook/assets/node8.JPG b/.gitbook/assets/node8.JPG new file mode 100644 index 00000000..d37dd896 Binary files /dev/null and b/.gitbook/assets/node8.JPG differ diff --git a/.gitbook/assets/pwd.txt b/.gitbook/assets/pwd.txt new file mode 100644 index 00000000..e69de29b diff --git a/.gitbook/assets/settings.json b/.gitbook/assets/settings.json new file mode 100644 index 00000000..89745197 --- /dev/null +++ b/.gitbook/assets/settings.json @@ -0,0 +1,5 @@ +{ + "python.analysis.extraPaths": [ + "./modules" + ] +} \ No newline at end of file diff --git a/.gitbook/assets/setup.py b/.gitbook/assets/setup.py new file mode 100644 index 00000000..28e3abeb --- /dev/null +++ b/.gitbook/assets/setup.py @@ -0,0 +1,15 @@ +from setuptools import setup, find_packages + + + +setup( + name = 'XDC3PYTHON', + version = '1.0.1', + description = 'XDC PYTHON SDK with support for smart contracts, XRC20 & XRC721', + long_description=open('README.md').read(), + url='https://github.com/XDCFoundation/XDC_Python_SDK_V1.git', + author='XDC Foundation', + license='MIT', + keywords='', + packages=find_packages(), +) \ No newline at end of file diff --git a/.gitbook/assets/xrc20.py b/.gitbook/assets/xrc20.py new file mode 100644 index 00000000..03fe9057 --- /dev/null +++ b/.gitbook/assets/xrc20.py @@ -0,0 +1,318 @@ +from web3 import Web3 +from web3._utils.encoding import ( + hexstr_if_str, + to_bytes, +) + +# xrc20 abi.json +xrc20abi = "[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"balance\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"},{\"name\":\"_spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"fallback\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"spender\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"}]" + + +# This is a class which consists all the methods as per XRC20 standards. + +class XRC20: + + def __init__(self,rpcUrl): + self.rpcUrl = rpcUrl + + # connection to network. + + def getConnection(self): + w3 = Web3(Web3.HTTPProvider(self.rpcUrl)) + return w3 + + # get contract Instance. + + def getContractInstance(self, tokenAddr): + contractInstance = self.getConnection().eth.contract(address=tokenAddr, abi=xrc20abi) + return contractInstance + + # Gets the Name of the specified address. + # Token address is required as argument. + + def name(self, tokenAddr): + name = self.getContractInstance(tokenAddr).functions.name().call() + return name + + # Gets method returns total supply of token. + # Token address is required as argument. + + def totalSupply(self, tokenAddr): + totalSupply = self.getContractInstance(tokenAddr).functions.totalSupply().call() + totalSupply = self.getConnection().fromWei(totalSupply, 'ether') + return totalSupply + + # Gets the Decimal of the specified address. + # Token address is required as argument. + + def decimal(self, tokenAddr): + decimal = self.getContractInstance(tokenAddr).functions.decimals().call() + return decimal + + # Gets the Symbol of the specified address. + # Token address is required as argument. + + def symbol(self, tokenAddr): + symbol = self.getContractInstance(tokenAddr).functions.symbol().call() + return symbol + + # Gets the balance of the specified address. + # token address, owner address are required as arguments. + + def balanceOf(self, tokenAddr, ownerAddress): + owner = Web3.toChecksumAddress(ownerAddress) + balance = self.getContractInstance(tokenAddr).functions.balanceOf(owner).call() + return self.getConnection().fromWei(balance, 'ether') + + # This method returns how much allowance spender have from owner. + # This function required three arguments. + # owner address, spender address, token address. + + def allowance(self, tokenAddr, ownerAddress, spenderAddress): + owner = Web3.toChecksumAddress(ownerAddress) + spender = Web3.toChecksumAddress(spenderAddress) + Allowance = self.getContractInstance(tokenAddr).functions.allowance(owner, spender).call() + return self.getConnection().fromWei(Allowance, 'ether') + + # Transfer XDC for a specified address. + # This function requires following arguments. + # private key, recipient address, amount. + + def transferXDC(self, ownerAddress, receiverAddress, ownerPrivateKey, amount): + + owner = Web3.toChecksumAddress(ownerAddress) + spender = Web3.toChecksumAddress(receiverAddress) + amount = self.getConnection().toWei(amount, 'ether') + + nonce = self.getConnection().eth.getTransactionCount(owner) + gasPrice = self.getConnection().eth.gas_price + estimateGas = self.getConnection().eth.estimateGas({ + 'to': spender, + 'from': owner, + 'value': amount + }) + + tx = { + 'nonce': nonce, + 'to': spender, + 'value': amount, + 'gas': estimateGas, + 'gasPrice': gasPrice, + } + + signedTx = self.getConnection().eth.account.signTransaction(tx, ownerPrivateKey) + + txHash = self.getConnection().eth.sendRawTransaction(signedTx.rawTransaction) + return self.getConnection().toHex(txHash) + + # Transfer token for a specified address. + # This function requires following arguments. + # ownerAddress, ownerPrivateKey, receiver address, token address, amount. + + def transferToken(self, tokenAddr, ownerAddress, ownerPrivateKey, receiverAddress, amount): + + owner = Web3.toChecksumAddress(ownerAddress) + spender = Web3.toChecksumAddress(receiverAddress) + + balance = self.balanceOf(tokenAddr,owner) + + if amount > balance: + return "amount exceeds balance" + + amount = self.getConnection().toWei(amount, 'ether') + + Transfer = self.getContractInstance(tokenAddr).functions.transfer(spender, amount) + + hexData = Transfer._encode_transaction_data() + + data = hexstr_if_str(to_bytes, hexData) + + estimateGas = Transfer.estimateGas( + { + 'from': owner, + } + ) + + nonce = self.getConnection().eth.getTransactionCount(owner) + gasPrice = self.getConnection().eth.gas_price + + tx = { + 'nonce': nonce, + 'to': tokenAddr, + 'data': data, + 'gas': estimateGas, + 'gasPrice': gasPrice, + } + + signedTx = self.getConnection().eth.account.signTransaction(tx, ownerPrivateKey) + + txHash = self.getConnection().eth.sendRawTransaction(signedTx.rawTransaction) + return self.getConnection().toHex(txHash) + + # Approve the passed address to spend the specified amount of tokens on behalf of owner. + # This function required arguments. + # ownerAddress, ownerPrivateKey, spenderAddress, tokenAddr, amount. + + def approve(self, tokenAddr, ownerAddress, ownerPrivateKey, spenderAddress, amount): + + owner = Web3.toChecksumAddress(ownerAddress) + spender = Web3.toChecksumAddress(spenderAddress) + + balance = self.balanceOf(tokenAddr, owner) + allowanceAmount = self.allowance(tokenAddr, owner, spender) + + if amount > balance and allowanceAmount > balance: + return "amount exceeds balance" + + amount = self.getConnection().toWei(amount, 'ether') + + approveData = self.getContractInstance(tokenAddr).functions.approve(spender, amount) + + hexData = approveData._encode_transaction_data() + + data = hexstr_if_str(to_bytes, hexData) + + estimateGas = approveData.estimateGas() + + nonce = self.getConnection().eth.getTransactionCount(owner) + + gasPrice = self.getConnection().eth.gas_price + + tx = { + 'nonce': nonce, + 'to': tokenAddr, + 'data': data, + 'gas': estimateGas, + 'gasPrice': gasPrice, + } + + signedTx = self.getConnection().eth.account.signTransaction(tx, ownerPrivateKey) + + txHash = self.getConnection().eth.sendRawTransaction(signedTx.rawTransaction) + return self.getConnection().toHex(txHash) + + # increase the amount of tokens that an owner allowed to a spender. + # This function required arguments. + # owner address, ownerPrivateKey, spender address, token address, amount. + + def increaseAllowance(self, tokenAddr, ownerAddress, ownerPrivateKey, spenderAddress, amount): + + + owner = Web3.toChecksumAddress(ownerAddress) + spender = Web3.toChecksumAddress(spenderAddress) + + balance = self.balanceOf(tokenAddr, owner) + + allowanceAmount = self.allowance(tokenAddr, owner , spender) + + allowanceAmount = self.getConnection().fromWei(allowanceAmount, 'ether') + + totalAmount = allowanceAmount + amount + + if totalAmount > balance: + return "amount exceeds balance" + + totalAmount = self.getConnection().toWei(totalAmount, 'ether') + + Transfer = self.getContractInstance(tokenAddr).functions.approve(spender, totalAmount) + + hexData = Transfer._encode_transaction_data() + + data = hexstr_if_str(to_bytes, hexData) + + estimateGas = Transfer.estimateGas() + + nonce = self.getConnection().eth.getTransactionCount(owner) + gasPrice = self.getConnection().eth.gas_price + + tx = { + 'nonce': nonce, + 'to': tokenAddr, + 'data': data, + 'gas': estimateGas, + 'gasPrice': gasPrice, + } + signedTx = self.getConnection().eth.account.signTransaction(tx, ownerPrivateKey) + + txHash = self.getConnection().eth.sendRawTransaction(signedTx.rawTransaction) + return self.getConnection().toHex(txHash) + + # decrease the amount of tokens that an owner allowed to a spender. + # This function required arguments. + # owner address, ownerPrivateKey, spender address, token address, amount. + + def decreaseAllowance(self, tokenAddr, ownerAddress, ownerPrivateKey, spenderAddress, amount): + + owner = Web3.toChecksumAddress(ownerAddress) + spender = Web3.toChecksumAddress(spenderAddress) + + allowanceAmount = self.allowance(tokenAddr, owner, spender) + allowanceAmount = self.getConnection().fromWei(allowanceAmount, 'ether') + + if allowanceAmount >= amount: + totalAmount = allowanceAmount - amount + else: + totalAmount = amount - allowanceAmount + + totalAmount = self.getConnection().toWei(totalAmount, 'ether') + + approveData = self.getContractInstance(tokenAddr).functions.approve(spender, totalAmount) + + hexData = approveData._encode_transaction_data() + + data = hexstr_if_str(to_bytes, hexData) + + estimateGas = approveData.estimateGas() + + nonce = self.getConnection().eth.getTransactionCount(owner) + gasPrice = self.getConnection().eth.gas_price + + tx = { + 'nonce': nonce, + 'to': tokenAddr, + 'data': data, + 'gas': estimateGas, + 'gasPrice': gasPrice, + } + signedTx = self.getConnection().eth.account.signTransaction(tx, ownerPrivateKey) + + txHash = self.getConnection().eth.sendRawTransaction(signedTx.rawTransaction) + return self.getConnection().toHex(txHash) + + # Transfer tokens from one address to another. + # This function requires following arguments. + # owner address, spenderPrivateKey, spender address, receiver address, token address, amount. + + def transferFrom(self, tokenAddr, ownerAddress, spenderPrivateKey, spenderAddress, receiver, amount): + + owner = Web3.toChecksumAddress(ownerAddress) + receiverAddres = Web3.toChecksumAddress(receiver) + spender = Web3.toChecksumAddress(spenderAddress) + + amount = self.getConnection().toWei(amount, 'ether') + + transferData = self.getContractInstance(tokenAddr).functions.transferFrom( + owner, receiverAddres, amount) + + estimateGas = transferData.estimateGas({ + 'from': spender, + }) + + hexData = transferData._encode_transaction_data() + + data = hexstr_if_str(to_bytes, hexData) + + nonce = self.getConnection().eth.getTransactionCount(spender) + gasPrice = self.getConnection().eth.gas_price + + tx = { + 'nonce': nonce, + 'to': tokenAddr, + 'data': data, + 'gas': estimateGas, + 'gasPrice': gasPrice, + } + signedTx = self.getConnection().eth.account.signTransaction(tx, spenderPrivateKey) + + txHash = self.getConnection().eth.sendRawTransaction(signedTx.rawTransaction) + return self.getConnection().toHex(txHash) diff --git a/.gitbook/assets/xrc721.py b/.gitbook/assets/xrc721.py new file mode 100644 index 00000000..2740422a --- /dev/null +++ b/.gitbook/assets/xrc721.py @@ -0,0 +1,281 @@ +from web3 import Web3 +from web3._utils.encoding import ( + hexstr_if_str, + to_bytes, +) + + +# xrc721 abi.json +xrc721abi = "[{\"constant\":true,\"inputs\":[{\"name\":\"interfaceId\",\"type\":\"bytes4\"}],\"name\":\"supportsInterface\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"getApproved\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"to\",\"type\":\"address\"},{\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"from\",\"type\":\"address\"},{\"name\":\"to\",\"type\":\"address\"},{\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"owner\",\"type\":\"address\"},{\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"tokenOfOwnerByIndex\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"from\",\"type\":\"address\"},{\"name\":\"to\",\"type\":\"address\"},{\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"safeTransferFrom\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"tokenByIndex\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"ownerOf\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"to\",\"type\":\"address\"},{\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"setApprovalForAll\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"from\",\"type\":\"address\"},{\"name\":\"to\",\"type\":\"address\"},{\"name\":\"tokenId\",\"type\":\"uint256\"},{\"name\":\"_data\",\"type\":\"bytes\"}],\"name\":\"safeTransferFrom1\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"tokenURI\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_tokenId\",\"type\":\"uint256\"},{\"name\":\"_uri\",\"type\":\"string\"}],\"name\":\"mint\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"owner\",\"type\":\"address\"},{\"name\":\"operator\",\"type\":\"address\"}],\"name\":\"isApprovedForAll\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"symbol\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"to\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"approved\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"tokenId\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"operator\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"approved\",\"type\":\"bool\"}],\"name\":\"ApprovalForAll\",\"type\":\"event\"}]" + + +# This is a class which consists all the methods as per XRC721 standards. + +class XRC721: + + def __init__(self,rpcUrl): + self.rpcUrl = rpcUrl + + # connection to network. + + def getConnection(self): + w3 = Web3(Web3.HTTPProvider(self.rpcUrl)) + return w3 + + # get contract Instance. + + def getContractInstance(self, tokenAddr): + contractInstance = self.getConnection().eth.contract(address=tokenAddr, abi=xrc721abi) + return contractInstance + + # Gets the Name of the specified address. + # token address required as an argument. + + def name(self, tokenAddr): + result = self.getContractInstance(tokenAddr).functions.name().call() + return result + + # Gets the Symbol of the specified address. + # token address required as an argument. + + def symbol(self, tokenAddr): + result = self.getContractInstance(tokenAddr).functions.symbol().call() + return result + + # Gets the owner of an NFT. + # required arguments. + # token address, token id. + + def ownerOf(self, tokenAddr, tokenId): + result = self.getContractInstance(tokenAddr).functions.ownerOf(tokenId).call() + return result + + # Gets the Totalsupply of the specified address. + # token address required as an argument. + + def totalSupply(self, tokenAddr): + token = Web3.toChecksumAddress(tokenAddr) + result = self.getContractInstance(tokenAddr).functions.totalSupply().call() + resultt = str(result) + return resultt + + # Gets the balance of the specified address. + # reuired arguments + # token address, owner address. + + def balanceOf(self, tokenAddr, ownerAddress): + owner = Web3.toChecksumAddress(ownerAddress) + result = self.getContractInstance(tokenAddr).functions.balanceOf(owner).call() + return result + + # A distinct Uniform Resource Identifier (URI) for a given asset. + # Gets URI of a token. + # required arguments + # tokenId The identifier for an NFT. + # address of the token. + + def tokenURI(self, tokenAddr, tokenId): + result = self.getContractInstance(tokenAddr).functions.tokenURI(tokenId).call() + return result + + # Enumerate NFTs assigned to an owner. + # tokenAddress An address for whom to query. + # IndexNO A counter less than `totalSupply()`. + # The token identifier for the `index`th NFT assigned to `owner`. + + def tokenByIndex(self, tokenAddr, index): + token = Web3.toChecksumAddress(tokenAddr) + result = self.getContractInstance(tokenAddr).functions.tokenByIndex(index).call() + return result + + # Enumerate NFTs assigned to an owner. + # The token identifier for the `index`th NFT assigned to `owner`. + # required arguments. + # owner address, token address, token index. + + def tokenofOwnerByIndex(self, tokenAddr, ownerAddress, index): + token = Web3.toChecksumAddress(tokenAddr) + owner = Web3.toChecksumAddress(ownerAddress) + result = self.getContractInstance(token).functions.tokenOfOwnerByIndex( + owner, index).call() + return result + + # Query if a contract implements an interface. + # tokenAddress An address for whom to query and x_bytes The interface identifier. + # `true` if the contract implements `interfaceID` andinterfaceID` is not 0xffffffff, `false` otherwise. + # required arguments. + # token address, interface id. + + def supportInterface(self, tokenAddr, interfaceId): + token = Web3.toChecksumAddress(tokenAddr) + result = self.getContractInstance(token).functions.supportsInterface( + interfaceId).call() + return result + + # The approved address for a token ID, or zero if no address set Reverts if the token ID does not exist. + # required arguments. + # token address, tokenId. + + def getApproved(self, tokenAddr, tokenId): + result = self.getContractInstance(tokenAddr).functions.getApproved(tokenId).call() + return result + + # Tells whether an operator is approved by a given owner. + # required arguments. + # owner address, spender address, token address. + + def isApprovedForAll(self, tokenAddr, ownerAddress, spenderAddress): + owner = Web3.toChecksumAddress(ownerAddress) + spender = Web3.toChecksumAddress(spenderAddress) + result = self.getContractInstance(tokenAddr).functions.isApprovedForAll( + owner, spender).call() + return result + + # Change or reaffirm the approved address for an NFT. + # The zero address indicates there is no approved address. + # Throws unless `owner` is the current NFT owner, or an authorized. + # required arguments. + # tokenAddress, owner address, ownerPrivateKey, spenderAddress, tokenID. + + def approve(self, tokenAddr, ownerAddress, ownerPrivateKey, spenderAddress, tokenId): + + owner = Web3.toChecksumAddress(ownerAddress) + spender = Web3.toChecksumAddress(spenderAddress) + + approveData = self.getContractInstance(tokenAddr).functions.approve(spender, tokenId) + + hexData = approveData._encode_transaction_data() + + data = hexstr_if_str(to_bytes, hexData) + + estimateGas = approveData.estimateGas({ + 'from': owner, + }) + + nonce = self.getConnection().eth.getTransactionCount(owner) + + gasPrice = self.getConnection().eth.gas_price + + tx = { + 'nonce': nonce, + 'to': tokenAddr, + 'data': data, + 'gas': estimateGas, + 'gasPrice': gasPrice, + } + + signedTx = self.getConnection().eth.account.signTransaction(tx, ownerPrivateKey) + + txHash = self.getConnection().eth.sendRawTransaction(signedTx.rawTransaction) + return self.getConnection().toHex(txHash) + + # Enable or disable approval for a third party ("operator") to manage all of `Owner`'s assets + # Emits the ApprovalForAll event. The contract MUST allow multiple operators per owner. + # required arguments. + # token address, owner address, ownerPrivateKey, sepnder address, tokenId. + + def setApprovalForAll(self, tokenAddr, ownerAddress, ownerPrivateKey, spenderAddress, boolValue): + + owner = Web3.toChecksumAddress(ownerAddress) + spender = Web3.toChecksumAddress(spenderAddress) + + approveData = self.getContractInstance(tokenAddr).functions.setApprovalForAll( + spender, boolValue) + + hexData = approveData._encode_transaction_data() + + data = hexstr_if_str(to_bytes, hexData) + + estimateGas = approveData.estimateGas({ + 'from': owner, + }) + + nonce = self.getConnection().eth.getTransactionCount(owner) + + gasPrice = self.getConnection().eth.gas_price + + tx = { + 'nonce': nonce, + 'to': tokenAddr, + 'data': data, + 'gas': estimateGas, + 'gasPrice': gasPrice, + } + + signedTx = self.getConnection().eth.account.signTransaction(tx, ownerPrivateKey) + + txHash = self.getConnection().eth.sendRawTransaction(signedTx.rawTransaction) + return self.getConnection().toHex(txHash) + + # Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE + # to confirm that `reciever Address` is capable of receiving NFTs or else they may be permanently lost. + # required arguments. + # token address, owner address, spender address, spenderPrivateKey, receiver address, tokenId. + + def transferFrom(self, tokenAddr, ownerAddress, spenderAddress, spenderPrivateKey, receiver, tokenId): + + owner = Web3.toChecksumAddress(ownerAddress) + receiverAddres = Web3.toChecksumAddress(receiver) + spender = Web3.toChecksumAddress(spenderAddress) + + transferData = self.getContractInstance(tokenAddr).functions.transferFrom( + owner, receiverAddres, tokenId) + + estimateGas = transferData.estimateGas({ + 'from': spender, + }) + + hexData = transferData._encode_transaction_data() + + data = hexstr_if_str(to_bytes, hexData) + + nonce = self.getConnection().eth.getTransactionCount(spender) + gasPrice = self.getConnection().eth.gas_price + + tx = { + 'nonce': nonce, + 'to': tokenAddr, + 'data': data, + 'gas': estimateGas, + 'gasPrice': gasPrice, + } + signedTx = self.getConnection().eth.account.signTransaction(tx, spenderPrivateKey) + + txHash = self.getConnection().eth.sendRawTransaction(signedTx.rawTransaction) + return self.getConnection().toHex(txHash) + + # Transfers the ownership of an NFT from one address to another address. + # required arguments. + # token address, owner address, spender address, spenderPrivateKey, receiver address, tokenId. + + def safeTransferFrom(self, tokenAddr, ownerAddress, spenderAddress, spenderPrivateKey, receiver, tokenId): + + owner = Web3.toChecksumAddress(ownerAddress) + receiverAddres = Web3.toChecksumAddress(receiver) + spender = Web3.toChecksumAddress(spenderAddress) + + transferData = self.getContractInstance(tokenAddr).functions.safeTransferFrom( + owner, receiverAddres, tokenId) + + estimateGas = transferData.estimateGas({ + 'from': spender, + }) + + hexData = transferData._encode_transaction_data() + + data = hexstr_if_str(to_bytes, hexData) + + nonce = self.getConnection().eth.getTransactionCount(spender) + gasPrice = self.getConnection().eth.gas_price + + tx = { + 'nonce': nonce, + 'to': tokenAddr, + 'data': data, + 'gas': estimateGas, + 'gasPrice': gasPrice, + } + signedTx = self.getConnection().eth.account.signTransaction(tx, spenderPrivateKey) + + txHash = self.getConnection().eth.sendRawTransaction(signedTx.rawTransaction) + return self.getConnection().toHex(txHash) diff --git a/.gitbook/assets/you_know b/.gitbook/assets/you_know new file mode 100644 index 00000000..013baaf4 --- /dev/null +++ b/.gitbook/assets/you_know @@ -0,0 +1,396 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Sign in to GitHub · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ Skip to content + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + +
+
+ + +
+ + + +
+

Sign in to GitHub

+
+ + +
+ + + + + + +
+ + + + +
+ + +
+ + +
+ + + + + + + + + + + + + + Forgot password? +
+
+
+ + + + +
+ +
+
+ + + + + + + + + + + + + + + + + +
+ +
+ + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..11b54232 --- /dev/null +++ b/.gitignore @@ -0,0 +1,49 @@ +# Node rules: +## Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +## Dependency directory +## Commenting this out is preferred by some people, see +## https://docs.npmjs.com/misc/faq#should-i-check-my-node_modules-folder-into-git +node_modules + +# Book build output +_book + +# eBook build output +*.epub +*.mobi +*.pdf + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud \ No newline at end of file diff --git a/README.md b/README.md index c846b746..c4891941 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,16 @@ # Welcome -The XDC Network is a global, open-source, delegated proof of stake consensus network (XDPoS), with near-zero gas fees, 2 second block finality, and interoperability with ISO 20022 financial messaging standards. The network’s enterprise-grade architecture is designed to support institutional use in trade finance and asset tokenization. Featuring interoperable smart contracts, 2,000 transactions per second, and Ethereum Virtual Machine compatibility, the XDC Network provides a scalable infrastructure for enterprises and independent community contributors. +Welcome and thank you for visiting XDC Network’s documentation. Whether you desire to learn the basics of blockchain technology, find technical information, guides, or are interested in building on the XDC Network, you have come to the right place. The documents are indexed for easy reference and laid out for easy reading and context as you navigate through them. -XDC is the underlying utility token of the XDC Network. Singapore-based XinFin launched the (public/private) mainnet XDC Network in 2019 with the goal of transforming real-world business processes, particularly in the global trade and finance markets. In Q1 2021, the XDC Foundation was established as a legal entity incorporated for the express purpose of supporting the XDC Network, and it relies on the input of community members in order to decentralize its influence. As part of its mission, the XDC Foundation seeks to encourage the development and use of the open-source XDC Network, which is currently being utilized by a variety of third-party operations. +If you would like to contribute to these documents, we encourage that and ask you to submit additions or edits through the GitHub pull request process here [https://docs.xdc.community/learn/community-support/gitbook]. +
+
+
-Through its ecosystem of participants and tools, the XDC Network supports ISO20022 compatible messaging systems and provides interoperability with legacy systems, such as ERP, SWIFT, and others. Cross-chain Ethereum based tokens and projects, such as ERC-20 and ERC721, can be migrated to the network, vastly improving scalability, speed, and providing nearly non-existent gas fees. The XDC Network is well-positioned to be a bridge between public blockchain networks and legacy systems. +## XDC Network Overview +The XDC Network is a highly scalable, delegated proof of stake consensus network (XDPoS), with near-zero gas fees and 2 second block time. Operating the XDC Network is a global infrastructure of Masternodes that participate in network consensus. The network’s enterprise-grade architecture provides a high-performance, EVM-compatible blockchain suited to the needs of institutional use in trade finance, enterprise, and tokenization. As an open-source technology, the XDC ecosystem also thrives on a growing community of developers, contributors, and participants. -The XDC Network supports digital smart contracts, which, among other things, can facilitate cross-border transactions and real-time settlement at nearly no cost to the user. The network also allows for asset digitization and tokenization. Distributed Applications (DAPPS) can be leveraged for various applications and business processes in supply chain, financing, procurement, distribution, and settlement. For example, Tradefinex is a marketplace platform that connects global participants of the trade and finance industry, enabling global contracting, financing, payments, and settlements through authorized financial institutions. -A recently published whitepaper showcases the XDC Network’s proposed upgrade to its decentralized consensus engine (XDPoS 2.0). This protocol upgrade forecasts a network with forensics capabilities, accountability and attributability, creating the ability to identify malicious actors with cryptographic integrity directly from blockchain records. +READ more about the XDC Network [here](https://docs.xdc.community/get-started/blockchain-basics/why-xdc-network). -| Document | Description | -| -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| XDC Network Overview | Describes XDC Network key concepts and design principles. | -| Getting Started | Documentation for getting started with XDC Network. | -| Smart Contracts | Tools and resources for smart contract development. | -| Installation and Operation | Illustrates how to set up and operate nodes on the XDC Network. | -| dApp Developers | Development resources and references for dApp developers. This section contains XDC Network API references and provides end-to-end dApp development tutorials. | - -**Disclaimer**: Some notes are derived from Ethereum documents as the XDC Network source code was forked from Ethereum. As the XDC Network evolves, XDC Community Docs will continue to be updated. Here are some websites for reference: - -* [https://ethereum.org/developers/](https://ethereum.org/developers/) -* [https://github.com/ethereum/go-ethereum/wiki](https://github.com/ethereum/go-ethereum/wiki) -* [https://trufflesuite.com/docs](https://trufflesuite.com/docs) -* [https://web3js.readthedocs.io/en/1.0/](https://web3js.readthedocs.io/en/1.0/) +DISCOVER what the upcoming release of XDC 2.0 will bring to the network and its participants [here](https://docs.xdc.community/get-started/xdc-design/xdpos-2.0). diff --git a/SUMMARY.md b/SUMMARY.md index d8d22ef8..3bb4cb71 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -6,6 +6,7 @@ * [What is a Blockchain](get-started/blockchain-basics/what-is-a-blockchain.md) * [What is a dApp](get-started/blockchain-basics/what-is-a-dapp.md) * [Why XDC Network](get-started/blockchain-basics/why-xdc-network.md) + * [XDC Wallets](get-started/blockchain-basics/xdc-wallets.md) * [XDC Design](get-started/xdc-design/README.md) * [Consensus Mechanism](get-started/xdc-design/consensus-mechanism.md) * [Masternodes](get-started/xdc-design/masternodes.md) @@ -38,15 +39,15 @@ * [XDCPay Changelist](get-details/wallet-integration/xdcpay-changelist.md) * [Wallet Connect](get-details/wallet-integration/walletconnect.md) * [Metamask](get-details/wallet-integration/metamask.md) - * [Networks](get-details/networks/README.md) + * [XDC Main & Test Networks Overviews](get-details/networks/README.md) * [Mainnet (XDPos)](get-details/networks/mainnet.md) * [Apothem Testnet (XDPoS)](get-details/networks/apothem.md) * [EVM Compatibility](get-details/evm-compatibility/README.md) * [XDC Network Ethereum Fork Details](get-details/evm-compatibility/xdc-fork-details.md) - * [XIP Proposals](get-details/xip-proposals.md) + * [Migrating from EVM to XDC](get-details/evm-compatibility/migrating-from-evm-to-xdc.md) * [Tools](tools/README.md) * [SDKs & Programming](tools/sdks-and-programming/README.md) - * [Soliditiy](tools/sdks-and-programming/soliditiy.md) + * [Solidity](tools/sdks-and-programming/soliditiy.md) * [Python SDK](tools/sdks-and-programming/python.md) * [iOS Swift SDK](tools/sdks-and-programming/switft.md) * [Java SDK](tools/sdks-and-programming/java.md) @@ -56,6 +57,7 @@ * [PHP SDK](tools/sdks-and-programming/php-sdk.md) * [DART SDK](tools/sdks-and-programming/dart-sdk.md) * [Rust SDK](tools/sdks-and-programming/rust-sdk.md) + * [Vyper](tools/sdks-and-programming/vyper.md) * [APIs & Packages](tools/apis-and-packages/README.md) * [XDC Connect](tools/apis-and-packages/npm-i-xdc-connect.md) * [Web3 Modal](tools/apis-and-packages/npm-i-xdc3.md) @@ -73,9 +75,17 @@ * [Business White Paper](https://github.com/XinFinOrg/Developer-Resource/blob/master/Docs/wp-and-research/whitepaper-tech.pdf) * [Run a Node](run-a-node/README.md) * [Masternode](run-a-node/masternode/README.md) - * [Full Node (Docker version)](run-a-node/masternode/full-node.md) + * [How to Stake an XDC Masternode](run-a-node/masternode/how-to-stake-an-xdc-masternode.md) * [One-Click-Installer Masternode (Windows OS)](run-a-node/masternode/standby-node.md) * [One-Click-Installer Masternode (macOS)](run-a-node/masternode/one-click-installer-masternode-macos.md) + * [How to Secure Masternode](run-a-node/masternode/securing-your-xdc-masternode.md) + * [How to Monitor Uptime](run-a-node/masternode/uptime-monitoring-xdc-masternode.md) + * [Full Node](run-a-node/full-node/README.md) + * [Full Node (Docker version)](run-a-node/full-node/full-node.md) + * [How to migrate an XDC Node](run-a-node/full-node/how-to-migrate-an-xdc-node.md) + * [RPC](run-a-node/rpc.md) + * [How to Encrypt RPC](run-a-node/how-to-ssl-tls-encryption-for-xdc-rpc.md) + * [Commands and Config Options](run-a-node/node-commands-and-config.md) ## Learn @@ -102,6 +112,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 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/get-details/evm-compatibility/README.md b/get-details/evm-compatibility/README.md index a3cd0161..3a48a1f2 100644 --- a/get-details/evm-compatibility/README.md +++ b/get-details/evm-compatibility/README.md @@ -1,3 +1,11 @@ # EVM Compatibility -For a How-To guide showing migration of a dApp from Ethereum to the XDC Network please go to [this link](https://docs.xdc.community/learn/how-to-articles/how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle). +Ethereum Virtual Machine (EVM) compatibility is becoming increasingly important in the world of blockchain networks. It allows different blockchain networks to utilize the same tools, import code to seperate networks, allow a simple and scalable means of implemeting smart contracts into a new blockchain and allows for a standard of skills and programming in a standardize language (solidity) contracts that have been created and standardized on other networks to be easily implemented on the XDC netwrok + +With EVM compatibility on the XDC network, this allows developers to use Ethereum-based programming languages and tools to build on other blockchain networks. Ethereum is currently the largest smart contract platform in the world and has a large developer community. By leveraging the EVM, developers can use familiar programming languages and tools, such as Solidity and Truffle, to create decentralized applications (DApps) on other networks. This reduces the learning curve for developers and allows for faster development times, resulting in a larger and more diverse range of applications on different networks. + +Also, EVM compatibility can increase the security of blockchain networks. The EVM is an already established deterministic machine that ensures that code executes in the same way every time it is run. This means that if a smart contract runs successfully on the Ethereum network, it will also run successfully on other EVM-compatible networks. This allows for the testing of smart contracts on the Ethereum network, which is known for its high level of security, before deploying them on other networks. This reduces the risk of vulnerabilities and increases the overall security of the blockchain ecosystem. + +The EVM allows for the DApps created on other networks to be easily imported over to the XDC network and this allows developers who have applications on other networks to import aready established code to be faster and cheaper on the XDC network without needing to change any of their propriatarty code + +In conclusion, EVM compatibility is a critical feature on XDC that can enhance the functionalities of the XDC networks in several ways. It enables interoperability, promotes innovation and growth, increases security, and enhances scalability. As the blockchain ecosystem continues to evolve, EVM compatibility will play an increasingly important role in connecting different networks and creating a more diverse and robust ecosystem. diff --git a/get-details/evm-compatibility/migrating-from-evm-to-xdc.md b/get-details/evm-compatibility/migrating-from-evm-to-xdc.md new file mode 100644 index 00000000..0a3b0d0b --- /dev/null +++ b/get-details/evm-compatibility/migrating-from-evm-to-xdc.md @@ -0,0 +1,43 @@ +# Migrating from EVM to XDC + +Migrating a Solidity contract from Ethereum to the XDC network with Truffle involves several steps. The XDC network is a public blockchain that is EVM compatible and designed to support enterprise-level applications. Truffle is a popular development framework for creating and deploying Solidity contracts. + +Step 1: Install Truffle + +The first step is to install the XDC network and Truffle. This can be done by following the installation instructions provided by XDC and Truffle. + +{% embed url="https://trufflesuite.com/docs/truffle/how-to/install/" %} + +Step 2: Configure Truffle for XDC + +Next, Truffle needs to be configured to work with the XDC network. This involves creating a new Truffle project and configuring the Truffle config file to connect to the XDC network by using a public RPC connected to the XDC network. + +{% embed url="https://trufflesuite.com/docs/truffle/reference/configuration/" %} + +Step 3: Compile the Contract + +After updating the Solidity contract, it needs to be compiled for the XDC network. This involves using the Truffle compiler to create a bytecode file that can be deployed on the XDC network. + +{% embed url="https://trufflesuite.com/docs/truffle/how-to/compile-contracts/" %} + +Step 4: Deploy the Contract + +The next step is to deploy the updated contract on the XDC network. This can be done using Truffle's deployment commands. It is important to ensure that the contract is deployed correctly and securely. + + + +Step 5: Test the Contract + +After deploying the contract, it is important to thoroughly test it on the XDC network. This includes testing all functions and features, as well as testing for security vulnerabilities. You can write test in truffle using Javascript to build debug and test contract ready to be deployed onto the network + +{% embed url="https://trufflesuite.com/docs/truffle/how-to/debug-test/write-tests-in-javascript/" %} + +Step 6: Update Clients and Interfaces + +Once the contract has been migrated and tested, any clients or interfaces that interact with the contract must be updated to be compatible with the XDC network by having them point to the appropriate RPCs on the xdc network. + + + + + +For a How-To guide showing migration of a dApp from Ethereum to the XDC Network please go to [this link](https://docs.xdc.community/learn/how-to-articles/how-to-migrate-a-dapp-from-ethereum-to-the-xdc-network-using-truffle). diff --git a/get-details/networks/README.md b/get-details/networks/README.md index 9fafe0f2..5e5a2bb6 100644 --- a/get-details/networks/README.md +++ b/get-details/networks/README.md @@ -1,2 +1,19 @@ -# Networks +# XDC Main & Test Networks Overviews +XDC main net is the production version of the XDC protocol, where real-world transactions occur. + +## **Overview of Apothem Test Network:** + +Apothem is a test network for the XDC protocol, designed to allow developers and users to test the protocol's functionalities without using real funds. It is a fully functional network that replicates the XDC main net's features, but with a separate blockchain. + +The Apothem test network is primarily used by developers to test their smart contracts and applications before deploying them on the XDC main net. It allows developers to test their code in a safe environment without the risk of losing funds. The test network also allows users to experiment with the XDC protocol's functionalities and learn how to use it before using the main net. + +Some of the functionalities of the Apothem test network include: + +1. Creating and testing smart contracts: Developers can create and test their smart contracts on the Apothem test network before deploying them on the XDC main net. +2. Testing transaction speed and fees: Users can test the transaction speed and fees of the XDC protocol on the Apothem test network, which is similar to the XDC main net. +3. Learning how to use XDC: Users can experiment with the XDC protocol's functionalities and learn how to use it before using the main net. + +## Overview + +In summary, the XDC main net is a production blockchain network that supports high transaction throughput and a wide range of enterprise use cases, while the Apothem test network is a separate blockchain network designed for testing the XDC protocol's functionalities without using real funds. Both networks offer developers and users the ability to experiment with the XDC protocol's functionalities and learn how to use it. diff --git a/get-details/networks/mainnet.md b/get-details/networks/mainnet.md index 3abf0989..9d95917a 100644 --- a/get-details/networks/mainnet.md +++ b/get-details/networks/mainnet.md @@ -2,14 +2,12 @@ ## Public Networks -Users with an internet connection can easily access a public network. They can read, create, or validate transactions executed on the blockchain, and a consensus mechanism makes agreement on the state of the network possible. - - +Users with an internet connection and access the a full node RPC one can easily access a public network. They can read, create, or validate transactions executed on the blockchain, and a consensus mechanism makes agreement on the state of the network possible. **XDC MainNet Specifications** * Chain id: `50` -* RPC endpoint: `https://rpc.xinfin.network` +* RPC endpoint: `https://rpc.xdc.org` * Websocket endpoint: `wss://ws.xinfin.network` * Consensus: XDPoS * Block finality: `>75%` @@ -20,13 +18,12 @@ Users with an internet connection can easily access a public network. They can r **Useful Links** * [XinFin Status Page](https://xinfin.network/#stats) -* [XinFin Explorer](https://explorer.xinfin.network/) (XinFin Scan) +* [XDC Network Explorer](https://xdc.blocksscan.io/) (Blocksscan) * [XinFin MasterNode APP ](https://master.xinfin.network/)(MasterNodeApp) -* [XinFin Web Wallet](https://wallet.xinfin.network/) (web Wallet) -* [XinFin Mobile Wallet](https://play.google.com/store/apps/details?id=com.xdcwallet\&hl=en\_IN) (Mobile Wallet) **Useful Tools** * [XinFin Remix](https://remix.xinfin.network/) -* [XDCPay](https://chrome.google.com/webstore/detail/xinpay/bocpokimicclpaiekenaeelehdjllofo?hl=en)\ - \ +* [XDCPay](https://chrome.google.com/webstore/detail/xinpay/bocpokimicclpaiekenaeelehdjllofo?hl=en) +* [MetaMask](https://docs.xdc.community/get-details/wallet-integration/metamask) + diff --git a/get-details/smart-contract-details/README.md b/get-details/smart-contract-details/README.md index de77e29d..25146f76 100644 --- a/get-details/smart-contract-details/README.md +++ b/get-details/smart-contract-details/README.md @@ -10,24 +10,32 @@ A smart contract is a computer code running on a blockchain that establishes rul Bitcoin was the first blockchain to support basic smart contracts. Its network of nodes only validated transactions if certain conditions were met. Here, we have an example of a rudimentary smart contract, where we use Set and Get functions: -`pragma solidity 0.4.0;`\ -`// Imagine a big integer that the whole world could share`\ -`contract SimpleStorage {`\ -`uint storedData;`\ -`function set(uint x) public {`\ -`storedData = x;`\ -`}`\ -`function get() constant public returns (uint) {`\ -`return storedData;`\ -`}`\ -`function increment (uint n) public {`\ -`storedData = storedData + n;`\ -`return;`\ -`}`\ -`function decrement (uint n) public {`\ -`storedData = storedData - n;`\ -`return;`\ -`}` +```solidity +pragma solidity 0.4.0; + +// Imagine a big integer that the whole world could share +contract SimpleStorage { + uint storedData; + + function set(uint x) public { + storedData = x; + } + + function get() constant public returns (uint) { + return storedData; + } + + function increment (uint n) public { + storedData = storedData + n; + return; + } + + function decrement (uint n) public { + storedData = storedData - n; + return; + } +} +``` ## **Key Features of Smart Contracts** diff --git a/get-details/smart-contract-details/flattening-smart-contracts/flattening-smart-contracts-with-hardhat.md b/get-details/smart-contract-details/flattening-smart-contracts/flattening-smart-contracts-with-hardhat.md index c99d308b..9f9fe69a 100644 --- a/get-details/smart-contract-details/flattening-smart-contracts/flattening-smart-contracts-with-hardhat.md +++ b/get-details/smart-contract-details/flattening-smart-contracts/flattening-smart-contracts-with-hardhat.md @@ -1,52 +1,57 @@ --- id: flatten-contract-hardhat title: Flatten a Smart Contract Using Hardhat -description: "Use Hardhat to deploy and verify smart contract" keywords: - docs - apothem - token - flatten - hardhat +description: Use Hardhat 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) -- [⚒ 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 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 Hardhat + +## 🧭 Table of contents + +* [🧭 Table of contents](flattening-smart-contracts-with-hardhat.md#-table-of-contents) +* [📰 Overview](flattening-smart-contracts-with-hardhat.md#-overview) + * [What you will learn](flattening-smart-contracts-with-hardhat.md#what-you-will-learn) + * [What you will do](flattening-smart-contracts-with-hardhat.md#what-you-will-do) +* [⚒ Starting a new Hardhat Project](flattening-smart-contracts-with-hardhat.md#-starting-a-new-hardhat-project) + * [⚒ Configuring XDC Mainnet and Apothem Testnet on Hardhat](flattening-smart-contracts-with-hardhat.md#-configuring-xdc-mainnet-and-apothem-testnet-on-hardhat) + * [⚒ Adding Testnet XDC to Development Wallet](flattening-smart-contracts-with-hardhat.md#-adding-testnet-xdc-to-development-wallet) +* [💵 Writing Smart Contract](flattening-smart-contracts-with-hardhat.md#-writing-smart-contract) + * [💵 Compiling and Testing](flattening-smart-contracts-with-hardhat.md#-compiling-and-testing) + * [Testing](flattening-smart-contracts-with-hardhat.md#testing) + * [💵 Deploying Contract](flattening-smart-contracts-with-hardhat.md#-deploying-contract) + * [💵 Flattening Contract](flattening-smart-contracts-with-hardhat.md#-flattening-contract) +* [🔍 Veryfing Contracts on the Block Explorer](flattening-smart-contracts-with-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 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 Hardhat -- 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 Hardhat +* 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 -# ⚒ 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/) Lets start by setting up our folder, we are creating a project called `MyCounter`, create a new `MyCounter` folder by running on terminal @@ -70,14 +75,11 @@ Ok to proceed? (y) The following message should log on your console: - -

- hardhat config -

+![hardhat config](https://user-images.githubusercontent.com/78161484/191259993-b817901f-7df9-4df1-bb1c-c4805c416974.png) 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: -

- hardhat folder -

+![hardhat folder](https://user-images.githubusercontent.com/78161484/191263408-af21bd08-98a8-440c-9270-7f9960bb531d.png) -## ⚒ 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: -

- Step 02 -

+![Step 02](https://user-images.githubusercontent.com/78161484/189952656-eb7793cc-7dee-4307-88fc-7c351a75cec7.png) -# 💵 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: -

- Folder 02 -

+![Folder 02](https://user-images.githubusercontent.com/78161484/191273560-8f666f6c-c7b9-4bad-8369-46337f6243b2.png) -### 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/): -

- Verify 01 -

+![Verify 01](https://user-images.githubusercontent.com/78161484/190875518-828c0061-71de-42c2-b222-0b8427852d01.png) 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! -

- Verify 02 -

+![Verify 02](https://user-images.githubusercontent.com/78161484/190875635-f6d3aa36-47b2-4b09-ad6a-fe6df3fb11f1.png) If everything is correctly filled out, your contract page on the block explorer should display a new tab called `Contract`: -

- Verify 03 -

+![Verify 03](https://user-images.githubusercontent.com/78161484/190875780-6223b4b0-fecc-4e79-83bc-c810c5b0351c.png) ---- +*** -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: -

- Step 01 -

- +![Step 01](https://user-images.githubusercontent.com/78161484/190839624-495ef863-e177-4c62-81ca-680e5e6a4cab.png) -## ⚒ 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: -

- Step 02 -

+![Step 02](https://user-images.githubusercontent.com/78161484/189952656-eb7793cc-7dee-4307-88fc-7c351a75cec7.png) -# 💵 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: -

- Step 03 -

+![Step 03](https://user-images.githubusercontent.com/78161484/190875030-27137576-84b6-45a1-be1d-f52f55d6488f.png) -### 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/): -

- Verify 01 -

+![Verify 01](https://user-images.githubusercontent.com/78161484/190875518-828c0061-71de-42c2-b222-0b8427852d01.png) 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! -

- Verify 02 -

+![Verify 02](https://user-images.githubusercontent.com/78161484/190875635-f6d3aa36-47b2-4b09-ad6a-fe6df3fb11f1.png) If everything is correctly filled out, your contract page on the block explorer should display a new tab called `Contract`: -

- Verify 03 -

+![Verify 03](https://user-images.githubusercontent.com/78161484/190875780-6223b4b0-fecc-4e79-83bc-c810c5b0351c.png) ---- +*** -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-details/smart-contract-details/xrc-standards/xrc721.md b/get-details/smart-contract-details/xrc-standards/xrc721.md index 73da32a2..1d3c52c8 100644 --- a/get-details/smart-contract-details/xrc-standards/xrc721.md +++ b/get-details/smart-contract-details/xrc-standards/xrc721.md @@ -61,7 +61,7 @@ Provides the name of the token. Returns the total amount of tokens in the contract. `balanceOf(address account) → uint256`\ -Provides the number of non-fungible tokens in the owner's **** account. +Provides the number of non-fungible tokens in the owner's account. `ownerOf(tokenId) → address`\ Returns the NFT owner specified by `tokenId`. diff --git a/get-details/wallet-integration/metamask.md b/get-details/wallet-integration/metamask.md index 9297d2b2..14d3f7a1 100644 --- a/get-details/wallet-integration/metamask.md +++ b/get-details/wallet-integration/metamask.md @@ -84,11 +84,11 @@ To add `xinfin` mainnet, use following configuration: | | | | ------------------ | -------------------------------- | -| Network Name | XinFin | -| New RPC URL | https://rpc.xinfin.network | +| Network Name | XDC Network | +| New RPC URL | https://rpc.xdc.org | | Chain ID | 50 | | Currency Symbol | XDC | -| Block Explorer URL | https://explorer.xinfin.network/ | +| Block Explorer URL | https://xdc.blocksscan.io/ | ![xinfin\_add](https://user-images.githubusercontent.com/102393474/195908951-b74da582-4d4a-4d01-a759-e0b941285b6f.png) @@ -138,7 +138,7 @@ You can click on it to get more info: If you press `View on block explorer`, you will be redirected to Apothem Explorer website entry with your transaction. -*** + For more information about MetaMask, Please Visit [MetaMask Website](https://metamask.io/).\ For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).\ diff --git a/get-details/wallet-integration/walletconnect.md b/get-details/wallet-integration/walletconnect.md index 0433b637..8373d17b 100644 --- a/get-details/wallet-integration/walletconnect.md +++ b/get-details/wallet-integration/walletconnect.md @@ -1,5 +1,4 @@ --- -description: 'This article will teach you what WalletConnect is, what WalletConnect is used for, and how to connect WalletConnect to the XDC Network.' keywords: - docs - how to @@ -11,15 +10,18 @@ keywords: - dapp - provider - walletconnect +description: >- + This article will teach you what WalletConnect is, what WalletConnect is used + for, and how to connect WalletConnect to the XDC Network. --- -# WalletConnect +# Wallet Connect ![WalletConnect logo](https://raw.githubusercontent.com/XDC-Community/docs/main/.gitbook/assets/example-walletconnect-header.png) The communications protocol for web3. [WalletConnect](https://walletconnect.com/) brings the ecosystem together by enabling wallets and apps to securely connect and interact. Opening up a whole world of Dapps that were once only available to specific wallets. ---- +*** ## For What is Used @@ -31,45 +33,31 @@ The user can interact with any Dapp without comprising their private keys and wi To connect a Dapp on XDC Network and a Web3 wallet with WalletConnect, just open the app, and prepare your wallet. Click on WalletConnect link: -

- How to connect your Dapp to WalletConnect -

+![How to connect your Dapp to WalletConnect](https://raw.githubusercontent.com/XDC-Community/docs/main/.gitbook/assets/example-walletconnect-dapp-connect.png) A WalletConnect modal should pop-up, here you can connect your wallet by scanning the `QR Code` or going to `Desktop` tab, and choose another connection method: -

- How to connect your Dapp to WalletConnect How to connect your Dapp to WalletConnect -

+![How to connect your Dapp to WalletConnect](https://raw.githubusercontent.com/XDC-Community/docs/main/.gitbook/assets/example-walletconnect-modal-qrcode.png) ![How to connect your Dapp to WalletConnect](https://raw.githubusercontent.com/XDC-Community/docs/main/.gitbook/assets/example-walletconnect-modal-desktop.png) After connecting and approving the connection on your wallet, now you have access to your Dapp: -

- How to connect your Dapp to WalletConnect -

+![How to connect your Dapp to WalletConnect](https://raw.githubusercontent.com/XDC-Community/docs/main/.gitbook/assets/example-walletconnect-dapp-use.png) On your Dapp, try to click on a action button to trigger a wallet request, for example `eth_sign (standard)`: -

- How to connect your Dapp to WalletConnect -

+![How to connect your Dapp to WalletConnect](https://raw.githubusercontent.com/XDC-Community/docs/main/.gitbook/assets/example-walletconnect-dapp-actions.png) -

- How to connect your Dapp to WalletConnect -

+![How to connect your Dapp to WalletConnect](https://raw.githubusercontent.com/XDC-Community/docs/main/.gitbook/assets/example-walletconnect-dapp-pending.png) After approving the action on your wallet you will see a success message on Dapp :rocket: -

- How to connect your Dapp to WalletConnect -

+![How to connect your Dapp to WalletConnect](https://raw.githubusercontent.com/XDC-Community/docs/main/.gitbook/assets/example-walletconnect-dapp-approved.png) ## Understanding WalletConnect **How does it work**? It's based on a websocket JSON-RPC channel, WalletConnect is a simple infrastructure that can be setup by any developer. Using a Bridge server to relay the messages without having access to any of its contents. -

- How to connect your Dapp to WalletConnect -

+![How to connect your Dapp to WalletConnect](https://raw.githubusercontent.com/XDC-Community/docs/main/.gitbook/assets/example-walletconnect-diagram.png) WalletConnect is an protocol for connecting Dapps to Wallets by scanning a QR code, the protocol establishes a remote connection between two apps and/or devices using a Bridge server to relay payloads. These payloads are symmetrically encrypted through a shared key between the two peers. @@ -79,7 +67,7 @@ The connection is initiated by one peer displaying a QR Code or deep link with a You can easly test this with a prepared demo project (full code [here](https://github.com/XDC-Community/docs/tree/main/how-to/walletconnect/walletconnect-example-dapp)). Just download and and install dependencies by running this commands on terminal: -> :information_source: The demo was made base on `Node.js v16.X` version. +> :information\_source: The demo was made base on `Node.js v16.X` version. ```shell git clone git@github.com:XDC-Community/docs.git @@ -87,7 +75,7 @@ cd docs/how-to/walletconnect/walletconnect-example-dapp npm install ``` -Now we just need to start the web app by running ```npm run start```. With your browser opened, visit the [`http://localhost:3000/`](http://localhost:3000/) url :rocket: +Now we just need to start the web app by running `npm run start`. With your browser opened, visit the [`http://localhost:3000/`](http://localhost:3000/) url :rocket: ## How to connect a web Dapp with WalletConnect @@ -99,7 +87,7 @@ npm install --save @walletconnect/client @walletconnect/qrcode-modal This code will initiate a WalletConnect session and integrate user's wallet, copy and paste this in your Javascript/Typescript project: -> :information_source: Syntax shown below is Javascript ES6 which requires bundling and transpiling to run in web browsers. If unfamiliar we recommend setting up an environment using [Webpack Starter](https://github.com/wbkd/webpack-starter) or [Create React App](https://github.com/facebook/create-react-app) +> :information\_source: Syntax shown below is Javascript ES6 which requires bundling and transpiling to run in web browsers. If unfamiliar we recommend setting up an environment using [Webpack Starter](https://github.com/wbkd/webpack-starter) or [Create React App](https://github.com/facebook/create-react-app) ```javascript import WalletConnect from "@walletconnect/client"; @@ -169,9 +157,9 @@ npm install --save web3 @walletconnect/web3-provider First, instantiate your WalletConnect web3-provider using the following options: Infura or Custom RPC mapping -

-

Infura -

+

+ +Infura ```javascript import WalletConnectProvider from "@walletconnect/web3-provider"; @@ -185,11 +173,11 @@ const provider = new WalletConnectProvider({ await provider.enable(); ``` -

-
Custom RPC -

+

+ +Custom RPC ```javascript import WalletConnectProvider from "@walletconnect/web3-provider"; @@ -209,15 +197,13 @@ const provider = new WalletConnectProvider({ await provider.enable(); ``` -

-

Then you can integrate your dapp using your favorite Ethereum library: ethers.js or web3.js -

-

ethers.js -

+

+ +ethers.js ```javascript import { providers } from "ethers"; @@ -226,11 +212,11 @@ import { providers } from "ethers"; const web3Provider = new providers.Web3Provider(provider); ``` -

-
web3.js -

+

+ +web3.js ```javascript import Web3 from "web3"; @@ -239,9 +225,7 @@ import Web3 from "web3"; const web3 = new Web3(provider); ``` -

-

After setting up your provider you should listen to EIP-1193 events to detect accounts and chain change and also disconnection. @@ -286,4 +270,4 @@ const accounts = await web3.eth.getAccounts(); In this guide we cover the **standalone client**, but there are two common ways to integrate WalletConnect: standalone client and Web3Modal :mag: -If you want to know more about Web3Modal or other wallet integrations check [this page](https://docs.xdc.community/get-details/wallet-integration). \ No newline at end of file +If you want to know more about Web3Modal or other wallet integrations check [this page](https://docs.xdc.community/get-details/wallet-integration). diff --git a/get-details/xdpos2.0-migration.md b/get-details/xdpos2.0-migration.md new file mode 100644 index 00000000..fa8f6181 --- /dev/null +++ b/get-details/xdpos2.0-migration.md @@ -0,0 +1,62 @@ +# XDPoS 2.0 Migration Steps + +- [To Master Owner](#to-master-owner) +- [To Protocol Team and Private Network Owner](#to-protocol-team-and-private-network-owner) +- [Verification](#verification) + +## To Master Owner +Upgrading the consensus engine from XDPoS1.0 to XDC2.0 only takes a 3 simple steps. + +1. All master node owners confirm their participation by deploying the latest code version. + +2. The protocol team will create a code branch that specifies a future block height as the consensus switch point, and build a docker image accordingly. + +3. Master node owners restart their nodes using this docker image. This step must be done before the network has reached the switch block, and this is why we want to ensure everyone is on the same page via step-1. + +## To Protocol Team and Private Network Owner + +More generically, to upgrade a XDC devnet/testnet/private network that you own: + +1. Configure a switch block number: Check your current block height and decide on a future block number as the switch block point. The block height should allow enough time for you to complete all the steps below. Once decided, configure it here: https://github.com/XinFinOrg/XDPoSChain/blob/dev-upgrade/common/constants.go#L39 + +sample: +``` +var TIPV2SwitchBlock = big.NewInt(73737373) +``` + +2. Configure a voting quorum threshold: The maximum reasonable value is 2/3, giving your network the highest level of Byzantine fault tolerance of 1/3. The threshold can be set here: https://github.com/XinFinOrg/XDPoSChain/blob/dev-upgrade/params/config.go#L72. + +sample: +``` + Default: { + SwitchRound: 0, + CertThreshold: 73, // based on masternode is 108 + TimeoutSyncThreshold: 3, + TimeoutPeriod: 60, + MinePeriod: 10, + } +``` + +3. Redeploy. Rebuild the node binary based on your changes above, and then deploy the binary on all your masternodes. + +## Verification +To verify whether the switch was successful: +* Monitor the block height by attach into web3 portal +* From the dashboard and wait until the switch block is passed. +* Query web3 api, to see v2 block specific information + +``` +curl --location 'http://Yournode.RPC.Endpoint' \ +--header 'Content-Type: application/json' \ +--data '{"jsonrpc":"2.0","method":"XDPoS_getV2BlockByNumber","params":["latest"],"id":1}' +``` + +``` +{ + "result": { + "Hash": "0x123", + "Round": 10, + "Number": 10 // This number is bigger then 0 + } +} +``` \ No newline at end of file diff --git a/get-details/xip-proposals.md b/get-details/xip-proposals.md deleted file mode 100644 index 2f0934ef..00000000 --- a/get-details/xip-proposals.md +++ /dev/null @@ -1,52 +0,0 @@ -# XIP Proposals - -## XIPs - -XDC Network Improvement Proposals (XIPs) describe standards for the XDC platform, including core protocol specifications, client APIs, and contract standards. Network upgrades are discussed separately. - -### Contributing - -First review XIP-1. Then clone the repository and add your XIP to it. There is a [template XIP here](https://github.com/XDC-Community/XIPs.github.io/blob/main/XIPS/xip-template.md). Then submit a Pull Request to XDC Community's [XIPs repository](https://github.com/XDC-Community/XIPs.github.io/pulls). - -### XIP status terms - -* **Idea** - An idea that is pre-draft. This is not tracked within the XIP Repository. -* **Draft** - The first formally tracked stage of an XIP in development. An XIP is merged by an XIP Editor into the XIP repository when properly formatted. -* **Review** - An XIP Author marks an XIP as ready for and requesting Peer Review. -* **Last Call** - This is the final review window for an XIP before moving to FINAL. An XIP editor will assign Last Call status and set a review end date (\`last-call-deadline\`), typically 14 days later. If this period results in necessary normative changes it will revert the XIP to Review. -* **Final** - This XIP represents the final standard. A Final XIP exists in a state of finality and should only be updated to correct errata and add non-normative clarifications. -* **Stagnant** - Any XIP in Draft or Review if inactive for a period of 6 months or greater is moved to Stagnant. An XIP may be resurrected from this state by Authors or XIP Editors through moving it back to Draft. -* **Withdrawn** - The XIP Author(s) have withdrawn the proposed XIP. This state has finality and can no longer be resurrected using this XIP number. If the idea is pursued at later date it is considered a new proposal. -* **Living** - A special status for XIPs that are designed to be continually updated and not reach a state of finality. This includes most notably XIP-1. - -### XIP Types - -XIPs are separated into a number of types, and each has its own list of XIPs. - -#### Standard Track - -Describes any change that affects most or all Ethereum implementations, such as a change to the network protocol, a change in block or transaction validity rules, proposed application standards/conventions, or any change or addition that affects the interoperability of applications using Ethereum. Furthermore Standard XIPs can be broken down into the following categories. - -**Core** - -Improvements requiring a consensus fork, as well as changes that are not necessarily consensus critical but may be relevant to “core dev” discussions. - -**Networking** - -Includes improvements around devp2p, as well as proposed improvements to network protocol specifications. - -**Interface** - -Includes improvements around client API/RPC specifications and standards, and also certain language-level standards like method names and contract ABIs. The label “interface” aligns with the interfaces repo and discussion should primarily occur in that repository before an XIP is submitted to the XIPs repository. - -**XRC** - -Application-level standards and conventions, including contract standards such as token standards, name registries, URI schemes, library/package formats, and wallet formats. - -#### Meta - -Describes a process surrounding XDC Network or proposes a change to (or an event in) a process. Process XIPs are like Standards Track XIPs but apply to areas other than the XDPoS protocol itself. They may propose an implementation, but not to XDPoS's codebase; they often require community consensus; unlike Informational XIPs, they are more than recommendations, and users are typically not free to ignore them. Examples include procedures, guidelines, changes to the decision-making process, and changes to the tools or environment used in XDC Network development. Any meta-XIP is also considered a Process XIP. - -#### Informational - -Describes a XDC Network design issue, or provides general guidelines or information to the XDC community, but does not propose a new feature. Informational XIPs do not necessarily represent XDC community consensus or a recommendation, so users and implementers are free to ignore Informational XIPs or follow their advice. diff --git a/get-started/README.md b/get-started/README.md index fc82f20f..57a4dfa6 100644 --- a/get-started/README.md +++ b/get-started/README.md @@ -1,2 +1,7 @@ # Get Started +These documents will help you start to learn more about the XDC Network’s technology, terminology, and processes. If you are just beginning your journey with the XDC Network, we recommend you start here. Developers will find general and smart contract information that will introduce essential details regarding building with the XDC Network. +
+
+ +It is not necessary to review every document in order to have working knowledge of the XDC Network. Read through as needed or head to a specific section. diff --git a/get-started/blockchain-basics/what-is-a-blockchain.md b/get-started/blockchain-basics/what-is-a-blockchain.md index 422046e2..a9673fe0 100644 --- a/get-started/blockchain-basics/what-is-a-blockchain.md +++ b/get-started/blockchain-basics/what-is-a-blockchain.md @@ -1,12 +1,16 @@ # What is a Blockchain -A blockchain can be described simply through its name, but first let's take a look at its concept. Simply put, a blockchain is an open digital ledger that processes and records transactions. +A blockchain is a digital ledger that records and stores data in a decentralized manner. It is essentially a database that is managed by a network of computers, rather than a single central authority. Each block in the chain contains a cryptographic hash of the previous block, along with transaction data, and a timestamp. This creates a permanent and unalterable record of all transactions, making it very difficult to tamper with or manipulate the data. -Transactions on the network are processed, finalized, and recorded into groups called blocks. When a block is created, it makes a permanent record of all the transactions and state of the network. A cryptographic hash is then created to identify that block and can be used to verify its data. +One of the key features of a blockchain is its immutability, which means that once a transaction is recorded on the blockchain, it cannot be changed or deleted. This makes it a highly secure and transparent system, which is why it has become increasingly popular in the financial industry and beyond. + +Blockchains are used for a variety of purposes, including financial transactions, supply chain management, and identity verification. They can also be used to create smart contracts, which are self-executing contracts with the terms of the agreement written into code on the blockchain. + +Transactions on the network are processed, finalized, and recorded into groups called blocks by Validators . When a block is created, it makes a permanent record of all the transactions and state of the network. A cryptographic hash is then created to identify that block and can be used to verify its data. The chain aspect comes from each block being connected to each other. When a new block is created, data from the previous block is verified through its cryptographic hash, connecting the new block to the previous. This process continues as each block is created, moving the state of the network forward one block at a time. -So how are transactions verified and blocks created? The blockchain is operated by a global network of nodes. These nodes are basically computers that communicate with each other, transact data on the network, and create blocks. When a new block is created, nodes ensure that data across the network is aligned and verifies the history from the previous block. +The blockchain is operated by a global network of Validator nodes. These nodes are computers that, transact data, value, and create new blocks. When a new block is created, nodes ensure that data across the network is aligned and verifies the history from the previous block by getting consensus. diff --git a/get-started/blockchain-basics/what-is-a-dapp.md b/get-started/blockchain-basics/what-is-a-dapp.md index 2dc28c03..b486ca26 100644 --- a/get-started/blockchain-basics/what-is-a-dapp.md +++ b/get-started/blockchain-basics/what-is-a-dapp.md @@ -1,9 +1,16 @@ +--- +description: dApps are decentralized applications that operate on the blockchain +--- + # What is a dApp -Decentralized applications, commonly referred to as dApps, are applications that run on a decentralized network. With blockchain running on a network of nodes instead of centralized servers, applications built on them operate in a decentralized environment. This allows them to be accessible by participants on the network, provides transparency, and ensures that data and transactions are not owned by one governing authority. +An application on the blockchain is a decentralized application (dApp) that utilizes smart contracts to automate and execute transactions without the need for a central authority. The data and transactions are recorded on the blockchain, which provides transparency and security. Examples of blockchain applications include decentralized finance (DeFi) platforms, supply chain management systems, and voting systems. + +Blockchain applications have the potential to revolutionize the finance industry by enabling faster, more secure, and more transparent transactions. Decentralized finance (DeFi) platforms, for example, allow for peer-to-peer lending, borrowing, and trading of digital assets, without the need for intermediaries such as banks. This can reduce costs and increase access to financial services for individuals and businesses around the world. + + + + -The functionality of dApps is built using a blockchain technology called smart contracts. Smart contracts are basically a collection of code that execute commands on the blockchain. As more features and capabilities are built to operate the application, smart contracts are created to execute those functions. Ultimately, dApps operate through a collection of smart contracts on the blockchain. -So how do you use the dApp? Well, the collection of smart contracts built to run a dApp would be running on the back end. Users can interact with the back end through a front end user interface. When you are using an application online or on your phone, you are interacting with the front end. The front end is for interaction, with the backend executing functions and capabilities. -Not all dApps necessarily need a front end UI. Let's think about what an application is. An application simply executes a function or a need. Even a single smart contract can be an application if it executes a need. In a blockchain ecosystem, smart contracts can leverage other smart contracts built on the network. This can create functionalities that operate as applications all on the blockchain, or back end. diff --git a/get-started/blockchain-basics/xdc-wallets.md b/get-started/blockchain-basics/xdc-wallets.md new file mode 100644 index 00000000..e0b9b18e --- /dev/null +++ b/get-started/blockchain-basics/xdc-wallets.md @@ -0,0 +1,27 @@ +--- +description: >- + An XDC wallet is a digital wallet that allows users to store, send, and + receive XDC tokens. These wallets are similar to traditional wallets, but they + are digital and can be accessed from anywhere. +--- + +# XDC Wallets + + + + + +XDC wallets work by utilizing public-key cryptography. When a user creates an XDC wallet, they are given a public key and a private key. The public key is used to receive XDC tokens, while the private key is used to send XDC tokens. These keys are stored in the XDC blockchain network, which is a decentralized and distributed ledger. + +When a user wants to send XDC tokens to another user, they create a transaction and sign it with their private key. The transaction is then broadcasted to the XDC blockchain network, where it is verified by a network of nodes. Once the transaction is verified, the XDC tokens are transferred from the sender's wallet to the receiver's wallet. + +The XDC network is EVM compatible> The Ethereum Virtual Machine (EVM) is a decentralized virtual machine that was originally built on top of the Ethereum blockchain but has since been adopted by other chains and technology to leverage its functionality. The EVM is a critical component of the XDC ecosystem because it allows developers to write and deploy smart contracts on the XDC blockchain with traditionally Ethereum tool sets. + +Smart contracts are code that run on the blockchain, they are what make up Dapps, Tokens, and automated agreements on the network. They can be used to automate the execution of contracts, agreements, and other types of applications. Smart contracts are executed by the EVM, which runs on top of the XDC blockchain. + +The XDC network is fully compatible with the EVM, which means that developers can write and deploy smart contracts on the XDC network using the same tools and programming languages that they use on the Ethereum network. This is made possible by XDC's use of the Ethereum client, which provides full EVM compatibility. + +XDC's compatibility with the EVM makes it easier for developers to create and deploy decentralized applications (dApps) on the XDC network. These dApps can be used to create new financial solutions, such as decentralized exchanges, lending platforms, and payment systems as well as create fully autonomous start ups who leverage the blockchain infrastructure to run and scale globally.. + +\ +\ 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 - ``` - ![powershell_j6ZGJ6csen](https://user-images.githubusercontent.com/41552663/197033638-5698520b-0c45-46e4-99c7-c40bd584f23b.gif) - - ![powershell_2yD7EobabD](https://user-images.githubusercontent.com/41552663/197037734-13540079-1cbb-4a99-8485-a51e05d72d40.gif) - - 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 - - ![powershell_i3TJBhkko9](https://user-images.githubusercontent.com/41552663/197038983-2df3513b-6015-47be-b0c9-a7ee2db9aea3.gif) - -#### 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``` - -![powershell_sCPO8SxO9k](https://user-images.githubusercontent.com/41552663/197041710-8f88be4c-9271-4404-aa64-f7f4126284b7.gif) - -### 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``` - -![Code_0emPCIYoOP](https://user-images.githubusercontent.com/41552663/197043395-d71887d1-fac6-4cfe-95b5-11a1bef7acbf.gif) - -```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 ->>> -``` - -![Code_HfFpNWKCbB](https://user-images.githubusercontent.com/41552663/197049220-d3af6794-59df-4000-97aa-cf01b84c16a4.gif) - -Our balance in fact: - -![chrome_mT1p7EHfaU](https://user-images.githubusercontent.com/41552663/197049576-0e41dd28-d5be-4635-84e7-a2d1c63f27c0.gif) - - - - - -## Initializing a new Brownie Project - -Using ```brownie init``` will output us a project structure containing folder to initialize our new project (tokens, etc) - -![Code_jgK7UqBOBb](https://user-images.githubusercontent.com/41552663/197054279-45eb9155-7582-4619-956c-f956b56aae3c.gif) - -#### Transfering XDC between Accounts using Brownie - -below we are transfering some XDC main token between accounts using browning - -![Code_XJR9qIggCn](https://user-images.githubusercontent.com/41552663/197057983-92494e80-e1a1-413f-8332-e9e92c5e9d26.gif) - -![chrome_elStq0tBGn](https://user-images.githubusercontent.com/41552663/197058096-ea984de5-dec7-4fe8-896d-b0458988001d.gif) - -### 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) {} -} - ``` - -![Code_2zkYkM5fdW](https://user-images.githubusercontent.com/41552663/197070060-13cd5b75-3159-42dc-8088-3dc3c49c828d.png) - -![Code_tZNY8mdGRn](https://user-images.githubusercontent.com/41552663/197070549-10b2103e-c70e-42dc-b452-c279623accba.gif) - -Deployed Token - -![chrome_hHyRarZ9m5](https://user-images.githubusercontent.com/41552663/197072906-23aa7bc4-e090-4b1c-8c82-74e906920e3c.png) - -After deployment the we can see "Blast Token" on-chain https://explorer.apothem.network/tokens/xdcaccf490aea9a2c17d60a62672ee519e61b5a1ec5 - -### Adding the token to XDC Pay & transfering - - -![chrome_pZKaMfMkQ0](https://user-images.githubusercontent.com/41552663/197070978-70267fc6-ed58-4118-bacd-4264eea7abc1.gif) - - -![chrome_5QXMaeYvoG](https://user-images.githubusercontent.com/41552663/197072620-fb1c9fa0-1055-4048-b298-175ad079ca3e.gif) - -## 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 +``` + +![powershell\_j6ZGJ6csen](https://user-images.githubusercontent.com/41552663/197033638-5698520b-0c45-46e4-99c7-c40bd584f23b.gif) + +![powershell\_2yD7EobabD](https://user-images.githubusercontent.com/41552663/197037734-13540079-1cbb-4a99-8485-a51e05d72d40.gif) + +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 + +![powershell\_i3TJBhkko9](https://user-images.githubusercontent.com/41552663/197038983-2df3513b-6015-47be-b0c9-a7ee2db9aea3.gif) + +**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` + +![powershell\_sCPO8SxO9k](https://user-images.githubusercontent.com/41552663/197041710-8f88be4c-9271-4404-aa64-f7f4126284b7.gif) + +#### 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` + +![Code\_0emPCIYoOP](https://user-images.githubusercontent.com/41552663/197043395-d71887d1-fac6-4cfe-95b5-11a1bef7acbf.gif) + +`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 +>>> +``` + +![Code\_HfFpNWKCbB](https://user-images.githubusercontent.com/41552663/197049220-d3af6794-59df-4000-97aa-cf01b84c16a4.gif) + +Our balance in fact: + +![chrome\_mT1p7EHfaU](https://user-images.githubusercontent.com/41552663/197049576-0e41dd28-d5be-4635-84e7-a2d1c63f27c0.gif) + +### Initializing a new Brownie Project + +Using `brownie init` will output us a project structure containing folder to initialize our new project (tokens, etc) + +![Code\_jgK7UqBOBb](https://user-images.githubusercontent.com/41552663/197054279-45eb9155-7582-4619-956c-f956b56aae3c.gif) + +**Transfering XDC between Accounts using Brownie** + +below we are transfering some XDC main token between accounts using browning + +![Code\_XJR9qIggCn](https://user-images.githubusercontent.com/41552663/197057983-92494e80-e1a1-413f-8332-e9e92c5e9d26.gif) + +![chrome\_elStq0tBGn](https://user-images.githubusercontent.com/41552663/197058096-ea984de5-dec7-4fe8-896d-b0458988001d.gif) + +#### 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) {} +} +``` + +![Code\_2zkYkM5fdW](https://user-images.githubusercontent.com/41552663/197070060-13cd5b75-3159-42dc-8088-3dc3c49c828d.png) + +![Code\_tZNY8mdGRn](https://user-images.githubusercontent.com/41552663/197070549-10b2103e-c70e-42dc-b452-c279623accba.gif) + +Deployed Token + +![chrome\_hHyRarZ9m5](https://user-images.githubusercontent.com/41552663/197072906-23aa7bc4-e090-4b1c-8c82-74e906920e3c.png) + +After deployment the we can see "Blast Token" on-chain https://explorer.apothem.network/tokens/xdcaccf490aea9a2c17d60a62672ee519e61b5a1ec5 + +#### Adding the token to XDC Pay & transfering + +![chrome\_pZKaMfMkQ0](https://user-images.githubusercontent.com/41552663/197070978-70267fc6-ed58-4118-bacd-4264eea7abc1.gif) + +![chrome\_5QXMaeYvoG](https://user-images.githubusercontent.com/41552663/197072620-fb1c9fa0-1055-4048-b298-175ad079ca3e.gif) + +### Some transactions done + +https://explorer.apothem.network/txs/0x23bbf8d8f84bbfdc85cce7493cb388e968f0aed3715b95fa81d3ac7c1614d004#overview + +https://explorer.apothem.network/txs/0x2acf5757d236580c98b0c7e4ec864f700964ffa0cf3fcf7fe6130fe2a77a8d0c#overview diff --git a/get-started/smart-contracts.md b/get-started/smart-contracts.md index df508724..e4ae1770 100644 --- a/get-started/smart-contracts.md +++ b/get-started/smart-contracts.md @@ -12,24 +12,32 @@ A smart contract is a computer code running on a blockchain that establishes rul Here, we have an example of a rudimentary smart contract, where we use Set and Get functions: -`pragma solidity 0.4.0;`\ -`// Imagine a big integer that the whole world could share`\ -`contract SimpleStorage {`\ -`uint storedData;`\ -`function set(uint x) public {`\ -`storedData = x;`\ -`}`\ -`function get() constant public returns (uint) {`\ -`return storedData;`\ -`}`\ -`function increment (uint n) public {`\ -`storedData = storedData + n;`\ -`return;`\ -`}`\ -`function decrement (uint n) public {`\ -`storedData = storedData - n;`\ -`return;`\ -`}` +```solidity +pragma solidity 0.4.0; + +// Imagine a big integer that the whole world could share +contract SimpleStorage { + uint storedData; + + function set(uint x) public { + storedData = x; + } + + function get() constant public returns (uint) { + return storedData; + } + + function increment (uint n) public { + storedData = storedData + n; + return; + } + + function decrement (uint n) public { + storedData = storedData - n; + return; + } +} +``` ## Key Features of Smart Contracts diff --git a/get-started/tokenization.md b/get-started/tokenization.md index 7919ade1..7a62b9f4 100644 --- a/get-started/tokenization.md +++ b/get-started/tokenization.md @@ -1,6 +1,6 @@ # Tokenization -Tokenization is the act of digitizing something of value into the form of a token, or smart contract, on the blockchain. This can range from real-world assets like gold or real estate, to even data. As previously stated, anything that has value can be tokenized on the blockchain. Smart contracts allow these tokenized assets to be programmed for different use cases and provide adaptability to various types of value. +Tokenization is the act of digitizing something valuable on a blockchain using smart contracts. This can range from real-world assets like gold or real estate, to even data. As previously stated, anything that has value can be tokenized on the blockchain. Smart contracts allow these tokenized assets to be programmed for different use cases and provide adaptability to various types of value. Tokenizing introduces these valuable assets to the benefits of blockchain, such as security, transparency, speed, and accountability. With blockchain being open-source, these assets can be easily accessed, verified, and transacted, which allows them the ability to easily participate in the evolving economy of Web3. @@ -18,6 +18,5 @@ Fungible means these assets are divisible into smaller units of value. Let's say Non-Fungible means the asset can not be broken down into smaller units of value. This can be used to tokenize assets that are not meant to be shared or divisible. These tokens are usually used to represent a piece of art or any other single asset. -**** -**** + diff --git a/get-started/xdc-design/masternodes.md b/get-started/xdc-design/masternodes.md index eb194a02..ca485507 100644 --- a/get-started/xdc-design/masternodes.md +++ b/get-started/xdc-design/masternodes.md @@ -1,14 +1,10 @@ # Masternodes -The XDC Network’s operation relies on Masternodes which are operated by third parties. Some operators have set up multiple Masternodes; XinFin Fintech operates three Masternodes which it set up originally to run the Network at inception, whereas XDC Foundation does not operate any Masternodes. Each Masternode falls into one of three subcategories: Validator, Standby, or Archival. +The XDC Network relies upon a distributed network of Masternodes that run on a Delegated Proof of Stake consensus mechanism. These Masternodes can be identified in 2 categories: Validator Masternodes and Standby Masternodes. Both Masternodes require the operator to stake 10 million XDC and comply with KYC procedures. The staked XDC is locked in a smart contract and can be released only after a 30-day cool-off period following the operator’s resignation of the Masternode. The Validator and Standby Masternode operators are incentivized to maintain the Network—and ensure the Masternodes do not act maliciously against the network—since any loss of trust in the Network may result in a reduction in the value of the staked XDC which cannot be immediately disposed of. -Validator and Standby Masternodes require the operator stake 10 million XDC and comply with KYC procedures. The staked XDC is locked in a smart contract and can be released only after a 30-day cooling off period following the operator’s resignation of the Masternode. The Validator and Standby Masternode operators are incentivized to maintain the Network—and ensure the Masternodes do not act maliciously against the network—since any loss of trust in the Network may result in a reduction in the value of the staked XDC which cannot be immediately disposed of. - - - -There are 108 Validator Masternodes (or simply “**Validators**”) on the Network. Validators operate pursuant to the XDPoS consensus mechanism to validate blocks before they are recorded on the Network blockchain. Only Validators propose and validate new blocks. During each validation cycle, Validators are selected in a random round-robin process to propose and to validate new blocks. Except with regard to the three Validators operated by XinFin Fintech, the Project Team has no control over the operation of the 108 Validators and does not control or necessarily know where the nodes are set up geographically. +There are 108 Validator Masternodes (or simply “**Validators**”) on the Network, which operates pursuant to the XDPoS consensus mechanism to validate blocks before they are recorded on the blockchain. During each validation cycle, Validators are selected in a random round-robin process to propose and validate new blocks. Except with regard to the three Validators operated by XinFin Fintech, the Project Team has no control over the operation of the 108 Validators and does not control or necessarily know where the nodes are set up geographically. @@ -16,11 +12,11 @@ Changes to the Network protocol are safeguarded and decentralized through two di -Standby Masternodes (or “**Standby Nodes**”) are identical in form and function to Validators but do not participate in the validation process. Rather, as the name implies, Standby Nodes are on standby and are called into action only when the number of Validators drops below 108. As of September 26, 2022, there are 100 Standby Nodes on the Network out of a total available 192 (i.e. only 92 more Standby Nodes can be created). As with most Validators, all Standby Nodes are owned by independent third parties. +Standby Masternodes (or “**Standby Nodes**”) are identical in form and function to Validators but do not participate in the validation process. Rather, as the name implies, Standby Nodes are on standby and are called into action only when the number of Validators drops below 108. As with most Validators, all Standby Nodes are owned by independent third parties. -Archival Masternodes (or “**Archival Nodes**”) do not require any XDC be staked and serve a different purpose than Validators and Standby Nodes. Archival Nodes contain the same Network blockchain data and history that are tracked by Validators and Standby Nodes but lack validating functionality (meaning that even if all current 208 Validator and Standby Nodes unexpectedly went offline, no Archival Nodes could be promoted). Anyone can set up an Archival Node and parties have various reasons for doing so. A common reason for creating an Archival Node is to maintain a local copy of the Network blockchain which may be efficiently accessed by a third party’s other programs via API or otherwise. + diff --git a/get-started/xdc-design/xdpos-2.0.md b/get-started/xdc-design/xdpos-2.0.md index e8d1c33e..3e1757da 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` @@ -153,7 +153,7 @@ Liveness means the blockchain makes progress and new transactions are included. The HotStuff protocol is optimistically responsive: in optimistic condition (honest leader and synchronous network), it only takes 3 block arrival time (BAT) to finalize a block and the transactions it contains. In practice, due to our strict network requirement on master nodes eligibility, the maximum network round-trip latency should be well below 2 seconds. Therefore, we can set BAT to be 2 seconds. This means that, in optimistic conditions, the finalization latency is only 6 seconds. **`Algorithm 2 HotStuff protocol`** \ -**``**`1: tH ← dVALIDATOR_SET_SIZE × 2/3e . constant` \ +`1: tH ← dVALIDATOR_SET_SIZE × 2/3e . constant` \ `2: highQC ← qcgenesis; lockQC ← qcgenesis . the latest QC and lock variable . Optimistic path` \ `3: for curRound ← 1, 2, . . . do` \ `4: as a leader` \ diff --git a/get-started/xips.md b/get-started/xips.md index 9315e4b3..a842a398 100644 --- a/get-started/xips.md +++ b/get-started/xips.md @@ -26,61 +26,17 @@ It is highly recommended that a single XIP contain a single key proposal or new An XIP must meet certain minimum criteria. It must be a clear and complete description of the proposed enhancement. The enhancement must represent a net improvement. The proposed implementation, if applicable, must be solid and must not complicate the protocol unduly. -### Special requirements for Core XIPs +### Special Requirements for Core XIPs If a **Core** XIP mentions or proposes changes to the EVM (Ethereum Virtual Machine), an [EIP](https://eips.ethereum.org/) should be created that addresses the desired changes to the EVM. -## XIP Work Flow - -### Shepherding an XIP - -Parties involved in the process are you, the champion or _XIP author_, the [_XIP editors_](xips.md#XIP-editors), and the [_XDC Core Developers_](https://github.com/XDC-Community). - -Before you begin writing a formal XIP, you should vet your idea. Ask the XDC community first if an idea is original to avoid wasting time on something that will be rejected based on prior research. It is thus recommended to open a discussion thread on [XDC.dev](https://xdc.dev) to do this. - -Once the idea has been vetted, your next responsibility will be to present (by means of an XIP) the idea to the reviewers and all interested parties, invite editors, developers, and the community to give feedback on the aforementioned channels. You should try and gauge whether the interest in your XIP is commensurate with both the work involved in implementing it and how many parties will have to conform to it. For example, the work required for implementing a Core XIP will be much greater than for an XRC and the XIP will need sufficient interest from the XDC Network client teams. Negative community feedback will be taken into consideration and may prevent your XIP from moving past the Draft stage. - -### Core XIPs - -For Core XIPs, given that they require client implementations to be considered **Final** (see "XIPs Process" below), you will need to either provide an implementation for clients or convince clients to implement your XIP. - -The best way to get client implementers to review your XIP is to present it on an AllCoreDevs call. You can request to do so by posting a comment linking your XIP on an [AllCoreDevs agenda GitHub Issue](https://github.com/XDC-Community). - -The AllCoreDevs call serves as a way for client implementers to do three things. First, to discuss the technical merits of XIPs. Second, to gauge what other clients will be implementing. Third, to coordinate XIP implementation for network upgrades. - -These calls generally result in a "rough consensus" around what XIPs should be implemented. This "rough consensus" rests on the assumptions that XIPs are not contentious enough to cause a network split and that they are technically sound. - -:warning: The XIPs process and AllCoreDevs call were not designed to address contentious non-technical issues, but, due to the lack of other ways to address these, often end up entangled in them. This puts the burden on client implementers to try and gauge community sentiment, which hinders the technical coordination function of XIPs and AllCoreDevs calls. If you are shepherding an XIP, you can make the process of building community consensus easier by making sure that [the XDC.dev](https://xdc.dev) thread for your XIP includes or links to as much of the community discussion as possible and that various stakeholders are well-represented. - -_In short, your role as the champion is to write the XIP using the style and format described below, shepherd the discussions in the appropriate forums, and build community consensus around the idea._ - -### XIP Process - -The following is the standardization process for all XIPs in all tracks:![](../.gitbook/assets/XIP-process-update.jpg) - -**Idea** - An idea that is pre-draft. This is not tracked within the XIP Repository. - -**Draft** - The first formally tracked stage of an XIP in development. An XIP is merged by an XIP Editor into the XIP repository when properly formatted. - -**Review** - An XIP Author marks an XIP as ready for and requesting Peer Review. - -**Last Call** - This is the final review window for an XIP before moving to `Final`. An XIP editor will assign `Last Call` status and set a review end date (`last-call-deadline`), typically 14 days later. - -If this period results in necessary normative changes it will revert the XIP to `Review`. - -**Final** - This XIP represents the final standard. A Final XIP exists in a state of finality and should only be updated to correct errata and add non-normative clarifications. - -**Stagnant** - Any XIP in `Draft` or `Review` or `Last Call` if inactive for a period of 6 months or greater is moved to `Stagnant`. An XIP may be resurrected from this state by Authors or XIP Editors through moving it back to `Draft` or it's earlier status. If not resurrected, a proposal may stay forever in this status. - -> _XIP Authors are notified of any algorithmic change to the status of their XIP_ - -**Withdrawn** - The XIP Author(s) have withdrawn the proposed XIP. This state has finality and can no longer be resurrected using this XIP number. If the idea is pursued at later date it is considered a new proposal. +## Creating an XIP -**Living** - A special status for XIPs that are designed to be continually updated and not reach a state of finality. This includes most notably XIP-1. +### Contributing -## What belongs in a successful XIP? +First review XIP-1. Then clone the repository and add your XIP to it. There is a [template XIP here](https://github.com/XDC-Community/XIPs.github.io/blob/main/XIPS/xip-template.md). Then submit a Pull Request to XDC Community's [XIPs repository](https://github.com/XDC-Community/XIPs.github.io/pulls). -Each XIP should have the following parts: +**Each XIP should have the following parts:** * Preamble - RFC 822 style headers containing metadata about the XIP, including the XIP number, a short descriptive title (limited to a maximum of 44 characters), a description (limited to a maximum of 140 characters), and the author details. Irrespective of the category, the title and description should not include XIP number. See [below](XIP-1.md#XIP-header-preamble) for details. * Abstract - Abstract is a multi-sentence (short paragraph) technical summary. This should be a very terse and human-readable version of the specification section. Someone should be able to read only the abstract to get the gist of what this specification does. @@ -93,11 +49,11 @@ Each XIP should have the following parts: * Security Considerations - All XIPs must contain a section that discusses the security implications/considerations relevant to the proposed change. Include information that might be important for security discussions, surfaces risks and can be used throughout the life-cycle of the proposal. E.g. include security-relevant design decisions, concerns, important discussions, implementation-specific guidance and pitfalls, an outline of threats and risks and how they are being addressed. XIP submissions missing the "Security Considerations" section will be rejected. An XIP cannot proceed to status "Final" without a Security Considerations discussion deemed sufficient by the reviewers. * Copyright Waiver - All XIPs must be in the public domain. The copyright waiver MUST link to the license file and use the following wording: `Copyright and related rights waived via [CC0](../LICENSE.md).` -## XIP Formats and Templates +### XIPs formats and templates XIPs should be written in [markdown](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) format. There is a [template](https://github.com/XDC-Community/XIPs.github.io/blob/main/XIPS/xip-template.md) to follow. -## XIP Header Preamble +### Header and Preamble Each XIP must begin with an [RFC 822](https://www.ietf.org/rfc/rfc822.txt) style header preamble, preceded and followed by three hyphens (`---`). This header is also termed ["front matter" by Jekyll](https://jekyllrb.com/docs/front-matter/). The headers must appear in the following order. @@ -165,6 +121,54 @@ The `created` header records the date that the XIP was assigned a number. Both h XIPs may have a `requires` header, indicating the XIP numbers that this XIP depends on. +## XIP Work Flow + +### Shepherding an XIP + +Parties involved in the process are you, the champion or _XIP author_, the [_XIP editors_](xips.md#XIP-editors), and the [_XDC Core Developers_](https://github.com/XDC-Community). + +Before you begin writing a formal XIP, you should vet your idea. Ask the XDC community first if an idea is original to avoid wasting time on something that will be rejected based on prior research. It is thus recommended to open a discussion thread on [XDC.dev](https://xdc.dev) to do this. + +Once the idea has been vetted, your next responsibility will be to present (by means of an XIP) the idea to the reviewers and all interested parties, invite editors, developers, and the community to give feedback on the aforementioned channels. You should try and gauge whether the interest in your XIP is commensurate with both the work involved in implementing it and how many parties will have to conform to it. For example, the work required for implementing a Core XIP will be much greater than for an XRC and the XIP will need sufficient interest from the XDC Network client teams. Negative community feedback will be taken into consideration and may prevent your XIP from moving past the Draft stage. + +### Core XIPs + +For Core XIPs, given that they require client implementations to be considered **Final** (see "XIPs Process" below), you will need to either provide an implementation for clients or convince clients to implement your XIP. + +The best way to get client implementers to review your XIP is to present it on an AllCoreDevs call. You can request to do so by posting a comment linking your XIP on an [AllCoreDevs agenda GitHub Issue](https://github.com/XDC-Community). + +The AllCoreDevs call serves as a way for client implementers to do three things. First, to discuss the technical merits of XIPs. Second, to gauge what other clients will be implementing. Third, to coordinate XIP implementation for network upgrades. + +These calls generally result in a "rough consensus" around what XIPs should be implemented. This "rough consensus" rests on the assumptions that XIPs are not contentious enough to cause a network split and that they are technically sound. + +:warning: The XIPs process and AllCoreDevs call were not designed to address contentious non-technical issues, but, due to the lack of other ways to address these, often end up entangled in them. This puts the burden on client implementers to try and gauge community sentiment, which hinders the technical coordination function of XIPs and AllCoreDevs calls. If you are shepherding an XIP, you can make the process of building community consensus easier by making sure that [the XDC.dev](https://xdc.dev) thread for your XIP includes or links to as much of the community discussion as possible and that various stakeholders are well-represented. + +_In short, your role as the champion is to write the XIP using the style and format described below, shepherd the discussions in the appropriate forums, and build community consensus around the idea._ + +### XIP Process + +The following is the standardization process for all XIPs in all tracks:![](../.gitbook/assets/XIP-process-update.jpg) + +**Idea** - An idea that is pre-draft. This is not tracked within the XIP Repository. + +**Draft** - The first formally tracked stage of an XIP in development. An XIP is merged by an XIP Editor into the XIP repository when properly formatted. + +**Review** - An XIP Author marks an XIP as ready for and requesting Peer Review. + +**Last Call** - This is the final review window for an XIP before moving to `Final`. An XIP editor will assign `Last Call` status and set a review end date (`last-call-deadline`), typically 14 days later. + +If this period results in necessary normative changes it will revert the XIP to `Review`. + +**Final** - This XIP represents the final standard. A Final XIP exists in a state of finality and should only be updated to correct errata and add non-normative clarifications. + +**Stagnant** - Any XIP in `Draft` or `Review` or `Last Call` if inactive for a period of 6 months or greater is moved to `Stagnant`. An XIP may be resurrected from this state by Authors or XIP Editors through moving it back to `Draft` or it's earlier status. If not resurrected, a proposal may stay forever in this status. + +> _XIP Authors are notified of any algorithmic change to the status of their XIP_ + +**Withdrawn** - The XIP Author(s) have withdrawn the proposed XIP. This state has finality and can no longer be resurrected using this XIP number. If the idea is pursued at later date it is considered a new proposal. + +**Living** - A special status for XIPs that are designed to be continually updated and not reach a state of finality. This includes most notably XIP-1. + ## Linking to External Resources Links to external resources **SHOULD NOT** be included. External resources may disappear, move, or change unexpectedly. @@ -189,6 +193,7 @@ The current XIP editors are * Jon McBee (@walterblueu) * Fisher Yu (@fishermanymc) +* Phillipe Menezes Emeritus XIP editors are @@ -240,6 +245,8 @@ XIPs are encouraged to follow [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt) f > The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119. + + ## History This document was derived heavily from [Ethereum's EIP-1](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1.md) written by Martin Becze, Hudson Jameson, et al. which in turn was derived from [Bitcoin's BIP-0001](https://github.com/bitcoin/bips) written by Amir Taaki which in turn was derived from [Python's PEP-0001](https://www.python.org/dev/peps/). In many places text was simply copied and modified. Although the PEP-0001 text was written by Barry Warsaw, Jeremy Hylton, and David Goodger, they are not responsible for its use in the XDC Network Improvement Process, and should not be bothered with technical questions specific to the XDC Network or the XIP. Please direct all comments to the XIP editors. 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 -
-

- -Plugin logo - -

-
+\ + + +[![Plugin logo](https://github.com/GoPlugin/Plugin/blob/main/docs/plugin.png)](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/goplugin/how-to-articles.md b/goplugin/how-to-articles.md index 09616a6e..0512dad0 100644 --- a/goplugin/how-to-articles.md +++ b/goplugin/how-to-articles.md @@ -1,56 +1,46 @@ # How-to Articles ---- +*** ## How to.. Access GoPlugin community support -Simply join the official community [discord server](discord.gg/PtSFYtMkCu) where you can get access to the both community resources & the GoPlugin team. - +Simply join the official community [discord server](discord.gg/PtSFYtMkCu/) where you can get access to the both community resources & the GoPlugin team. ## How to.. Become a GoPlugin Node Operator - The best resources to aid with setting up your node are as follows; - 1. Keep up to date with changes on the [official documentation](https://docs.goplugin.co/), paying special attention to the [system requirements](https://docs.goplugin.co/plugin-installations/how-to-install-plugin-node#system-requirements) as these can change & is something to consider when choosing the specs of your Virtual Private Server (VPS). - - 2. The offical github [Plugin-deployment repository](https://github.com/GoPlugin/plugin-deployment) which has all the detailed guides on how to install and manage your node. +1. Keep up to date with changes on the [official documentation](https://docs.goplugin.co/), paying special attention to the [system requirements](https://docs.goplugin.co/plugin-installations/how-to-install-plugin-node#system-requirements) as these can change & is something to consider when choosing the specs of your Virtual Private Server (VPS). +2. The offical github [Plugin-deployment repository](https://github.com/GoPlugin/plugin-deployment) which has all the detailed guides on how to install and manage your node. **NOTE:** _The recommended and most widely supported approach to installing your GoPlugin node is using what is called the 'Modular Script' method._ ### How to.. Select a VPS to host your node -This is a commonly asked question on the official community [discord server](discord.gg/PtSFYtMkCu). The following are the current list of providers that node operators use. Be sure to factor in the above system requirements. - - - [Racknerd](https://tinyurl.com/BlackFridayPLI) - - [Liteserver](https://liteserver.nl/nvme-ssd-vps/) - - [Netcup](https://www.netcup.de/vserver/vps.php#v-server-details) - - [Strato](https://www.strato.de/server/linux-vserver/) - - [Hetzner](https://www.hetzner.com/cloud) - - [Vultr](https://www.vultr.com/) - - [Contabo](https://contabo.com/) - - [Servarica](https://servarica.com/) +This is a commonly asked question on the official community [discord server](discord.gg/PtSFYtMkCu/). The following are the current list of providers that node operators use. Be sure to factor in the above system requirements. +* [Racknerd](https://tinyurl.com/BlackFridayPLI) +* [Liteserver](https://liteserver.nl/nvme-ssd-vps/) +* [Netcup](https://www.netcup.de/vserver/vps.php#v-server-details) +* [Strato](https://www.strato.de/server/linux-vserver/) +* [Hetzner](https://www.hetzner.com/cloud) +* [Vultr](https://www.vultr.com/) +* [Contabo](https://contabo.com/) +* [Servarica](https://servarica.com/) Do NOT use the following provider(s) as previous nodes have experienced issues simply due to being associated with crypto; - - EthernetServers +* EthernetServers **NOTE ::** _This is simply a list of current known providers and is not exhaustive. None of the providers listed here are in anyway officially endorsed by GoPlugin._ ---- - +*** ## How to.. Monitor your node While there are many platforms available that will provide various levels of monitoring, we have made every effort to eliminate costs and so the following solutions are proposed; - - [UptimeRobot](https://uptimerobot.com/) - This is a free service and provides basic ping and port checking monitor with email & app push notifications - - - [Netdata](https://www.netdata.cloud/) - This is a free service which provides detailed system & process monitoring with all historic data stored locally on the host system. So from a security perspective your node data stays on your node. +* [UptimeRobot](https://uptimerobot.com/) This is a free service and provides basic ping and port checking monitor with email & app push notifications +* [Netdata](https://www.netdata.cloud/) This is a free service which provides detailed system & process monitoring with all historic data stored locally on the host system. So from a security perspective your node data stays on your node. - You can install netdata with configuration for monitoring the plugin node processes using the following script should you wish; - https://github.com/inv4fee2020/pli_netdata - + You can install netdata with configuration for monitoring the plugin node processes using the following script should you wish; https://github.com/inv4fee2020/pli\_netdata diff --git a/how-to/.DS_Store b/how-to/.DS_Store deleted file mode 100644 index 38bc9c9e..00000000 Binary files a/how-to/.DS_Store and /dev/null differ 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 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 + +![image](https://user-images.githubusercontent.com/114102465/203121145-7cc2a09d-4b2d-4606-90a7-8531c036afd4.png) + + +[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. + +![image](https://user-images.githubusercontent.com/114102465/203061766-76fbddb4-35c4-40d7-82fb-c985eed36e70.png) + + +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. + +![image](https://user-images.githubusercontent.com/114102465/203102902-22b85584-271c-4755-8fc1-975955cecd80.png) + +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). + +![image](https://user-images.githubusercontent.com/114102465/203111916-f92d40c2-20d6-4e20-ae21-1e547f5d5d94.png) + +# 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. +![image](https://user-images.githubusercontent.com/114102465/203114917-29ec08e6-3810-45ef-995a-771c52ea967c.png) + +![image](https://user-images.githubusercontent.com/114102465/203115094-9e3dbfc4-5f85-41d7-8bd4-c6ef3705bf65.png) + +![image](https://user-images.githubusercontent.com/114102465/203115311-5c360ae2-381b-49f6-bc89-da87ded7818a.png) + +![image](https://user-images.githubusercontent.com/114102465/203115584-93e90371-8560-460d-8758-a5024d51e4d6.png) + +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 diff --git a/how-to/openzeppelin/.DS_Store b/how-to/openzeppelin/.DS_Store deleted file mode 100644 index f06d41c5..00000000 Binary files a/how-to/openzeppelin/.DS_Store and /dev/null differ 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 ``` -Screenshot 2022-09-13 at 11 56 26 AM +![Screenshot 2022-09-13 at 11 56 26 AM](https://user-images.githubusercontent.com/35517007/189841544-480b1a9c-b5d8-483c-a77e-b04501f6f121.png) -- 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 -Screenshot 2022-09-25 at 12 12 40 AM +Now, you will have a folder structure as below ![Screenshot 2022-09-25 at 12 12 40 AM](https://user-images.githubusercontent.com/35517007/192116380-698146f9-860f-4748-95f6-cba2cfa2edde.png) -# 💵 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) -Screenshot 2022-09-13 at 12 31 31 PM +![Screenshot 2022-09-13 at 12 31 31 PM](https://user-images.githubusercontent.com/35517007/189842148-a3d20b76-e14a-44fa-9c94-445825acd42b.png) -- 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) -Screenshot 2022-09-13 at 12 35 05 PM +![Screenshot 2022-09-13 at 12 35 05 PM](https://user-images.githubusercontent.com/35517007/189842216-01c87935-4b4e-49bc-89ea-11026250dbf8.png) -## 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. - Screenshot 2022-09-18 at 12 27 44 AM +* 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. ![Screenshot 2022-09-18 at 12 27 44 AM](https://user-images.githubusercontent.com/35517007/190872826-b3437164-e6a8-487d-91c7-4a1d85d341d1.png) Click on the `Export Private key` inside the popup. -Screenshot 2022-09-18 at 12 31 05 AM +![Screenshot 2022-09-18 at 12 31 05 AM](https://user-images.githubusercontent.com/35517007/190872880-c0c34a79-b81f-40f5-895d-d29714ef42b6.png) Enter the password that you used while creating the account. -Screenshot 2022-09-18 at 12 31 20 AM +![Screenshot 2022-09-18 at 12 31 20 AM](https://user-images.githubusercontent.com/35517007/190872906-4cf58f76-bb80-4a53-a496-b05a33217758.png) Copy your private key. This key will be used to sign transactions when deploying the contract through hardhat. -Screenshot 2022-09-18 at 12 31 35 AM +![Screenshot 2022-09-18 at 12 31 35 AM](https://user-images.githubusercontent.com/35517007/190872961-7ffb8329-2601-4346-bbb0-7a4ff38fd5f8.png) -## ⚒ 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/): -

- -Screenshot 2022-10-05 at 11 26 10 AM - -

+![Screenshot 2022-10-05 at 11 26 10 AM](https://user-images.githubusercontent.com/35517007/194009497-9deffaf8-dc30-482a-a143-f4cb972e1a53.png) 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! -

- Screenshot 2022-10-05 at 11 28 46 AM - - -

+![Screenshot 2022-10-05 at 11 28 46 AM](https://user-images.githubusercontent.com/35517007/194009622-ea5966ba-aa15-4f81-ba94-bd2da2ca7dbf.png) If everything is correctly filled out, your contract page on the block explorer should display a new tab called `Contract`: -

- -Screenshot 2022-10-05 at 11 35 12 AM - -

+![Screenshot 2022-10-05 at 11 35 12 AM](https://user-images.githubusercontent.com/35517007/194009732-96bdc2be-cb9a-4fff-895c-9bcb7a1feb10.png) In this page you can Read from, Write to, or simply read the information tied to your Smart Contract on the blockchain: -

- Screenshot 2022-10-05 at 1 28 22 PM - -

+![Screenshot 2022-10-05 at 1 28 22 PM](https://user-images.githubusercontent.com/35517007/194010105-908c60ed-1261-4eac-b752-6b1f6feb8cc9.png) ---- +*** -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! -

-

+![Egg Gacha!](https://user-images.githubusercontent.com/78161484/193483143-7589a63f-4204-4adb-9394-42544497e2c2.png) + +**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: -

- Truffle Workspace -

- +![Truffle Workspace](https://user-images.githubusercontent.com/78161484/193672515-d058ee10-70ee-4693-91f0-546592efe52a.png) -## 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: -

- Hardhat Workspace -

+![Hardhat Workspace](https://user-images.githubusercontent.com/78161484/193684235-f794ebff-40f1-463d-87fd-039b9a4fa6cb.png) -# 📀 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. -

- Solidity Flattening 01 -

+![Solidity Flattening 01](https://user-images.githubusercontent.com/78161484/193687692-ededd9b9-3466-496e-bc25-6e250533327d.png) -### 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: - -

- Solidity Flattening 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: -### Step 03 +![Solidity Flattening 02](https://user-images.githubusercontent.com/78161484/193695078-ee199266-0103-405d-bf58-a62ee666dd87.png) - - 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`; - -

- Solidity Flattening 03 -

+#### 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`; + +![Solidity Flattening 03](https://user-images.githubusercontent.com/78161484/193696014-c496f3b6-7d8d-4011-bc2e-2a93fbffcc2a.png) By the end of this process, your folder should look like this: -

- Solidity Flattening 04 -

+![Solidity Flattening 04](https://user-images.githubusercontent.com/78161484/193696481-44aad18b-0384-4895-91ec-3299751fb53f.png) -: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/`: -

- Egg Gacha Front-end -

+![Egg Gacha Front-end](https://user-images.githubusercontent.com/78161484/193703640-1fcd5cf2-d8e1-47b2-88a6-803cb496f604.png) 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: -

- Egg Gacha Folder 01 -

+![Egg Gacha Folder 01](https://user-images.githubusercontent.com/78161484/193709413-8a2f95ed-64cf-4bbf-b28e-0f2ad9246ccc.png) 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: -

- Egg Gacha Folder 02 -

+![Egg Gacha Folder 02](https://user-images.githubusercontent.com/78161484/193714901-0f6519b8-433a-46e4-aa98-df0678f2c8cb.png) -## 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 new file mode 100644 index 00000000..65e3b6d1 --- /dev/null +++ b/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-foundry.md @@ -0,0 +1,578 @@ +# 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-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 + +![image](https://user-images.githubusercontent.com/114102465/203121145-7cc2a09d-4b2d-4606-90a7-8531c036afd4.png) + +[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 +``` + +1. Initialize our Foundry project within our XRC20\_Royalty folder: + +```bash +forge init +``` + +1. Install Solmate into our Foundry project: + +```bash +forge install rari-capital/solmate +``` + +1. Create a remappings.txt file for the Solmate library we just added: + +```bash +touch remappings.txt +``` + +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. + +![image](https://user-images.githubusercontent.com/114102465/203061766-76fbddb4-35c4-40d7-82fb-c985eed36e70.png) + +1. 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 {} +``` + +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; +} +``` + +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: + +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); + } +} +``` + +1. 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; + } +``` + +1. 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; +} +``` + +1. 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); + } + +} +``` + +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); + 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); + } +``` + +1. 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); + } +} +``` + +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` + +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. + +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 + +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` + +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. + +![image](https://user-images.githubusercontent.com/114102465/203102902-22b85584-271c-4755-8fc1-975955cecd80.png) + +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). + +![image](https://user-images.githubusercontent.com/114102465/203111916-f92d40c2-20d6-4e20-ae21-1e547f5d5d94.png) + +## 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. ![image](https://user-images.githubusercontent.com/114102465/203114917-29ec08e6-3810-45ef-995a-771c52ea967c.png) + +![image](https://user-images.githubusercontent.com/114102465/203115094-9e3dbfc4-5f85-41d7-8bd4-c6ef3705bf65.png) + +![image](https://user-images.githubusercontent.com/114102465/203115311-5c360ae2-381b-49f6-bc89-da87ded7818a.png) + +![image](https://user-images.githubusercontent.com/114102465/203115584-93e90371-8560-460d-8758-a5024d51e4d6.png) + +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/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 - -

- hardhat -

+# 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://raw.githubusercontent.com/menezesphill/application\_utils/main/hardhaticon.png) [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: - -

- hardhat config -

+![hardhat config](https://user-images.githubusercontent.com/78161484/191259993-b817901f-7df9-4df1-bb1c-c4805c416974.png) 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: -

- hardhat folder -

+![hardhat folder](https://user-images.githubusercontent.com/14329097/192099706-bcd0f3ad-2ad1-4a3a-880f-9dcc5bbe4a72.png) -## ⚒ 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: -

- Step 02 -

+![Step 02](https://user-images.githubusercontent.com/78161484/189952656-eb7793cc-7dee-4307-88fc-7c351a75cec7.png) -# 💵 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: -

- Folder 02 -

+![Folder 02](https://user-images.githubusercontent.com/14329097/192099710-95371105-2268-49bf-b0e6-121de01dc651.png) 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/): -

- Verify 01 -

+![Verify 01](https://user-images.githubusercontent.com/78161484/190875518-828c0061-71de-42c2-b222-0b8427852d01.png) 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! -

- Verify 02 -

+![Verify 02](https://user-images.githubusercontent.com/78161484/190875635-f6d3aa36-47b2-4b09-ad6a-fe6df3fb11f1.png) If everything is correctly filled out, your contract page on the block explorer should display a new tab called `Contract`: -

- Verify 03 -

+![Verify 03](https://user-images.githubusercontent.com/78161484/190875780-6223b4b0-fecc-4e79-83bc-c810c5b0351c.png) -## 🔍 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. -

- Verify 04 -

+![Verify 04](https://user-images.githubusercontent.com/78161484/190876289-57de5994-809a-4307-b68d-6bb37e3601af.png) 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: -

- Verify 05 -

+![Verify 05](https://user-images.githubusercontent.com/78161484/190876402-32e800d4-b456-499d-8255-ba10aa35c0af.png) After clicking in `Write`, you'll need to confirm the transaction on the XDCPay wallet: -

- Verify 05 -

+![Verify 05](https://user-images.githubusercontent.com/78161484/190876653-eb8e558b-2b09-4c0f-ad5f-a3d17a54bf30.png) 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 - -

- hardhat -

+# 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://raw.githubusercontent.com/menezesphill/application\_utils/main/hardhaticon.png) [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: - -

- hardhat config -

+![hardhat config](https://user-images.githubusercontent.com/78161484/191259993-b817901f-7df9-4df1-bb1c-c4805c416974.png) 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: -

- hardhat folder -

+![hardhat folder](https://user-images.githubusercontent.com/78161484/191263408-af21bd08-98a8-440c-9270-7f9960bb531d.png) -## ⚒ 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: -

- Step 02 -

+![Step 02](https://user-images.githubusercontent.com/78161484/189952656-eb7793cc-7dee-4307-88fc-7c351a75cec7.png) -# 💵 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: -

- Folder 02 -

+![Folder 02](https://user-images.githubusercontent.com/78161484/191273560-8f666f6c-c7b9-4bad-8369-46337f6243b2.png) 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/): -

- Verify 01 -

+![Verify 01](https://user-images.githubusercontent.com/78161484/190875518-828c0061-71de-42c2-b222-0b8427852d01.png) 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! -

- Verify 02 -

+![Verify 02](https://user-images.githubusercontent.com/78161484/190875635-f6d3aa36-47b2-4b09-ad6a-fe6df3fb11f1.png) If everything is correctly filled out, your contract page on the block explorer should display a new tab called `Contract`: -

- Verify 03 -

+![Verify 03](https://user-images.githubusercontent.com/78161484/190875780-6223b4b0-fecc-4e79-83bc-c810c5b0351c.png) -## 🔍 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. -

- Verify 04 -

+![Verify 04](https://user-images.githubusercontent.com/78161484/190876289-57de5994-809a-4307-b68d-6bb37e3601af.png) 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: -

- Verify 05 -

+![Verify 05](https://user-images.githubusercontent.com/78161484/190876402-32e800d4-b456-499d-8255-ba10aa35c0af.png) After clicking in `Write`, you'll need to confirm the transaction on the XDCPay wallet: -

- Verify 05 -

+![Verify 05](https://user-images.githubusercontent.com/78161484/190876653-eb8e558b-2b09-4c0f-ad5f-a3d17a54bf30.png) 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-remix.md b/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-remix.md index ddc37a65..408733de 100644 --- a/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-remix.md +++ b/learn/how-to-articles/how-to-create-and-deploy-an-xrc20-token-using-remix.md @@ -390,4 +390,4 @@ You can check your successful transaction on the [Block Explorer!](https://explo *** For more information about Remix IDE, Please Visit [Remix IDE Documentation](https://remix-ide.readthedocs.io/en/latest/).\ -For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).\ +For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).\\ 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: -

- Step 01 -

- +![Step 01](https://user-images.githubusercontent.com/78161484/190839624-495ef863-e177-4c62-81ca-680e5e6a4cab.png) -## ⚒ 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: -

- Step 02 -

+![Step 02](https://user-images.githubusercontent.com/78161484/189952656-eb7793cc-7dee-4307-88fc-7c351a75cec7.png) -# 💵 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: -

- Step 03 -

+![Step 03](https://user-images.githubusercontent.com/78161484/190875030-27137576-84b6-45a1-be1d-f52f55d6488f.png) 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/): -

- Verify 01 -

+![Verify 01](https://user-images.githubusercontent.com/78161484/190875518-828c0061-71de-42c2-b222-0b8427852d01.png) 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! -

- Verify 02 -

+![Verify 02](https://user-images.githubusercontent.com/78161484/190875635-f6d3aa36-47b2-4b09-ad6a-fe6df3fb11f1.png) If everything is correctly filled out, your contract page on the block explorer will display a new tab called `Contract`: -

- Verify 03 -

+![Verify 03](https://user-images.githubusercontent.com/78161484/190875780-6223b4b0-fecc-4e79-83bc-c810c5b0351c.png) -## 🔍 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. -

- Verify 04 -

+![Verify 04](https://user-images.githubusercontent.com/78161484/190876289-57de5994-809a-4307-b68d-6bb37e3601af.png) You can try transfering `500 MTK` tokens that we have just created to a new wallet `xdc0431d52fe37f3839895018272dfa3ba189fce07e`. Lets fill out the `recipient` field with the new wallet address, and fill out the `amout` field with `500 * 10^18`. Remember that our token has 18 decimals, and when you write numbers with decimals to the blockchain you must to account for the decimals as the virtual machine does not understand floating numbers like we humans do: -

- Verify 05 -

+![Verify 05](https://user-images.githubusercontent.com/78161484/190876402-32e800d4-b456-499d-8255-ba10aa35c0af.png) After clicking `Write`, you need to confirm the transaction on the XDCPay wallet: -

- Verify 05 -

+![Verify 05](https://user-images.githubusercontent.com/78161484/190876653-eb8e558b-2b09-4c0f-ad5f-a3d17a54bf30.png) 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 - -

- hardhat -

+# 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://raw.githubusercontent.com/menezesphill/application\_utils/main/hardhaticon.png) [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: - -

- hardhat config -

+![hardhat config](https://user-images.githubusercontent.com/78161484/191259993-b817901f-7df9-4df1-bb1c-c4805c416974.png) 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: -

- hardhat folder -

+![hardhat folder](https://user-images.githubusercontent.com/78161484/191263408-af21bd08-98a8-440c-9270-7f9960bb531d.png) -## ⚒ 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: -

- Step 02 -

+![Step 02](https://user-images.githubusercontent.com/78161484/189952656-eb7793cc-7dee-4307-88fc-7c351a75cec7.png) -# 💵 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/) -![XRC721_0](https://user-images.githubusercontent.com/102393474/192279556-98d2fcb1-06aa-4b5b-8462-05a84489026b.png) -![xrc721_1](https://user-images.githubusercontent.com/102393474/192279202-f9204bec-48a8-4a0a-8d7f-cd2c93218a42.png) - +![XRC721\_0](https://user-images.githubusercontent.com/102393474/192279556-98d2fcb1-06aa-4b5b-8462-05a84489026b.png) ![xrc721\_1](https://user-images.githubusercontent.com/102393474/192279202-f9204bec-48a8-4a0a-8d7f-cd2c93218a42.png) -# 🔍 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/): -

- Verify 01 -

+![Verify 01](https://user-images.githubusercontent.com/78161484/190875518-828c0061-71de-42c2-b222-0b8427852d01.png) 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! -

- Verify 02 -

+![Verify 02](https://user-images.githubusercontent.com/78161484/190875635-f6d3aa36-47b2-4b09-ad6a-fe6df3fb11f1.png) If everything is correctly filled out, your contract page on the block explorer will display a new tab called `Contract`: -

- Verify 03 -

- -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). +![Verify 03](https://user-images.githubusercontent.com/78161484/190875780-6223b4b0-fecc-4e79-83bc-c810c5b0351c.png) +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-create-and-deploy-an-xrc721-nft-using-remix.md b/learn/how-to-articles/how-to-create-and-deploy-an-xrc721-nft-using-remix.md index 89cd91ae..94ea6968 100644 --- a/learn/how-to-articles/how-to-create-and-deploy-an-xrc721-nft-using-remix.md +++ b/learn/how-to-articles/how-to-create-and-deploy-an-xrc721-nft-using-remix.md @@ -404,4 +404,4 @@ You can check your successful transaction on the [Block Explorer!](https://explo *** For more information about Remix IDE, Please Visit [Remix IDE Documentation](https://remix-ide.readthedocs.io/en/latest/).\ -For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).\ +For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).\\ diff --git a/learn/how-to-articles/how-to-create-and-deploy-an-xrc721-nft-using-truffle.md b/learn/how-to-articles/how-to-create-and-deploy-an-xrc721-nft-using-truffle.md index a7c423ee..89b49fae 100644 --- a/learn/how-to-articles/how-to-create-and-deploy-an-xrc721-nft-using-truffle.md +++ b/learn/how-to-articles/how-to-create-and-deploy-an-xrc721-nft-using-truffle.md @@ -546,4 +546,4 @@ You can also check our successful transaction on the [Block Explorer!](https://e *** 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/).\ +For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).\\ diff --git a/learn/how-to-articles/how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-remix.md b/learn/how-to-articles/how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-remix.md index 2bf37514..9f3dd594 100644 --- a/learn/how-to-articles/how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-remix.md +++ b/learn/how-to-articles/how-to-deploy-your-first-smart-contract-on-the-xdc-network-using-remix.md @@ -244,4 +244,4 @@ We can easily test our contract with the help of that contract address. To start *** For more information about Remix IDE, Please Visit [Remix IDE Documentation](https://remix-ide.readthedocs.io/en/latest/).\ -For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).\ +For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).\\ 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: -

- Step 01 -

+![Step 01](https://user-images.githubusercontent.com/78161484/189928139-f8448866-b691-486c-a300-2b7dd21f10c1.png) -## ⚒ 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: -

- Step 02 -

+![Step 02](https://user-images.githubusercontent.com/78161484/189952656-eb7793cc-7dee-4307-88fc-7c351a75cec7.png) -# 🍕 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: -

- Step 03 -

+![Step 03](https://user-images.githubusercontent.com/78161484/189987467-d1dc7cb8-623b-4e94-a4fa-f8732f46426d.png) -## 🍕 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/): -

- Verify 01 -

+![Verify 01](https://user-images.githubusercontent.com/78161484/190028078-ebc0f083-28a5-4772-88c1-ef49e91681fa.png) -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! -

- Verify 02 -

+![Verify 02](https://user-images.githubusercontent.com/78161484/190028508-003c942d-685a-4d14-9d93-264e7ff4a0b5.png) If everything is correctly filled out, your contract page on the block explorer should display a new tab called `Contract`: -

- Verify 03 -

+![Verify 03](https://user-images.githubusercontent.com/78161484/190029029-2547af3f-d32c-48d6-a785-e47b1f7a91c5.png) On this page you can read from, write to, or simply read the information tied to your smart contract on the blockchain: -

- Verify 03 -

- - ---- - -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). - - - - +![Verify 03](https://user-images.githubusercontent.com/78161484/190030842-4ab30b85-f87b-43d1-a8b2-8d089abb1a34.png) +*** +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: -

- Screenshot 2022-09-29 at 1 01 13 PM +![Screenshot 2022-09-29 at 1 01 13 PM](https://user-images.githubusercontent.com/35517007/192987763-26cd7979-0e21-4804-b3c3-75ba66a8e1b0.png) -

- -# 📝 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: -

- Screenshot 2022-09-29 at 1 03 39 PM -

- +![Screenshot 2022-09-29 at 1 03 39 PM](https://user-images.githubusercontent.com/35517007/192988098-11f5f626-6623-421b-8e9d-255c2cd3b3f5.png) > 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/): -

- - Screenshot 2022-09-29 at 1 23 00 PM - -

+![Screenshot 2022-09-29 at 1 23 00 PM](https://user-images.githubusercontent.com/35517007/192988503-29ea1b20-fd9d-4ca7-beb8-0f79d65b9678.png) 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! -

- Screenshot 2022-09-29 at 1 23 14 PM - -

+![Screenshot 2022-09-29 at 1 23 14 PM](https://user-images.githubusercontent.com/35517007/192988653-f5987b54-df83-4464-a96a-2d71e2002905.png) If everything is correctly filled out, your contract page on the block explorer should display a new tab called `Contract`: -

- Screenshot 2022-09-29 at 1 23 24 PM - -

+![Screenshot 2022-09-29 at 1 23 24 PM](https://user-images.githubusercontent.com/35517007/192988808-72505e63-7810-402d-a61f-cf59defb15e3.png) In this page you can read from, write to, or simply read the information tied to your smart contract on the blockchain: -

- - Screenshot 2022-09-29 at 1 23 40 PM - -

+![Screenshot 2022-09-29 at 1 23 40 PM](https://user-images.githubusercontent.com/35517007/192988899-eb41c2ae-c4b9-4bab-89e8-227d42bfe2b3.png) ---- +*** -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` -![faucet](https://user-images.githubusercontent.com/102393474/191441945-6eee9b64-acef-4901-bf22-62becd342f93.png) +### 💵 Add funds to wallet using Apothem Faucet + +Go to https://faucet.apothem.network/ and paste your address and press `Request 1000 XDC` ![faucet](https://user-images.githubusercontent.com/102393474/191441945-6eee9b64-acef-4901-bf22-62becd342f93.png) 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 -![stage0](https://user-images.githubusercontent.com/102393474/191442289-32269ab1-5b5a-4a94-b4a1-00a1d35a6358.png) -![stage1](https://user-images.githubusercontent.com/102393474/191442300-45cc3af3-674c-4fcd-9310-e8ae1daa731f.png) -![stage2](https://user-images.githubusercontent.com/102393474/191442310-4ada2b4f-43d0-4bd0-88f9-991e3a9cf9f4.png) -![stage3](https://user-images.githubusercontent.com/102393474/191442321-10a88d6b-664e-453b-a653-e938fc3c63b9.png) +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 ![stage0](https://user-images.githubusercontent.com/102393474/191442289-32269ab1-5b5a-4a94-b4a1-00a1d35a6358.png) ![stage1](https://user-images.githubusercontent.com/102393474/191442300-45cc3af3-674c-4fcd-9310-e8ae1daa731f.png) ![stage2](https://user-images.githubusercontent.com/102393474/191442310-4ada2b4f-43d0-4bd0-88f9-991e3a9cf9f4.png) ![stage3](https://user-images.githubusercontent.com/102393474/191442321-10a88d6b-664e-453b-a653-e938fc3c63b9.png) -## 💵 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: -![txinfo](https://user-images.githubusercontent.com/102393474/191441715-334960ee-4b40-455a-a14a-2e1b49e60609.png) +You should see the following: ![txinfo](https://user-images.githubusercontent.com/102393474/191441715-334960ee-4b40-455a-a14a-2e1b49e60609.png) -Here, you can see that your transaction ended with success: -![txstatus](https://user-images.githubusercontent.com/102393474/191441672-128fd5f5-a394-497c-8bea-27528901635f.png) +Here, you can see that your transaction ended with success: ![txstatus](https://user-images.githubusercontent.com/102393474/191441672-128fd5f5-a394-497c-8bea-27528901635f.png) -This is how much you ended up paying for our transaction: -![txprice](https://user-images.githubusercontent.com/102393474/191441705-df45c604-86aa-4e07-9680-5ae530be7cbb.png) +This is how much you ended up paying for our transaction: ![txprice](https://user-images.githubusercontent.com/102393474/191441705-df45c604-86aa-4e07-9680-5ae530be7cbb.png) -And here is how much tokens we sent: -![tokenamount](https://user-images.githubusercontent.com/102393474/191441729-eeb9d535-dd31-4cac-8aaa-fe19b7b2dce9.png) +And here is how much tokens we sent: ![tokenamount](https://user-images.githubusercontent.com/102393474/191441729-eeb9d535-dd31-4cac-8aaa-fe19b7b2dce9.png) ---- +*** -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: -

- Step 01 -

+![Step 01](https://user-images.githubusercontent.com/78161484/190839624-495ef863-e177-4c62-81ca-680e5e6a4cab.png) - -## ⚒ 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: -

- Step 02 -

+![Step 02](https://user-images.githubusercontent.com/78161484/189952656-eb7793cc-7dee-4307-88fc-7c351a75cec7.png) -# 💵 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: -![folder_struct](https://user-images.githubusercontent.com/102393474/192887344-772b3e7a-a43a-47b1-a255-3a6f04f11ba5.png) +![folder\_struct](https://user-images.githubusercontent.com/102393474/192887344-772b3e7a-a43a-47b1-a255-3a6f04f11ba5.png) 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. -![ganache_home](https://user-images.githubusercontent.com/102393474/192887131-53f9bcec-9843-4027-8ec1-8b442c2d2bb7.png) +![ganache\_home](https://user-images.githubusercontent.com/102393474/192887131-53f9bcec-9843-4027-8ec1-8b442c2d2bb7.png) 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. -![ganache_0](https://user-images.githubusercontent.com/102393474/192887165-4e766c71-5167-4ef7-9e00-2568ece97580.png) +This is what you will see from Ganache app. ![ganache\_0](https://user-images.githubusercontent.com/102393474/192887165-4e766c71-5167-4ef7-9e00-2568ece97580.png) -![ganache_1](https://user-images.githubusercontent.com/102393474/192887171-6ba7b46d-80d4-4d0b-96a5-092cca193a30.png) - - -## 💵 Testing FarmToken contract +![ganache\_1](https://user-images.githubusercontent.com/102393474/192887171-6ba7b46d-80d4-4d0b-96a5-092cca193a30.png) +### 💵 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/): -

- Verify 01 -

+![Verify 01](https://user-images.githubusercontent.com/78161484/190875518-828c0061-71de-42c2-b222-0b8427852d01.png) 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! -

- Verify 02 -

+![Verify 02](https://user-images.githubusercontent.com/78161484/190875635-f6d3aa36-47b2-4b09-ad6a-fe6df3fb11f1.png) If everything was filled out correctly, your contract page on the block explorer should display a new tab called `Contract`: -

- Verify 03 -

+![Verify 03](https://user-images.githubusercontent.com/78161484/190875780-6223b4b0-fecc-4e79-83bc-c810c5b0351c.png) 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/learn/how-to-articles/how-to-use-xdcpay-connect-to-create-a-dapp-connected-to-xdc-network.md b/learn/how-to-articles/how-to-use-xdcpay-connect-to-create-a-dapp-connected-to-xdc-network.md index b4fd72dc..5b633135 100644 --- a/learn/how-to-articles/how-to-use-xdcpay-connect-to-create-a-dapp-connected-to-xdc-network.md +++ b/learn/how-to-articles/how-to-use-xdcpay-connect-to-create-a-dapp-connected-to-xdc-network.md @@ -617,4 +617,4 @@ Now you have created your first dApp on XDC Network using XDCPay! 🎉🥳 This dApp Scaffold is available in the [xdc-dapp-scaffold folder](https://github.com/menezesphill/docs/tree/main/how-to/XDCPay/Integration/xdc-dapp-scaffold).\ This Dapp completed version (fully functional) is also available in the [xdc-dapp-scaffold-completed folder](https://github.com/menezesphill/docs/tree/main/how-to/XDCPay/Integration/xdc-dapp-scaffold-completed).\ -For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).\ +For more information about XinFin Network, Please Visit [XDC Network Documentation on GitBook](https://docs.xdc.org/).\\ diff --git a/run-a-node/README.md b/run-a-node/README.md index 1c490b5c..4e82f5d8 100644 --- a/run-a-node/README.md +++ b/run-a-node/README.md @@ -1,2 +1,30 @@ # Run a Node +Nodes are computers or servers that run an application software known as clients to perform essential tasks on a blockchain network. These tasks can include transactions, block creation, consensus, network security, and other operational tasks for the network. The tasks and functionalities a node execute depend on the type of node, with each node having different system requirements and deployment processes. This section will provide details and information on how to run and maintain nodes on the XDC Network. + +## Masternodes + +The XDC Network runs on a globally distributed system of masternodes that participate in a Delegated Proof of Stake (DPoS) consensus mechanism. To enhance network integrity and security, Masternodes are required to complete a KYC process and stake 10,000,000 XDC. Masternodes can be identified as “Validator” or “Standby” Masternodes. + +### Validator Masternode + +Validator Masternodes operate and participate in XDC Network’s DPoS consensus engine, validating transactions and block creation. + +### Standby Masternodes + +Standby Masternodes (or “Standby Nodes”) are identical in form and function to Validators but do not participate in validating transactions and block creation. These nodes are on standby to fill the role of Validators that drop from network participation. + +## Full Node + +Full nodes do not participate in block creation or validating transactions like Masternodes so staking and KYC is not required. These nodes can be used to provide the state of the blockchain, transaction history, or as an RPC. A complete state and history can be provided up to the previous 128 blocks, and block header only after the previous 128 blocks to genesis. + +## Archive Node + +This type of node is used to query data, providing everything in the full node plus complete blockchain and state history to genesis. An archive node would be used if details beyond block header are needed, such as account balances and data stored in blocks. These nodes do not have the same functionality or requirements as Masternodes + +\ + + +#### + +\ diff --git a/run-a-node/full-node/README.md b/run-a-node/full-node/README.md new file mode 100644 index 00000000..3902c65f --- /dev/null +++ b/run-a-node/full-node/README.md @@ -0,0 +1,2 @@ +# Full Node + diff --git a/run-a-node/masternode/full-node.md b/run-a-node/full-node/full-node.md similarity index 73% rename from run-a-node/masternode/full-node.md rename to run-a-node/full-node/full-node.md index f7b6124e..3eeb2d83 100644 --- a/run-a-node/masternode/full-node.md +++ b/run-a-node/full-node/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,8 +74,8 @@ 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 -sudo docker-compose -f apothem-network.yml up -d +cd testnet +sudo docker-compose -f docker-compose.yml up -d ``` You should be able to see your node listed on the \[Apothem Network] page. Select **"Switch to LiveNet"** to check **LiveNetwork** Stats and Select **"Switch to TestNet"** for **TestNetwork.** @@ -85,37 +85,39 @@ 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 docker-compose.yml down ``` -## Downloading a Network Snapshot +## Downloading a Network Snapshot (Mainnet or Apothem) The following steps are to expedite the syncing process of your node with the XDC Network. If you followed the steps above, your node will take 3-4 days to sync up with the network fully. You can reduce that time by downloading a network snapshot and bringing your node back up after the chain has been downloaded and unpacked. {% embed url="https://youtu.be/ZQF3f0Zd6-k" %} -### First safely bring down your node: +## Mainnet Snapshot + +### 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 +### 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,27 +127,64 @@ 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.
-### +## Apothem Snapshot + +### Bring down your node: + +``` +sudo docker-compose -f docker-compose.yml down +``` + +### Remove the old xdchain file from the server + +``` +rm -rf apothem.tar +``` + +### Download the snapshot + +``` +wget https://download.apothem.network/apothem.tar +``` + +### Unpack the apothem.tar file + +``` +tar -xvzf apothem.tar +``` + +## Move the xdcchain-testnet + +``` +mv XDC xdcchain-testnet +``` + +## Bring up the node + +``` +sudo docker-compose -f docker-compose.yml up -d +``` + diff --git a/run-a-node/full-node/how-to-migrate-an-xdc-node.md b/run-a-node/full-node/how-to-migrate-an-xdc-node.md new file mode 100644 index 00000000..cf96bbba --- /dev/null +++ b/run-a-node/full-node/how-to-migrate-an-xdc-node.md @@ -0,0 +1,107 @@ +--- +description: >- + This guide will walk you through migrating you current XDC standby/masternode + from a local machine or cloud provider to another cloud provider. +--- + +# How to migrate an XDC Node + +## Things you will need + +You will need the following to be able to migrate you current XDC node: + +* The coinbase address from your current node +* The keystore file (file name starts with UTC--) +* SCP tool if using Windows (already built in to terminal if using a Mac) +* Login information for destination cloud provider (IP address and user for that terminal, normally admin, root, or ubuntu). + +## Step 1 + +If you manage your node, log in, navigate to your coinbase.txt file, and copy the XDC address inside it. You can use either Nano or Vi. For the purpose of this guide and the tool's simplicity, we will be using Nano. + +{% hint style="info" %} +Note: If your node is being managed by a third party, please get in touch with them for items 1 and 2 above as these two are needed for the following steps. +{% endhint %} + +## Step 2 + +Log in to your new server where you are migrating your old XDC node to and navigate to: + +``` +cd XinFin-Network/mainnet +``` + +## Step 3 + +Bring down your node + +``` +sudo docker-compose -f docker-compose.yml down +``` + +## Step 4 + +Paste the command below, you should still be in the "XinFin-Node/mainnet" directory. The command below will open the coinbase.txt file. + +``` +nano coinbase.txt +``` + +Replace the address in the coinbase.txt file with the one from your old node or the one received from your cloud provider. Save and exit the nano tool. + +Next, we are going to replace the UTC-- file inside the keystore directory. Absolute path: + + \~/XinFin-Node/mainnet/xdcchain/keystore + +## Step 5 + +On your local machine, open the terminal (Mac users) or cmd prompt (if using Windows). + +{% hint style="info" %} +To securely copy (scp) files from a local Mac machine to a remote Ubuntu server, you first need to ensure that you have SSH access to your Ubuntu server. + +Once you have SSH access, you can use the scp command from the terminal on your Mac. Here is a general format for the scp command: +{% endhint %} + +``` +scp /path/to/local/file username@remote-IP:/path/to/remote/directory +``` + +* `/path/to/local/file`: Replace this with the path to the file on your local machine that you want to copy. +* `username`: Replace this with your username on the remote Linux server. +* `remote-IP`: Replace this with the IP address of the remote Linux server. +* `/path/to/remote/directory`: Replace this with the path on the remote Linux server where you want to copy the file. + +For example, if you want to copy a file named "example.txt" from your Desktop to the home directory of your user account (named "myusername") on a remote server with the IP address "192.168.1.1", you would use this command: + +``` +scp ~/Desktop/example.txt myusername@192.168.1.1:~ +``` + +Remember to replace "myusername" and "192.168.1.1" with your actual username and the IP address of your remote server. + +After entering this command, you'll be prompted to enter your password for the remote Ubuntu server. After entering the password, the file will be copied. + +Note: You may also need to specify the port number if your SSH server is listening on a non-default port. You can do this by adding `-P port` after the scp command. For example: + +``` +scp -P 2222 ~/Desktop/example.txt myusername@192.168.1.1:~ +``` + +## Step 6 + +Remove the old UTC file in the keystore directory + +``` +rm UTC--2021-12-27T21-48-18.376753555Z--xdc785076b971F2a90b029b0000000000000000000 +``` + +## Step 7 + +Bring back node back up + +``` +sudo docker-compose -f docker-compose.yml up -d +``` + +Check the logs to ensure that everything is working as intended. diff --git a/run-a-node/how-to-ssl-tls-encryption-for-xdc-rpc.md b/run-a-node/how-to-ssl-tls-encryption-for-xdc-rpc.md new file mode 100644 index 00000000..e62a1002 --- /dev/null +++ b/run-a-node/how-to-ssl-tls-encryption-for-xdc-rpc.md @@ -0,0 +1,225 @@ +# How to Encrypt RPC + +_Notes:_ + +* _These instructions relate to XDC Mainnet Nodes._ +* _Appendix A shows process modifications needed for Apothem Testnet nodes._ + +*** + +Implementing SSL/TLS encryption for XDC node RPCs offers key advantages. + +* SSL/TLS ensures the confidentiality of data exchanged between clients and nodes, guarding against unauthorized access. +* It maintains data integrity, preventing tampering or unauthorized modifications during transit. +* SSL/TLS authentication enhances trust by verifying the identities of the communicating parties, thwarting man-in-the-middle attacks. + +By protecting sensitive information and complying with security standards, SSL/TLS fortifies the overall security of XDC node RPCs. + +*** + +![Nginx Logo](../.gitbook/assets/image27-nginx-logo.png) + +Nginx is a popular web server and reverse proxy server that efficiently handles and routes HTTP and other network protocols. We can use Nginx to establish SSL/TLS encryption for an XDC node's RPC by acting as a reverse proxy. + +To accomplish this, we need to: + +1. Obtain an SSL/TLS certificate for the domain or IP address of the XDC node server +2. Configure Nginx with the certificate and set it up to listen for incoming encrypted connections +3. Configure Nginx to forward incoming encrypted connections to the local address and port of the XDC node's Docker container + +We will now walk through these processes. After they are completed, we will secure our ports and test the new encrypted RPC! + +*** + +## Obtain an SSL/TLS Certificate + +SSL/TLS certificates can be obtained from a trusted third-party Certificate Authority (CA) or alternately, a self-signed certificate can be generated by the server itself. A CA certificate provides widespread recognition and trust, while a self-signed certificate provides encryption but lacks the third-party validation. + +For the purposes of this article, we will be generating and using a self-signed certificate. _If choosing to use an official CA certificate, the setup processes other than generating a self-signed SSL certificate should remain the same._ + +We start by first connecting to your XDC node server. Remember to replace _root_ in this command with your actual username for the remote server, replace _22_ with the actual ssh port number you are using, and replace _ip.address_ with the actual IP address of the remote server: + +``` +ssh -lroot -p22 ip.address +``` + +Install OpenSSL: + +``` +sudo apt install openssl +``` + +Run the following command on your XDC node server to generate a private key _(key.pem)_ and self-signed SSL/TLS certificate _(cert.pem)_. You can vary your certificate's period of validity as desired. It is set below to 3065 days (\~10 years): + +``` +sudo openssl req -x509 -nodes -days 3065 -newkey rsa:2048 -keyout /etc/ssl/private/key.pem -out /etc/ssl/certs/cert.pem +``` + +Fill in the required information when prompted. _Note that the Common Name (CN) field should be the public IP address of your server (or the domain if people will be using that)._ + +*** + +## Install and Configure Nginx + +First we need to install Nginx: + +``` +sudo apt install nginx +``` + +We will shortly need to edit the Nginx configuration file and customise it. In order to make the necessary changes, you will need 2 pieces of information: + +* the public IP address of your XDC node server (the same IP address you entered as the Common Name (CN) when setting up your SSL certificate above); and +* the local IP address being used by the XDC node's Docker container + +To obtain the local IP address being used by the Docker container, use: + +``` +sudo docker inspect mainnet_xinfinnetwork_1 +``` + +You will see a lot of configuration information relating to your Docker container shown in your terminal. The part you are looking for is the IP address shown after _"IPAddress":_. It is towards the end of the configuration information that is displayed in the terminal window. In the screenshot image below, we can see that this Docker container is using IP address _172.18.0.2_: + +![Docker Container IP Address](../.gitbook/assets/image28-docker-container-ip-address.png) + +Now open the Nginx configuration file in nano for editing: + +``` +sudo nano /etc/nginx/nginx.conf +``` + +It will look like this: + +![nginx.conf original appearance](../.gitbook/assets/image29-nginx-config-file-original-on-opening.png) + +Locate the http block in the nginx.conf file. It begins with the _http_ keyword and ends with a closing brace _}_. At the end of the http block (before the closing brace), add the following configuration: + +``` + ## + # XDC Node RPC Reverse Proxy + ## + + server { + listen 443 ssl; + server_name ; + + ssl_certificate /etc/ssl/certs/cert.pem; + ssl_certificate_key /etc/ssl/private/key.pem; + + location /rpc { + proxy_pass http://:8545; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + } + } +``` + +After adding it, the part you have added to the file should look like this: + +![nginx.conf added section](../.gitbook/assets/image30-nginx-config-file-modified.png) + +In the configuration text you have just added we need to also: + +* replace `` with the public IP address of the XDC node server; and +* replace `` with the IP address we obtained by using the _docker inspect_ command above + +Then save the changes and exit nano: + +> Press "CTRL+X" Press "y" Press "ENTER" + +Check that the syntax you have entered in nginx.conf is ok: + +``` +sudo nginx -t +``` + +We will need to set the ownership and permissions of the private key and certificate we created earlier. This makes sure they are secure. We also need to ensure that Nginx can access them when needed. The Nginx process usually runs as _www-data_, so we will add _www-data_ to the group _ssl-cert_ that has access to the credentials: + +``` +sudo addgroup ssl-cert +sudo chown root:ssl-cert /etc/ssl/certs/cert.pem +sudo chmod 0644 /etc/ssl/certs/cert.pem +sudo chown root:ssl-cert /etc/ssl/private/key.pem +sudo chmod 0640 /etc/ssl/private/key.pem +sudo usermod -a -G ssl-cert www-data +``` + +Restart the Nginx service: + +``` +sudo systemctl restart nginx +``` + +*** + +## Port Considerations + +At this point, your XDC Mainnet node is now using: + +* port 443 for HTTPS access to the XDC RPC; and +* port 30303 for peer-to-peer communications; and +* whichever port you have set to access the server by ssh + +In the majority of cases, we should now block (filter) port 8989 with our firewall as plain HTTP access to the RPC is no longer required and defeats the purpose of securing the RPC with SSL. You will of course need to consider your port requirements based on whatever your node is being used for. + +*** + +## Test your new SSL/TLS Encrypted RPC + +You can now test the HTTPS access to your XDC Node RPC by using a web browser and going to `https:///rpc` _(or if you just go to `https://` you will see the Nginx information page._ + +As we are using a self-signed certificate, we expect that there would be an "Untrusted certificate warning" which we will need to just set an exception for in the browser. If using a CA certificate instead, this warning will not occur. + +Congratulations you have just set up SSL/TLS encryption for your XDC Mainnet RPC! + +*** + +![Appendix A - Apothem Testnet](../.gitbook/assets/image15-appendix-header.png) + +## Appendix A - Modifications for Apothem Testnet Nodes + +### Modification 1 + +When obtaining the local IP address being used by the Docker container, we need to use the testnet container name as shown here: + +``` +sudo docker inspect testnet_xinfinnetwork_1 +``` + +### Modification 2 + +When adding the extra configuration information to the nginx.conf file, we must allow for the different HTTP-RPC port used by the Apothem Testnet Client. We can use the following configuration text instead of the mainnet version above: + +``` + ## + # Apothem Node RPC Reverse Proxy + ## + + server { + listen 443 ssl; + server_name ; + + ssl_certificate /etc/ssl/certs/cert.pem; + ssl_certificate_key /etc/ssl/private/key.pem; + + location /rpc { + proxy_pass http://:8555; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + } + } +``` + +### Modification 3 + +After restarting the Nginx service, we note that the Apothem Testnet node is now using: + +* port 443 for HTTPS access to the XDC RPC; and +* port 30304 for peer-to-peer communications; and +* whichever port you have set to access the server by ssh + +In the majority of cases, we should now block (filter) port 8999 with our firewall as plain HTTP access to the RPC is no longer required and defeats the purpose of securing the RPC with SSL. You will of course need to consider your port requirements based on whatever your node is being used for. + +Congratulations you have just set up SSL/TLS encryption for your Apothem Testnet RPC! + +*** diff --git a/run-a-node/masternode/how-to-stake-an-xdc-masternode.md b/run-a-node/masternode/how-to-stake-an-xdc-masternode.md new file mode 100644 index 00000000..ded9ce5b --- /dev/null +++ b/run-a-node/masternode/how-to-stake-an-xdc-masternode.md @@ -0,0 +1,49 @@ +--- +description: >- + Note: You do not need 10,000,000 XDC to run a node for RPC or just querying + live data from the chain. +--- + +# How to Stake an XDC Masternode + +As an XDC masternode candidate, you are going to need the following: + +1. XDCPay or XinFin web wallet or a hardware wallet (Trezor ) +2. 10,000,000 XDC (mainnet) or test XDC (Apothem testnet) +3. Your coinbase address (you can log in to your node and retrieve it from there) + +Follow these steps to stake your node. + +{% embed url="https://youtu.be/ilhZRBbyfU8" %} + +1. Go to [https://www.xinfin.network/#masternode](https://www.xinfin.network/#masternode) and switch to either mainnet or Apothem: +2. Click on login + +
+3. You will be presented with the following options to log in. We will be using XDCPay for this tutorial: + +
+ +4. Once logged in, click on "Become a candidate" and you will see the following screen: + +

If you dont have your KYC document ready. You can download a copy via the highlighted links on this image.

+ +5. Once the file has been uploaded, you will see that KYC shows "True." + +
+ +6. Click on "Become a candidate" and input your coinbase address from your node and hit apply. + +
+ +7. Once you click apply, your wallet will prompt you to sign the transaction. Click "Confirm" on your wallet. + +
+ +8. Once the transaction executes successfully, you will get a notification at the bottom right side of the screen as shown below. + +
+ +9. You can also verify the transaction if you open your wallet, click on "Transactions" and click on the "Propose" event. + +
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/run-a-node/masternode/securing-your-xdc-masternode.md b/run-a-node/masternode/securing-your-xdc-masternode.md new file mode 100644 index 00000000..ee5fc384 --- /dev/null +++ b/run-a-node/masternode/securing-your-xdc-masternode.md @@ -0,0 +1,549 @@ +# How to Secure Masternode + +## Securing your XDC Masternode + +_Notes:_ + +* _Although this guide refers to masternodes, it will also work for standby nodes as well as non-validator nodes (as long as they are reachable via a public IP address). For non-validator nodes using HTTP/Websocket JSON-RPC connection, you'll also need to take into account your specific port access requirements when dealing with ports 8888 and/or 8989._ +* _For Apothem Testnet Nodes, Appendix A at the base of this article shows what process modifications you will need._ +* _Instructions are for a Docker node running on Ubuntu 20.04LTS_ + +*** + +XDC network masternodes are important because they validate transactions, help to maintain the network's security and integrity, and ensure that the network runs smoothly. Securing your node will help with all of these issues. + +From a high-level consideration, to secure your XDC masternode you would need to: + +1. Keep it up-to-date with the latest security patches. +2. Use a strong and unique password. +3. Change your SSH port and enable firewall rules to restrict access to the node. +4. Use SSL/TLS encryption to secure communication with it. +5. Implement access controls to limit who can interact with it. +6. Regularly monitor it for any suspicious activity or unauthorized access attempts. + +We will deal with each of these in turn below. + +*** + +### Keeping your node up-to-date with the latest security patches + +This has 2 components. Component 1 is the server OS. Component 2 is the XDC client. + +#### Regarding the Server OS + +As per [XinFin's original XDC network node setup instructions](https://xinfin.org/setup-masternode) deploying an XDC node by the Docker method is supported on CentOS, RedHat Enterprise Linux (latest release) and Ubuntu 15.04+. + +Each OS vendor has a period for which its product is supported. For example we can see in the image below that Ubuntu 20.04LTS has hardware and maintenance updates until 2025 as well as Extended Security Maintenance until 2032. Ensure your OS is supported with current updates. + +![Ubuntu LTS Release Cycle](../../.gitbook/assets/image01-ubuntu-release-cycle-securing-masternode.png) + +To update the OS packages on your server we first need to connect to the remote server so we can then do all the following steps on the remote server. Remember to replace “root” in this command with your actual username for the remote server, and replace ip.address with the actual IP address of the remote server: + +``` +ssh -lroot -p22 ip.address +``` + +Update the OS packages: + +``` +sudo apt update -y && sudo apt upgrade -y && sudo apt autoremove -y +``` + +Many OS updates often require you to reboot your server, but we must first stop the XDC client. To do this, first change to the Mainnet client directory: + +``` +cd ~/XinFin-Node/mainnet +``` + +Stop the XDC client: + +``` +sudo ./docker-down.sh +``` + +Reboot the server: + +``` +sudo reboot +``` + +You’ll notice this has disconnected your Terminal from the VPS while it reboots. Allow enough time for the VPS to reboot, then reconnect to your VPS as you normally would. Remember to replace “root” with your actual username for the remote server, and replace ip.address with the actual IP address of the remote server: + +``` +ssh -lroot -p22 ip.address +``` + +Change to the Mainnet client directory: + +``` +cd ~/XinFin-Node/mainnet +``` + +Start the XDC Client: + +``` +sudo ./docker-up.sh +``` + +Logout of your server: + +``` +logout +``` + +#### Regarding the XDC Network Client + +Connect to your VPS as you normally would. Remember to replace “root” with your actual username for the remote server, and replace ip.address with the actual IP address of the remote server: + +``` +ssh -lroot -p22 ip.address +``` + +Change to the Mainnet client directory: + +``` +cd ~/XinFin-Node/mainnet +``` + +In the Mainnet client directory there is a script we can run to upgrade the XDC network configuration scripts and the Docker images. _Note that as part of the process it will stop and start the XDC client, so expect to see your peers drop on_ [_the XDC Foundation Network Stats page_](https://stats.xdc.org). To run the upgrade script: + +``` +sudo ./upgrade.sh +``` + +Logout of your server: + +``` +logout +``` + +*** + +### Using a strong and unique password + +The time it takes to guess passwords by brute force depends on the length and complexity of the password, as well as the computing power of the attacker. It can range from a few seconds to several years or even centuries (or even longer!). + +As per the image below (sourced from Hive Systems), in 2023 an 18 character password consisting of only numbers can take as little as 6 days to obtain by brute force. Using the same length password but including random numbers, upper and lowercase letters as well as symbols, can increase the brute force time to 26 trillion years with the same computing power. + +![Hive Systems Password Brute Force Times](../../.gitbook/assets/image02-brute-force-time-securing-masternode.jpg) + +Ensuring that a password is not reused is also important. If the same password is used on multiple sites then if ANY of those sites are compromised and your password is somehow obtained, it could potentially allow unauthorised parties to access other accounts/services where you have reused the same password. + +If you have difficulty generating a random password with the criteria described above, there are online password generators from reputable vendors. One example of this is the [Norton Password Generator](https://my.norton.com/extspa/passwordmanager?path=pwd-gen) + +![Norton Password Generator](../../.gitbook/assets/image03-norton-pw-gen-securing-masternode.png) + +If you already have an existing password and would like to change it, you can do so by first connecting to your VPS as you normally would. Remember to replace “root” with your actual username for the remote server, and replace ip.address with the actual IP address of the remote server: + +``` +ssh -lroot -p22 ip.address +``` + +Change your password with the following command. Replace `` with the actual username of the user whose password you want to change. You will be prompted to enter and confirm the new password: + +``` +sudo passwd +``` + +Logout of your server: + +``` +logout +``` + +_Note: another alternative is to setup ssh key-based authentication and then to disable the ability to use password logins. This will not be covered in this article. If there is demand, I'll consider covering it in a future article._ + +*** + +### Change your SSH port and enable firewall rules to restrict access to the node + +Securing the server ports and RPC endpoint is important to prevent unauthorized access and potential security breaches such as execution of malicious code. + +![XDC Network Andromeda Upgrade](../../.gitbook/assets/image04-andromeda-securing-masternode.jpg) + +Those who were around at the time may remember that the Andromeda update to the XDC network implemented an upgrade to Geth 1.9.X. From examining an XDC node's docker-compose.yml file shown in the image below, we can see that Geth nodes on the XDC network use: + +* Port 30303 for RLPx(TCP)/UDP peer-to-peer communications allowing node discovery and connection to peers +* Port 8989 for HTTP JSON-RPC API which allows external applications to interact with the XDC blockchain +* Port 8888 for secure Websocket communications to the XDC blockchain + +![XDC Node docker-compose.yml](../../.gitbook/assets/image05-yml-file-securing-masternode.png) + +In addition Linux servers normally have their SSH port set at 22 by default, and this is used to connect to the server and access its command line. + +For the purposes of this article, we will assume that your masternode is being used only for the purpose of maintaining the XDC blockchain and does not require RPC/Websocket access for external applications to use. + +Based on the above, the best way of securing our node with a firewall is to: + +* Change our SSH port from 22 to a different number to make it harder for random malcontents to connect +* Use a firewall to block ALL incoming ports +* Then open ONLY ports 30303 and our new SSH port +* We will leave ports 8888 and 8989 blocked (filtered) as we are assuming that these are not needed as noted above + +To change the port used for SSH on Ubuntu, you need to first connect to your VPS as you normally would. Remember to replace “root” with your actual username for the remote server, and replace ip.address with the actual IP address of the remote server: + +``` +ssh -lroot -p22 ip.address +``` + +Next you need to edit the SSH configuration file located at /etc/ssh/sshd\_config : + +``` +sudo nano /etc/ssh/sshd_config +``` + +Look for the line that says "Port 22". If there is a `#` before "Port 22" as in the image below, you'll need to delete the `#` symbol: + +![Port22](../../.gitbook/assets/image06-port22-securing-masternode.png) + +Change the number 22 to whatever new port number you want to use for SSH connections: + +![Your new SSH port](../../.gitbook/assets/image07-new-ssh-port-securing-masternode.png) + +Save the file: + +> Press "CTRL+X" +> +> Press "y" +> +> Press "ENTER" + +Then restart the SSH service: + +``` +sudo service ssh restart +``` + +_Note: Whenever we have previously used "-p22" as part of our command to connect to a VPS via SSH, this is specifying to ssh what port the remote server is using for ssh. From now on whenever you connect to your XDC node, you will need to change the 22 in "-p22" to your new port number instead._ + +![UFW Uncomplicated Firewall](../../.gitbook/assets/image08-ufw-logo-securing-masternode.png) + +Now to implement a firewall we will use UFW (Uncomplicated Firewall) which is a front-end tool for managing firewall rules on Ubuntu. + +First we need to install ufw: + +``` +sudo apt install ufw +``` + +Next we establish our default policies to block ALL incoming traffic and only allow outgoing traffic: + +``` +sudo ufw default deny incoming +sudo ufw default allow outgoing +``` + +Then we open up port 30303 so the XDC client is discoverable by peers: + +``` +sudo ufw allow 30303 +``` + +**IMPORTANT: Next we need to ensure that we open up our SSH port (22 or whatever port number you changed it to):** + +``` +sudo ufw allow +``` + +Lastly we need to enable UFW: + +``` +sudo ufw enable +``` + +Reboot your server: + +``` +reboot +``` + +Now ssh to your server to test your new port number instead of 22 and ensure that you can connect ok. + +If you are unable to connect and need to get back to the command line on your server to modify the firewall details, most VPS providers will have a console for the server directly accessible through their VPS control panel. So you just need to go to your VPS provider website, login and find the console for the VPS running your XDC client. Then login and do what you need to do. + +After rebooting, we will need to restart the XDC Mainnet client, so first we need to SSH to our VPS: + +``` +ssh -lroot -p ip.address +``` + +Change to the XDC Mainnet client directory: + +``` +cd ~/XinFin-Node/mainnet +``` + +Restart the XDC Mainnet client: + +``` +sudo ./docker-up.sh +``` + +Then logout of your VPS: + +``` +logout +``` + +_Note: In another section of this book we will be making some further adjustments allowing certain IP addresses restricted access to port 8989 (HTTP JSON-RPC) in the firewall rules._ + +*** + +### Use SSL/TLS encryption to secure communication with the node + +SSL/TLS encryption makes things safer if external applications are using the JSON-RPC (HTTP/Websocket) functionalities of your node to communicate with the XDC blockchain. The assumption of this page is that your node is not being used for this so this issue will be covered in another section. + +*** + +### Implement access controls to limit who can interact with the node + +This involves: + +* Configuring firewall rules to restrict access to the node from specific IP addresses or networks. +* Setting up RPC authentication on Geth + +These are not relevant to a masternode (with its RPC port filtered) and will be covered in other sections of this book. + +*** + +### Regularly monitor it for any suspicious activity or unauthorized access attempts + +You can regularly monitor an XDC node for any suspicious activity or unauthorized access attempts by setting up alerts and notifications for any unusual activity and regularly reviewing logs and metrics. Additionally, you can consider using third-party security tools and services to enhance your node's security. Usage of monitoring should not however replace implementing security best practices such as using strong passwords and keeping your software up to date. + +Many VPS providers will have some kind of VPS monitoring in place which is already accessible via their control panel and generally includes alerts when certain preset VPS parameter limits (eg CPU usage, memory usage, network traffic, disk I/O) are breached. If your VPS provider does not provide this, third party solutions such as Netdata can be used to provide it. Netdata will be covered in another section. + +![Fail2Ban](../../.gitbook/assets/image09-fail2ban-logo-securing-masternode.png) + +Implementing the fail2ban linux package can also be useful for keeping your node safe by blocking IP addresses that attempt to access the node with incorrect login credentials or perform suspicious activities. + +Install fail2ban: + +``` +sudo apt install fail2ban +``` + +Next we create a copy of the configuration file for us to customise: + +``` +sudo cp -p /etc/fail2ban/jail.conf /etc/fail2ban/jail.local +``` + +Open the new file in nano so we can configure fail2ban: + +``` +sudo nano /etc/fail2ban/jail.local +``` + +Scroll down until you find this sshd section: + +![The SSHD section you are looking for](../../.gitbook/assets/image10-fail2ban-sshd-original-securing-masternode.png) + +Replace the 3 white lines shown above with all of these lines: + +``` +enabled = true +filter = sshd +port = ssh +banaction = iptables-multiport +findtime = 86400 # 86400 seconds = 1 day +bantime = -1 # -1 = ban forever +maxretry = 3 # 3 attempts in 1 day = ban +logpath = %(sshd_log)s +backend = %(sshd_backend)s +``` + +![Reconfigured fail2ban](../../.gitbook/assets/image11-fail2ban-sshd-new-securing-masternode.png) + +Save the file: + +> Press "CTRL+X" +> +> Press "y" +> +> Press "ENTER" + +Restart fail2ban: + +``` +sudo systemctl restart fail2ban +``` + +Logout of your server + +``` +logout +``` + +**Commands to use fail2ban** + +To check who is banned: + +``` +sudo fail2ban-client status sshd +``` + +To unban an IP address: + +``` +sudo fail2ban-client set sshd unban +``` + +If you manage to ban yourself by using incorrect passwords etc, you can use the direct console on your VPS provider's control panel to access the command line of your VPS (same as described in the Firewall section above) and unban your IP address using the above command. + +*** + +In conclusion, securing XDC nodes is crucial to protect the network from potential attacks and ensure the safety of user funds. By implementing the methods discussed in this article, such as using strong passwords, enabling firewalls, regularly updating software, and using monitoring tools, node operators can significantly increase the security of their nodes. It is important to stay vigilant and proactive in maintaining node security to prevent any potential breaches. With these measures in place, the XDC network can continue to operate securely and efficiently. + +*** + +![Apothem Testnet](../../.gitbook/assets/image15-appendix-header.png) + +## Appendix A - Securing your Apothem Testnet Masternode + +### Keeping your node up-to-date with the latest security patches + +Once again we separately consider the server OS and the Apothem Testnet client. + +#### Regarding the Server OS + +Updating the OS packages on your server is very similar to the Mainnet instructions but with a minor path adjustment to the testnet directory when stopping and restarting the client. When using ssh to connect to your server, remember to replace “root” in the command with your actual username for the remote server, and replace ip.address with the actual IP address of the remote server: + +``` +ssh -lroot -p22 ip.address +``` + +Then: + +``` +sudo apt update -y && sudo apt upgrade -y && sudo apt autoremove -y +cd ~/XinFin-Node/testnet +sudo ./docker-down.sh +sudo reboot +``` + +After your server has rebooted we need to reconnect to it and restart the Apothem client. First step is to reconnect: + +``` +ssh -lroot -p22 ip.address +``` + +Then restart the client: + +``` +cd ~/XinFin-Node/testnet +sudo ./docker-up.sh +logout +``` + +#### Regarding the Apothem Testnet Client + +At present there is no upgrade script for the Apothem Testnet client. The Apothem tree can be [seen here](https://github.com/XinFinOrg/XDPoSChain/tree/apothem) and docker image versions can be [seen here](https://hub.docker.com/r/xinfinorg/xinfinnetwork/tags). There is nothing extra to do here unless official guidance is received. + +*** + +### Using a strong and unique password + +No changes from the Mainnet section of the page above. + +*** + +### Change your SSH port and enable firewall rules to restrict access to the node + +Ports on the Apothem Testnet client are different to those on the Mainnet client. From examining an Apothem Testnet client's docker-compose.yml file shown in the image below, we can see that clients on the Apothem Testnet use: + +* Port 30304 for RLPx(TCP)/UDP peer-to-peer communications allowing node discovery and connection to peers +* Port 8999 for HTTP JSON-RPC API which allows external applications to interact with the Apothem blockchain +* Port 8898 for Websocket communications between external applications and the Apothem blockchain + +![Apothem Testnet docker-compose.yml](../../.gitbook/assets/image14-apothem-yml-file.png) + +The processes for securing the ports of your server running the Apothem Testnet client are similar to those for the Mainnet client. As previously, we will assume that your masternode is being used only for the purpose of maintaining the Apothem Testnet blockchain and does not require RPC/Websocket access for external applications to use. _(If you are using ports 8898 and/or 8999, you will need to ensure they are open for whatever access you require)._ The steps we will use are: + +* Change our SSH port from 22 to a different number to make it harder for random malcontents to connect +* Use a firewall to block ALL incoming ports +* Then open ONLY ports 30304 and our new SSH port +* We will leave ports 8898 and 8999 blocked (filtered) as we are assuming that these are not needed as noted above + +Changing the SSH port from 22 to a different number uses exactly the same steps as in the Mainnet article. Please follow the steps in the Mainnet article to modify /etc/ssh/sshd\_config + +Then restart your ssh service with: + +``` +sudo service ssh restart +``` + +_Note: Whenever we have previously used "-p22" as part of our command to connect to a VPS via SSH, this is specifying to ssh what port the remote server is using for ssh. From now on whenever you connect to your Apothem Testnet node, you will need to change the 22 in "-p22" to your new port number instead._ + +![UFW Uncomplicated Firewall](../../.gitbook/assets/image08-ufw-logo-securing-masternode.png) + +Same as for the Mainnet nodes, we will use ufw for our firewall configuration. Install ufw: + +``` +sudo apt install ufw +``` + +Establish our default policies to block ALL incoming traffic and only allow outgoing traffic: + +``` +sudo ufw default deny incoming +sudo ufw default allow outgoing +``` + +Open up port 30304 so the Apothem Testnet client is discoverable by peers: + +``` +sudo ufw allow 30304 +``` + +**IMPORTANT: Next we need to ensure that we open up our SSH port (22 or whatever port number you changed it to):** + +``` +sudo ufw allow +``` + +Enable UFW then stop the Apothem Testnet client and reboot the server: + +``` +sudo ufw enable +cd ~/XinFin-Node/testnet +sudo ./docker-down.sh +sudo reboot +``` + +Now ssh to your server to test your new ssh port number. + +If unable to connect, find the console for that VPS on your VPS-provider’s website. Use it to login and do whatever you need to do. + +After rebooting, we need to restart the Apothem Testnet client, so first SSH to the VPS: + +``` +ssh -lroot -p ip.address +``` + +Restart the Apothem Testnet client and logout of your server: + +``` +cd ~/XinFin-Node/testnet +sudo ./docker-up.sh +logout +``` + +*** + +### Use SSL/TLS encryption to secure communication with the node + +No changes from the Mainnet section of the page above. + +*** + +### Implement access controls to limit who can interact with the node + +No changes from the Mainnet section of the page above. + +*** + +### Regularly monitor it for any suspicious activity or unauthorized access attempts + +No changes from the Mainnet section of the page above. + +*** diff --git a/run-a-node/masternode/uptime-monitoring-xdc-masternode.md b/run-a-node/masternode/uptime-monitoring-xdc-masternode.md new file mode 100644 index 00000000..62703992 --- /dev/null +++ b/run-a-node/masternode/uptime-monitoring-xdc-masternode.md @@ -0,0 +1,331 @@ +# How to Monitor Uptime + +## Uptime Monitoring for XDC Masternodes + +_Notes:_ + +* _Although this guide refers to masternodes, it will also work for standby nodes as well as non-validator nodes (as long as they are reachable via a public IP address). For non-validator nodes using HTTP/Websocket JSON-RPC connection, you'll also need to take into account your specific port access requirements when dealing with ports 8888 and/or 8989._ +* _For Apothem Testnet Nodes, Appendix A at the base of this article shows what process modifications you will need._ +* _Instructions are for a Docker node running on Ubuntu 20.04LTS_ + +*** + +It is important for XDC Network masternode operators to ensure that their nodes are online and working properly because masternodes play a crucial role in the network's security, stability, and performance. If a masternode goes offline or malfunctions, it can negatively impact the network's overall functionality and potentially compromise its security. Additionally, masternode operators receive rewards for their participation in the network, so ensuring their nodes are online and functioning properly is necessary to receive those rewards. + +Uptime Robot is a powerful tool that can be used to monitor the status of an XDC masternode (or standby/non-validator node). It does so by regularly pinging your server and also by sending HTTP requests to the RPC endpoint and checking for a successful response. + +By setting up Uptime Robot to monitor your masternode, you can receive real-time notifications if your server goes offline or if your XDC client experiences any issues that have taken its RPC endpoint offline. This can help you ensure that your masternode is always up and running. In this guide, we will walk you through the process of safely setting up Uptime Robot to monitor your XDC masternode. + +![The Uptime Robot Website](../../.gitbook/assets/image16-uptime-robot-site.png) + +*** + +### Registering on Uptime Robot + +1. Go to the Uptime Robot website at http://uptimerobot.com +2. Click on the "Register for FREE" button. +3. Enter your name, email address and a password. +4. Click on the "Create My Account" button. +5. Verify your email address by clicking on the link sent to your email. +6. Log in to your account and start monitoring your node(s). + +*** + +### Creating a monitor that will intermittently ping your node server + +1. Login to the Uptime Robot website. +2. Click on the "Add new monitor" button to the top left of the page. + +![Add New Monitor Button](../../.gitbook/assets/image17-UTrobot-add-new-monitor-button.png) + +3. From the "Monitor Type" select the "Ping" option. + +![Select the Ping option](../../.gitbook/assets/image18-monitor-type-ping.png) + +4. Then in the "Friendly Name" field, type a nickname for this alert. + +![Details for the Ping Monitor](../../.gitbook/assets/image19-friendly-name.png) + +5. Put your node's IP address in the "IP" field. +6. Move the "Monitoring Interval" slider bar to 5 mins. A free 5 minutely check will be great for our general purposes at this point. (Any more frequent checks than this require a paid account). +7. In the yellow box you will see the “Select Alert Contacts to Notify” section. Place a check mark next to your email address. + +![Email checkbox](../../.gitbook/assets/image20-contacts-to-notify.png) + +8. Then click on the blue "Create Monitor" button at the bottom right of the popup window. + +![Create Monitor Button](../../.gitbook/assets/image21-create-monitor.png) + +*** + +### Creating a monitor for your node's RPC endpoint + +When opening the access port for a node's RPC endpoint, we must ensure that we do it in a secure fashion to prevent unauthorized access and potential attacks on the node, including manipulation of data, or disruption of the network. + +One way we can securely do this is by restricting access to the RPC endpoint by allowing only trusted IP addresses to connect to it. To do this, we will need to make some special rules for the firewall running on the node. + +We first need to know which IP addresses Uptime Robot sends HTTP requests from. Uptime Robot helpfully provides this information on their website on [THIS PAGE](https://uptimerobot.com/help/locations/) shown in the image below. + +![Uptime Robot Locations and IPs](../../.gitbook/assets/image22-locations-and-ips.png) + +Towards the bottom of the page they provide some green coloured links to files containing a list of the relevant IPv4 and IPv6 addresses that we will need to whitelist on our firewall. Right click on the _"IPv4 and IPv6 combined (.txt)"_ link on that page and copy the link URL. + +![Link to IP addresses we need to Whitelist](../../.gitbook/assets/image23-whitelisting-file-links.png) + +Store the link URL by pasting it to a notepad if needed. We will need to use it shortly on our Terminal. + +For the following steps to work, I am assuming that you have set up the firewall on your server using ufw as per the instructions on [THIS PAGE](securing-your-xdc-masternode.md). If you have not done so, please go to that page and follow the instructions in the section on setting up your ssh port and firewall. + +![UFW Uncomplicated Firewall](../../.gitbook/assets/image08-ufw-logo-securing-masternode.png) + +After following the setup instructions there, you will have: + +* Moved your SSH port from 22 to something else +* Have installed ufw +* Established a default policy that blocks all incoming connections (with the 2 exceptions of port 30303 and whichever port you chose to use for SSH) +* Left ports 8888 and 8989 blocked (filtered) on the assumption that the node is not being used by external applications to access the XDC blockchain via Websocket/HTTP JSON-RPC + +From this point on, we assume those steps are done and that is how your firewall setup looks. + +Now open up a terminal window and ssh to your node server. When using the following command, remember to replace “root” in this command with your actual username for the remote server, replace the "22" with whichever port you have set up for ssh on your server, and replace "ip.address" with the actual IP address of the remote server: + +``` +ssh -lroot -p22 ip.address +``` + +In the terminal, we will now download the file containing the list of Uptime Robot IP addresses for us to Whitelist. To do this we will use the "wget" command and paste the link URL we copied from the Uptime Robot website after it: + +``` +wget +``` + +It should look something like: + +![wget IP file](../../.gitbook/assets/image24-wget-ip-file.jpg) + +The file we have just downloaded with wget is actually in a DOS format (with CRLF line ends instead of the Unix format of LF line ends). This will cause errors with ufw so we first need to convert it to a unix format. Install dos2unix: + +``` +sudo apt install dos2unix +``` + +Run dos2unix on the file to convert it to the Unix format. Use the name of whatever filename you downloaded. I've used the filename IPv4andIPv6.txt as that is what the UptimeRobot file download is called today: + +``` +dos2unix IPv4andIPv6.txt +``` + +Now run this command to provide restricted access to port 8989 on your VPS to only the IP addresses listed in the file: + +``` +while IFS= read -r ip; do sudo ufw allow from "$ip" to any port 8989; done < IPv4andIPv6.txt +``` + +You can check your firewall now and you should see ports 30303 and your SSH port open, along with now all of the port 8989 entries for each IP address you have just added: + +``` +sudo ufw status +``` + +You will see a long list of entries, somewhat like this: + +![Whitelisted IP addresses](../../.gitbook/assets/image25-whitelisted-ips.png) + +Now we need to take your node offline. Change to the XDC mainnet client directory: + +``` +cd ~/XinFin-Node/mainnet +``` + +Stop the XDC mainnet client: + +``` +./docker-down.sh +``` + +Reboot your node: + +``` +reboot +``` + +After allowing enough time for your server to reboot, ssh to it again. Remember to replace “root” in this command with your actual username for the remote server, replace the "22" with whichever port you have set up for ssh on your server, and replace "ip.address" with the actual IP address of the remote server: + +``` +ssh -lroot -p22 ip.address +``` + +Change to the XDC mainnet client directory: + +``` +cd ~/XinFin-Node/mainnet +``` + +Restart the XDC mainnet client: + +``` +./docker-up.sh +``` + +Logout of your VPS: + +``` +logout +``` + +Now back on the Uptime Robot website again, repeat the "Add a New Monitor" process again but this time: + +* For Monitor Type, select "HTTP(s)". +* Give your monitor a different nickname. +* Enter the address of your node's RPC endpoint. eg http://your.nodes.IP.address:8989 +* Set the Monitoring Interval to 5mins as before. +* The Monitor Timeout just determines how long the monitor will wait for a response before determining that the RPC is offline. Should be ok to leave at 30sec. +* If you haven't specifically set up an SSL certificate on your node then you can uncheck the boxes next to "Monitor SSL errors" and "Enable SSL expiry reminders". +* Leave "HTTP Method" as HEAD. +* Tick the box next to your email address. +* Click the "Create Monitor" button. + +*** + +At this point, a list of the monitors you have just created should now be visible on the left side of the page. If you click on one of them you will see the "dashboard" for that monitor appear on the right side of the page. On the dashboard you can test your alert by clicking the "Test Notification setup" button and then clicking "Send Test Notifications" on the popup that comes up. + +![Test Notification Button](../../.gitbook/assets/image26-test-notification-setup.png) + +You can individually check both of the monitors you have just created in this way. + +*** + +You now have an uptime monitor checking every 5 minutes that: + +* Your server is pingable and therefore online/reachable on network; and +* Your XDC client is running as its RPC endpoint is up; and +* You have secured the HTTP JSON-RPC endpoint by making it only accessible from the Uptime Robot IP addresses you have whitelisted on your firewall + +This will help you to ensure that your XDC node is always online, which will help to prevent missed rewards, ensure the stability of the network, and allow you to identify and fix any problems with your node as soon as possible. + +*** + +![Apothem Testnet](../../.gitbook/assets/image15-appendix-header.png) + +## Appendix A - Uptime Monitoring for your Apothem Testnet Masternode + +### Registering on Uptime Robot + +No changes from the Mainnet instructions above. + +*** + +### Creating a monitor that will intermittently ping your node server + +No changes from the Mainnet instructions above. + +*** + +### Creating a monitor for your client's RPC endpoint + +Go to [THIS PAGE](https://uptimerobot.com/help/locations/) shown in the image below. + +![Uptime Robot Locations and IPs](../../.gitbook/assets/image22-locations-and-ips.png) + +Right click on the green _"IPv4 and IPv6 combined (.txt)"_ link on that page and copy the link URL. This is a link to the file containing a list of the IP addresses we need to whitelist. Store the link URL by pasting it to a notepad if needed. We will need to use it shortly on our Terminal. + +For the following steps to work, we assume that you have set up the firewall on your server using ufw as per the Apothem instructions in [THIS PAGE](securing-your-xdc-masternode.md). If you have not done so, please go to that article and follow the instructions in the Apothem section on setting up your ssh port and firewall. + +![UFW Uncomplicated Firewall](../../.gitbook/assets/image08-ufw-logo-securing-masternode.png) + +After following the setup instructions there, you will have: + +* Moved your SSH port from 22 to something else +* Have installed ufw +* Established a default policy that blocks all incoming connections (with the 2 exceptions of port 30304 and whichever port you chose to use for SSH) +* Left ports 8898 and 8999 blocked (filtered) on the assumption that the node is not being used by external applications to access the XDC blockchain via Websocket/HTTP JSON-RPC + +From this point on, we assume those steps are done and that is how your firewall setup looks. + +Now open up a terminal window and ssh to your node server. When using the following command, remember to replace “root” in this command with your actual username for the remote server, replace the "22" with whichever port you have set up for ssh on your server, and replace "ip.address" with the actual IP address of the remote server: + +``` +ssh -lroot -p22 ip.address +``` + +Use wget to download the Uptime Robot file containing the IP addresses we need to whitelist. Use the link URL we copied from the Uptime Robot website to specify the file location: + +``` +wget +``` + +It should look something like: + +![wget IP file](../../.gitbook/assets/image24-wget-ip-file.jpg) + +Install dos2unix: + +``` +sudo apt install dos2unix +``` + +Use dos2unix to convert the file to the Unix format: + +``` +dos2unix IPv4andIPv6.txt +``` + +Now run this command to provide restricted access to port 8999 on your VPS to only the IP addresses listed in the file: + +``` +while IFS= read -r ip; do sudo ufw allow from "$ip" to any port 8999; done < IPv4andIPv6.txt +``` + +You can check your firewall now and you should see ports 30304 and your SSH port open, along with now all of the port 8999 entries for each IP address you have just added: + +``` +sudo ufw status +``` + +Stop your Apothem Testnet client and reboot your server: + +``` +cd ~/XinFin-Node/testnet +./docker-down.sh +reboot +``` + +After allowing enough time for your server to reboot, ssh to it again. Remember to replace “root” in this command with your actual username for the remote server, replace the "22" with whichever port you have set up for ssh on your server, and replace "ip.address" with the actual IP address of the remote server: + +``` +ssh -lroot -p22 ip.address +``` + +Restart the Apothem Testnet client and logout of your server: + +``` +cd ~/XinFin-Node/testnet +./docker-up.sh +logout +``` + +Now back on the Uptime Robot website again, repeat the "Add a New Monitor" process again but this time: + +* For Monitor Type, select "HTTP(s)". +* Give your monitor a different nickname. +* Enter the address of your node's RPC endpoint. eg http://your.nodes.IP.address:8999 +* Set the Monitoring Interval to 5mins as before. +* The Monitor Timeout just determines how long the monitor will wait for a response before determining that the RPC is offline. Should be ok to leave at 30sec. +* If you haven't specifically set up an SSL certificate on your node then you can uncheck the boxes next to "Monitor SSL errors" and "Enable SSL expiry reminders". +* Leave "HTTP Method" as HEAD. +* Tick the box next to your email address. +* Click the "Create Monitor" button. + +*** + +Individually test both of the monitors you have just created as per the process described in the Mainnet section above. + +*** + +You now have an uptime monitor checking every 5 minutes that: + +* Your server is pingable and therefore online/reachable on network; and +* Your Apothem Testnet client is running as its RPC endpoint is up; and +* You have secured the HTTP JSON-RPC endpoint by making it only accessible from the Uptime Robot IP addresses you have whitelisted on your firewall + +*** diff --git a/run-a-node/node-commands-and-config.md b/run-a-node/node-commands-and-config.md new file mode 100644 index 00000000..eafa3499 --- /dev/null +++ b/run-a-node/node-commands-and-config.md @@ -0,0 +1,1143 @@ +# Commands and Config Options + +The XDC client software runs as a containerized application in Docker. This ensures a standardized and efficient environment for running XDC nodes. Let's start by examining this client software. + +To obtain a comprehensive list of available commands and options, we can use the following command with the XDC Client: + +``` +sudo docker exec -it mainnet_xinfinnetwork_1 XDC --help +``` + +By executing this command, we gain access to the XDC client within the Docker container named _mainnet\_xinfinnetwork\_1_. The inclusion of the _--help_ flag prompts the client to display its usage information, presenting an extensive list of commands and their respective options. The first page of output is shown here: + +![XDC Client Commands and Configuration Options](../.gitbook/assets/image31-xdc-client-commands.png) + +From the output, we can observe that the appropriate formatting for commands and options within the XDC client's Docker container is as follows: + +``` +XDC [options] command [command options] [arguments...] +``` + +By adhering to this structure, we can pass commands and options to Docker when running within the container. Consequently, the appropriate command structure from our external command line also becomes clear: + +``` +sudo docker exec -it mainnet_xinfinnetwork_1 XDC [options] command [command options] [arguments...] +``` + +Now, let's proceed to explore each command and option individually, based on the output obtained when using the _--help_ flag. + +*** + +## COMMANDS + +## account + +Manage accounts, list all existing accounts, import a private key into a new account, create a new account or update an existing account. + +It supports interactive mode, when you are prompted for password as well as non-interactive mode where passwords are supplied via a given password file. Non-interactive mode is only meant for scripted use on test networks or known safe environments. + +Make sure you remember the password you gave when creating a new account (with either new or import). Without it you are not able to unlock your account. + +Note that exporting your key in unencrypted format is NOT supported. + +Keys are stored under /keystore. + +It is safe to transfer the entire directory or the individual keys therein between XDC nodes by simply copying. + +Make sure you backup your keys regularly. + +### USAGE: + +``` +XDC account command [command options] [arguments...] +``` + +### account COMMANDS: + +#### list _\[command options] \[arguments...]_ + +``` +XDC account list +``` + +Print a short summary of all accounts + +**XDPoSChain OPTIONS:** + +* _--datadir "/root/.XDC"_ Data directory for the databases and keystore +* _--keystore_ Directory for the keystore (default = inside the datadir) + +#### new \[command options] \[arguments...] + +``` +XDC account new +``` + +Creates a new account and prints the address. + +The account is saved in encrypted format, you are prompted for a passphrase. + +You must remember this passphrase to unlock your account in the future. + +For non-interactive use the passphrase can be specified with the --password flag. + +Note, this is meant to be used for testing only, it is a bad idea to save your password to file or expose in any other way. + +**XDPoSChain OPTIONS:** + +* _--datadir "/root/.XDC"_ Data directory for the databases and keystore +* _--keystore_ Directory for the keystore (default = inside the datadir) + +**ACCOUNT OPTIONS:** + +* _--password value_ Password file to use for non-interactive password input + +**MISC OPTIONS:** + +* _--lightkdf_ Reduce key-derivation RAM & CPU usage at some expense of KDF strength + +#### update \[command options] \[arguments...] + +``` +XDC account update [options]
+``` + +Update an existing account. + +The account is saved in the newest version in encrypted format, you are prompted for a passphrase to unlock the account and another to save the updated file. + +This same command can therefore be used to migrate an account of a deprecated format to the newest format or change the password for an account. + +For non-interactive use the passphrase can be specified with the --password flag. + +Since only one password can be given, only format update can be performed, changing your password is only possible interactively. + +**XDPoSChain OPTIONS:** + +* _--datadir "/root/.XDC"_ Data directory for the databases and keystore +* _--keystore_ Directory for the keystore (default = inside the datadir) + +**MISC OPTIONS:** + +* _--lightkdf_ Reduce key-derivation RAM & CPU usage at some expense of KDF strength + +#### import \[command options] \[arguments...] + +``` +XDC account import [options] +``` + +Imports an unencrypted private key from and creates a new account. Prints the address. + +The keyfile is assumed to contain an unencrypted private key in hexadecimal format. + +The account is saved in encrypted format, you are prompted for a passphrase. + +You must remember this passphrase to unlock your account in the future. + +For non-interactive use the passphrase can be specified with the --password flag + +Note: As you can directly copy your encrypted accounts to another XDC instance, this import mechanism is not needed when you transfer an account between nodes. + +**XDPoSChain OPTIONS:** + +* _--datadir "/root/.XDC"_ Data directory for the databases and keystore +* _--keystore_ Directory for the keystore (default = inside the datadir) + +**ACCOUNT OPTIONS:** + +* _--password value_ Password file to use for non-interactive password input + +**MISC OPTIONS:** + +* _--lightkdf_ Reduce key-derivation RAM & CPU usage at some expense of KDF strength + +*** + +## attach + +The XDC console is an interactive shell for the JavaScript runtime environment which exposes a node admin interface as well as the Ðapp JavaScript API. + +See https://github.com/XinFinOrg/XDPoSChain/wiki/JavaScript-Console. + +This command allows to open a console on a running XDC node. + +### USAGE: + +``` +XDC attach [command options] [arguments...] +``` + +**XDPoSChain OPTIONS:** + +* _--datadir "/root/.XDC"_ Data directory for the databases and keystore + +**API AND CONSOLE OPTIONS:** + +* _--jspath loadScript_ JavaScript root path for loadScript (default: ".") +* _--exec value_ Execute JavaScript statement +* _--preload value_ Comma separated list of JavaScript files to preload into the console + +*** + +## console + +The XDC console is an interactive shell for the JavaScript runtime environment which exposes a node admin interface as well as the Ðapp JavaScript API. See https://github.com/XinFinOrg/XDPoSChain/wiki/JavaScript-Console. + +### USAGE: + +``` +XDC console [command options] [arguments...] +``` + +**XDPoSChain OPTIONS:** + +* _--identity value_ Custom node name +* _--datadir "/root/.XDC"_ Data directory for the databases and keystore +* _--keystore_ Directory for the keystore (default = inside the datadir) +* _--syncmode "full"_ Blockchain sync mode ("fast", "full", or "light") +* _--gcmode value_ Blockchain garbage collection mode ("full", "archive") (default: "full") +* _--networkid value_ Network identifier (integer, 89=XDPoSChain) (default: 88) +* _--ethstats value_ Reporting URL of a ethstats service (nodename:secret@host:port) +* _--config value_ TOML configuration file + +**ACCOUNT OPTIONS:** + +* _--unlock value_ Comma separated list of accounts to unlock +* _--password value_ Password file to use for non-interactive password input + +**API AND CONSOLE OPTIONS:** + +* _--rpccorsdomain value_ Comma separated list of domains from which to accept cross origin requests (browser enforced) +* _--rpcvhosts value_ Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '\*' wildcard. (default: "localhost") +* _--rpc_ Enable the HTTP-RPC server +* _--rpcaddr value_ HTTP-RPC server listening interface (default: "localhost") +* _--rpcport value_ HTTP-RPC server listening port (default: 8545). _See Appendix A at the base of this page for port clarification._ +* _--rpcapi value_ API's offered over the HTTP-RPC interface +* _--ws_ Enable the WS-RPC server +* _--wsaddr value_ WS-RPC server listening interface (default: "localhost") +* _--wsport value_ WS-RPC server listening port (default: 8546). _See Appendix A at the base of this page for port clarification._ +* _--wsapi value_ API's offered over the WS-RPC interface +* _--wsorigins value_ Origins from which to accept websockets requests +* _--ipcdisable_ Disable the IPC-RPC server +* _--ipcpath_ Filename for IPC socket/pipe within the datadir (explicit paths escape it) +* _--jspath loadScript_ JavaScript root path for loadScript (default: ".") +* _--exec value_ Execute JavaScript statement +* _--preload value_ Comma separated list of JavaScript files to preload into the console + +**NETWORKING OPTIONS:** + +* _--bootnodes value_ Comma separated enode URLs for P2P discovery bootstrap (set v4+v5 instead for light servers) +* _--bootnodesv4 value_ Comma separated enode URLs for P2P v4 discovery bootstrap (light server, full nodes) +* _--bootnodesv5 value_ Comma separated enode URLs for P2P v5 discovery bootstrap (light server, light nodes) +* _--port value_ Network listening port (default: 30303) +* _--maxpeers value_ Maximum number of network peers (network disabled if set to 0) (default: 25) +* _--maxpendpeers value_ Maximum number of pending connection attempts (defaults used if set to 0) (default: 0) +* _--nat value_ NAT port mapping mechanism (any|none|upnp|pmp|extip:) (default: "any") +* _--nodiscover_ Disables the peer discovery mechanism (manual peer addition) +* _--nodekey value_ P2P node key file +* _--nodekeyhex value_ P2P node key as hex (for testing) + +**STAKER OPTIONS:** + +* _--etherbase value_ Public address for block mining rewards (default = first account created) (default: "0") +* _--gasprice "250000000"_ Minimal gas price to accept for mining a transactions +* _--minerthreads value_ Number of CPU threads to use for staking (default: 8) +* _--mine_ Enable staking +* _--targetgaslimit value_ Target gas limit sets the artificial target gas floor for the blocks to mine (default: 84000000) + +**LOGGING AND DEBUGGING OPTIONS:** + +* _--metrics_ Enable metrics collection and reporting + +**DEPRECATED OPTIONS:** + +* _--fast_ Enable fast syncing through state downloads +* _--light_ Enable light client mode + +**MISC OPTIONS:** + +* _--XDCx_ Enable the XDCX protocol +* _--XDCx.datadir "/root/.XDC/XDCx"_ Data directory for the XDCX databases +* _--XDCx.dbengine value_ Database engine for XDCX (leveldb, mongodb) (default: "leveldb") +* _--XDCx.dbConnectionUrl value_ ConnectionUrl to database if dbEngine is mongodb. Host:port. If there are multiple instances, separated by comma. Eg: localhost:27017,localhost:27018 (default: "localhost:27017") +* _--XDCx.dbReplicaSetName value_ ReplicaSetName if Master-Slave is setup +* _--XDCx.dbName value_ Database name for XDCX (default: "XDCdex") +* _--txpool.nolocals_ Disables price exemptions for locally submitted transactions +* _--txpool.journal value_ Disk journal for local transaction to survive node restarts (default: "transactions.rlp") +* _--txpool.rejournal value_ Time interval to regenerate the local transaction journal (default: 1h0m0s) +* _--txpool.pricelimit value_ Minimum gas price limit to enforce for acceptance into the pool (default: 1) +* _--txpool.pricebump value_ Price bump percentage to replace an already existing transaction (default: 10) +* _--txpool.accountslots value_ Minimum number of executable transaction slots guaranteed per account (default: 16) +* _--txpool.globalslots value_ Maximum number of executable transaction slots for all accounts (default: 4096) +* _--txpool.accountqueue value_ Maximum number of non-executable transaction slots permitted per account (default: 64) +* _--txpool.globalqueue value_ Maximum number of non-executable transaction slots for all accounts (default: 1024) +* _--txpool.lifetime value_ Maximum amount of time non-executable transaction are queued (default: 3h0m0s) +* _--apothem_ XDC Apothem Network +* _--enable-0x-prefix_ Address use 0x-prefix (default = false) +* _--rewound value_ Rewound blocks (default: 0) +* _--announce-txs_ Always commit transactions +* _--store-reward_ Store reward to file +* _--rollback value_ Rollback chain at hash +* _--slave_ Enable slave mode +* _--shh_ Enable Whisper +* _--shh.maxmessagesize value_ Max message size accepted (default: 1048576) +* _--shh.pow value_ Minimum POW accepted (default: 0.2) + +*** + +## dump + +Dump a specific block from storage + +The arguments are interpreted as block numbers or hashes. Use "XDC dump 0" to dump the genesis block. + +### USAGE: + +``` +XDC dump [command options] [arguments...] +``` + +**XDPoSChain OPTIONS:** + +* _--datadir "/root/.XDC"_ Data directory for the databases and keystore + +**DEPRECATED OPTIONS:** + +* _--light_ Enable light client mode + +**MISC OPTIONS:** + +* _--cache value_ Megabytes of memory allocated to internal caching (default: 1024) + +*** + +## dumpconfig + +The dumpconfig command shows configuration values. + +### USAGE: + +``` +XDC dumpconfig [command options] [arguments...] +``` + +**XDPoSChain OPTIONS:** + +* _--identity value_ Custom node name +* _--datadir "/root/.XDC"_ Data directory for the databases and keystore +* _--keystore_ Directory for the keystore (default = inside the datadir) +* _--syncmode "full"_ Blockchain sync mode ("fast", "full", or "light") +* _--gcmode value_ Blockchain garbage collection mode ("full", "archive") (default: "full") +* _--networkid value_ Network identifier (integer, 89=XDPoSChain) (default: 88) +* _--ethstats value_ Reporting URL of a ethstats service (nodename:secret@host:port) +* _--config value_ TOML configuration file + +**ACCOUNT OPTIONS:** + +* _--unlock value_ Comma separated list of accounts to unlock +* _--password value_ Password file to use for non-interactive password input + +**API AND CONSOLE OPTIONS:** + +* _--rpccorsdomain value_ Comma separated list of domains from which to accept cross origin requests (browser enforced) +* _--rpcvhosts value_ Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '\*' wildcard. (default: "localhost") +* _--rpc_ Enable the HTTP-RPC server +* _--rpcaddr value_ HTTP-RPC server listening interface (default: "localhost") +* _--rpcport value_ HTTP-RPC server listening port (default: 8545). _See Appendix A at the base of this page for port clarification._ +* _--rpcapi value_ API's offered over the HTTP-RPC interface +* _--ws_ Enable the WS-RPC server +* _--wsaddr value_ WS-RPC server listening interface (default: "localhost") +* _--wsport value_ WS-RPC server listening port (default: 8546). _See Appendix A at the base of this page for port clarification._ +* _--wsapi value_ API's offered over the WS-RPC interface +* _--wsorigins value_ Origins from which to accept websockets requests +* _--ipcdisable_ Disable the IPC-RPC server +* _--ipcpath_ Filename for IPC socket/pipe within the datadir (explicit paths escape it) + +**NETWORKING OPTIONS:** + +* _--bootnodes value_ Comma separated enode URLs for P2P discovery bootstrap (set v4+v5 instead for light servers) +* _--bootnodesv4 value_ Comma separated enode URLs for P2P v4 discovery bootstrap (light server, full nodes) +* _--bootnodesv5 value_ Comma separated enode URLs for P2P v5 discovery bootstrap (light server, light nodes) +* _--port value_ Network listening port (default: 30303) +* _--maxpeers value_ Maximum number of network peers (network disabled if set to 0) (default: 25) +* _--maxpendpeers value_ Maximum number of pending connection attempts (defaults used if set to 0) (default: 0) +* _--nat value_ NAT port mapping mechanism (any|none|upnp|pmp|extip:) (default: "any") +* _--nodiscover_ Disables the peer discovery mechanism (manual peer addition) +* _--nodekey value_ P2P node key file +* _--nodekeyhex value_ P2P node key as hex (for testing) + +**STAKER OPTIONS:** + +* _--etherbase value_ Public address for block mining rewards (default = first account created) (default: "0") +* _--gasprice "250000000"_ Minimal gas price to accept for mining a transactions +* _--minerthreads value_ Number of CPU threads to use for staking (default: 8) +* _--mine_ Enable staking +* _--targetgaslimit value_ Target gas limit sets the artificial target gas floor for the blocks to mine (default: 84000000) + +**LOGGING AND DEBUGGING OPTIONS:** + +* _--metrics_ Enable metrics collection and reporting + +**DEPRECATED OPTIONS:** + +* _--fast_ Enable fast syncing through state downloads +* _--light_ Enable light client mode + +**MISC OPTIONS:** + +* _--XDCx_ Enable the XDCX protocol +* _--XDCx.datadir "/root/.XDC/XDCx"_ Data directory for the XDCX databases +* _--XDCx.dbengine value_ Database engine for XDCX (leveldb, mongodb) (default: "leveldb") +* _--XDCx.dbConnectionUrl value_ ConnectionUrl to database if dbEngine is mongodb. Host:port. If there are multiple instances, separated by comma. Eg: localhost:27017,localhost:27018 (default: "localhost:27017") +* _--XDCx.dbReplicaSetName value_ ReplicaSetName if Master-Slave is setup +* _--XDCx.dbName value_ Database name for XDCX (default: "XDCdex") +* _--txpool.nolocals_ Disables price exemptions for locally submitted transactions +* _--txpool.journal value_ Disk journal for local transaction to survive node restarts (default: "transactions.rlp") +* _--txpool.rejournal value_ Time interval to regenerate the local transaction journal (default: 1h0m0s) +* _--txpool.pricelimit value_ Minimum gas price limit to enforce for acceptance into the pool (default: 1) +* _--txpool.pricebump value_ Price bump percentage to replace an already existing transaction (default: 10) +* _--txpool.accountslots value_ Minimum number of executable transaction slots guaranteed per account (default: 16) +* _--txpool.globalslots value_ Maximum number of executable transaction slots for all accounts (default: 4096) +* _--txpool.accountqueue value_ Maximum number of non-executable transaction slots permitted per account (default: 64) +* _--txpool.globalqueue value_ Maximum number of non-executable transaction slots for all accounts (default: 1024) +* _--txpool.lifetime value_ Maximum amount of time non-executable transaction are queued (default: 3h0m0s) +* _--apothem_ XDC Apothem Network +* _--enable-0x-prefix_ Address use 0x-prefix (default = false) +* _--rewound value_ Rewound blocks (default: 0) +* _--announce-txs_ Always commit transactions +* _--store-reward_ Store reward to file +* _--rollback value_ Rollback chain at hash +* _--slave_ Enable slave mode +* _--shh_ Enable Whisper +* _--shh.maxmessagesize value_ Max message size accepted (default: 1048576) +* _--shh.pow value_ Minimum POW accepted (default: 0.2) + +*** + +## export + +Export blockchain into file + +Requires a first argument of the file to write to. Optional second and third arguments control the first and last block to write. In this mode, the file will be appended if already existing. + +### USAGE: + +``` +XDC export [command options] [arguments...] +``` + +**XDPoSChain OPTIONS:** + +* _--datadir "/root/.XDC"_ Data directory for the databases and keystore + +**DEPRECATED OPTIONS:** + +* _--light_ Enable light client mode + +**MISC OPTIONS:** + +* _--cache value_ Megabytes of memory allocated to internal caching (default: 1024) + +*** + +## import + +Import a blockchain file + +The import command imports blocks from an RLP-encoded form. The form can be one file with several RLP-encoded blocks, or several files can be used. + +If only one file is used, import error will result in failure. If several files are used, processing will proceed even if an individual RLP-file import failure occurs. + +### USAGE: + +``` +XDC import [command options] [arguments...] +``` + +**XDPoSChain OPTIONS:** + +* _--datadir "/root/.XDC"_ Data directory for the databases and keystore +* _--gcmode value_ Blockchain garbage collection mode ("full", "archive") (default: "full") + +**DEPRECATED OPTIONS:** + +* _--light_ Enable light client mode + +**MISC OPTIONS:** + +* _--cache value_ Megabytes of memory allocated to internal caching (default: 1024) +* _--cache.database value_ Percentage of cache memory allowance to use for database io (default: 75) +* _--cache.gc value_ Percentage of cache memory allowance to use for trie pruning (default: 25) + +*** + +## init + +Bootstrap and initialize a new genesis block + +The init command initializes a new genesis block and definition for the network. This is a destructive action and changes the network in which you will be participating. + +It expects the genesis file as argument. + +### USAGE: + +``` +XDC init [command options] [arguments...] +``` + +**XDPoSChain OPTIONS:** + +* _--datadir "/root/.XDC"_ Data directory for the databases and keystore + +**DEPRECATED OPTIONS:** + +* _--light_ Enable light client mode + +*** + +## js + +Execute the specified JavaScript files + +The JavaScript VM exposes a node admin interface as well as the Ðapp JavaScript API. See https://github.com/XinFinOrg/XDPoSChain/wiki/JavaScript-Console + +### USAGE: + +``` +XDC js [command options] [arguments...] +``` + +**XDPoSChain OPTIONS:** + +* _--identity value_ Custom node name +* _--datadir "/root/.XDC"_ Data directory for the databases and keystore +* _--keystore_ Directory for the keystore (default = inside the datadir) +* _--syncmode "full"_ Blockchain sync mode ("fast", "full", or "light") +* _--gcmode value_ Blockchain garbage collection mode ("full", "archive") (default: "full") +* _--networkid value_ Network identifier (integer, 89=XDPoSChain) (default: 88) +* _--ethstats value_ Reporting URL of a ethstats service (nodename:secret@host:port) +* _--config value_ TOML configuration file + +**ACCOUNT OPTIONS:** + +* _--unlock value_ Comma separated list of accounts to unlock +* _--password value_ Password file to use for non-interactive password input + +**API AND CONSOLE OPTIONS:** + +* _--rpccorsdomain value_ Comma separated list of domains from which to accept cross origin requests (browser enforced) +* _--rpcvhosts value_ Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '\*' wildcard. (default: "localhost") +* _--jspath loadScript_ JavaScript root path for loadScript (default: ".") +* _--exec value_ Execute JavaScript statement +* _--preload value_ Comma separated list of JavaScript files to preload into the console + +**NETWORKING OPTIONS:** + +* _--bootnodes value_ Comma separated enode URLs for P2P discovery bootstrap (set v4+v5 instead for light servers) +* _--bootnodesv4 value_ Comma separated enode URLs for P2P v4 discovery bootstrap (light server, full nodes) +* _--bootnodesv5 value_ Comma separated enode URLs for P2P v5 discovery bootstrap (light server, light nodes) +* _--port value_ Network listening port (default: 30303) +* _--maxpeers value_ Maximum number of network peers (network disabled if set to 0) (default: 25) +* _--maxpendpeers value_ Maximum number of pending connection attempts (defaults used if set to 0) (default: 0) +* _--nat value_ NAT port mapping mechanism (any|none|upnp|pmp|extip:) (default: "any") +* _--nodiscover_ Disables the peer discovery mechanism (manual peer addition) +* _--nodekey value_ P2P node key file +* _--nodekeyhex value_ P2P node key as hex (for testing) + +**STAKER OPTIONS:** + +* _--etherbase value_ Public address for block mining rewards (default = first account created) (default: "0") +* _--gasprice "250000000"_ Minimal gas price to accept for mining a transactions +* _--minerthreads value_ Number of CPU threads to use for staking (default: 8) +* _--mine_ Enable staking +* _--targetgaslimit value_ Target gas limit sets the artificial target gas floor for the blocks to mine (default: 84000000) + +**LOGGING AND DEBUGGING OPTIONS:** + +* _--metrics_ Enable metrics collection and reporting + +**DEPRECATED OPTIONS:** + +* _--fast_ Enable fast syncing through state downloads +* _--light_ Enable light client mode + +**MISC OPTIONS:** + +* _--XDCx_ Enable the XDCX protocol +* _--XDCx.datadir "/root/.XDC/XDCx"_ Data directory for the XDCX databases +* _--XDCx.dbengine value_ Database engine for XDCX (leveldb, mongodb) (default: "leveldb") +* _--XDCx.dbConnectionUrl value_ ConnectionUrl to database if dbEngine is mongodb. Host:port. If there are multiple instances, separated by comma. Eg: localhost:27017,localhost:27018 (default: "localhost:27017") +* _--XDCx.dbReplicaSetName value_ ReplicaSetName if Master-Slave is setup +* _--XDCx.dbName value_ Database name for XDCX (default: "XDCdex") +* _--txpool.nolocals_ Disables price exemptions for locally submitted transactions +* _--txpool.journal value_ Disk journal for local transaction to survive node restarts (default: "transactions.rlp") +* _--txpool.rejournal value_ Time interval to regenerate the local transaction journal (default: 1h0m0s) +* _--txpool.pricelimit value_ Minimum gas price limit to enforce for acceptance into the pool (default: 1) +* _--txpool.pricebump value_ Price bump percentage to replace an already existing transaction (default: 10) +* _--txpool.accountslots value_ Minimum number of executable transaction slots guaranteed per account (default: 16) +* _--txpool.globalslots value_ Maximum number of executable transaction slots for all accounts (default: 4096) +* _--txpool.accountqueue value_ Maximum number of non-executable transaction slots permitted per account (default: 64) +* _--txpool.globalqueue value_ Maximum number of non-executable transaction slots for all accounts (default: 1024) +* _--txpool.lifetime value_ Maximum amount of time non-executable transaction are queued (default: 3h0m0s) +* _--apothem_ XDC Apothem Network +* _--enable-0x-prefix_ Address use 0x-prefix (default = false) +* _--rewound value_ Rewound blocks (default: 0) +* _--announce-txs_ Always commit transactions +* _--store-reward_ Store reward to file +* _--rollback value_ Rollback chain at hash +* _--slave_ Enable slave mode + +*** + +### removedb + +Remove blockchain and state databases. + +### USAGE: + +``` +XDC removedb [command options] [arguments...] +``` + +**XDPoSChain OPTIONS:** + +* _--datadir "/root/.XDC"_ Data directory for the databases and keystore + +**DEPRECATED OPTIONS:** + +* _--light_ Enable light client mode + +*** + +### version + +Print version numbers. + +The output of this command is supposed to be machine-readable. + +### USAGE: + +``` +XDC version [arguments...] +``` + +*** + +### wallet + +Manage XDPoSChain wallets. + +This will prompt for your password and imports your XDC account. It can be used non-interactively with the --password option taking a passwordfile as argument containing the wallet password in plaintext. + +### USAGE: + +``` +XDC wallet command [command options] [arguments...] +``` + +**COMMANDS (ACCOUNT COMMANDS):** + +* _import_ Import XDPoSChain wallet + +**OPTIONS:** + +* _--help, -h_ Show help + +*** + +### help, h + +Shows a list of commands or help for one command. + +### USAGE: + +``` +XDC help [arguments...] +``` + +*** + +## XDPoSChain OPTIONS + +### --config _value_ + +TOML configuration file + +*** + +### --datadir _"/root/.XDC"_ + +Data directory for the databases and keystore + +*** + +### --keystore + +Directory for the keystore (default = inside the datadir) + +*** + +### --networkid _value_ + +Network identifier (integer, 89=XDPoSChain) (default: 88) + +*** + +### --syncmode _"full"_ + +Blockchain sync mode ("fast", "full", or "light") + +*** + +### --gcmode _value_ + +Blockchain garbage collection mode ("full", "archive") (default: "full") + +*** + +### --ethstats _value_ + +Reporting URL of a ethstats service (nodename:secret@host:port) + +*** + +### --identity _value_ + +Custom node name + +*** + +## ACCOUNT OPTIONS + +### --unlock _value_ + +Comma separated list of accounts to unlock + +*** + +### --password _value_ + +Password file to use for non-interactive password input + +*** + +## API AND CONSOLE OPTIONS + +### --rpc + +Enable the HTTP-RPC server + +*** + +### --rpcaddr _value_ + +HTTP-RPC server listening interface (default: "localhost") + +*** + +### --rpcport _value_ + +HTTP-RPC server listening port (default: 8545). _See Appendix A at the base of this page for port clarification._ + +*** + +### --rpcapi _value_ + +API's offered over the HTTP-RPC interface + +*** + +### --ws + +Enable the WS-RPC server + +*** + +### --wsaddr _value_ + +WS-RPC server listening interface (default: "localhost") + +*** + +### --wsport _value_ + +WS-RPC server listening port (default: 8546). _See Appendix A at the base of this page for port clarification._ + +*** + +### --wsapi _value_ + +API's offered over the WS-RPC interface + +*** + +### --wsorigins _value_ + +Origins from which to accept websockets requests + +*** + +### --ipcdisable + +Disable the IPC-RPC server + +*** + +### --ipcpath + +Filename for IPC socket/pipe within the datadir (explicit paths escape it) + +*** + +### --rpccorsdomain _value_ + +Comma separated list of domains from which to accept cross origin requests (browser enforced) + +*** + +### --rpcvhosts _value_ + +Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '\*' wildcard. (default: "localhost") + +*** + +### --jspath _loadScript_ + +JavaScript root path for loadScript (default: ".") + +*** + +### --exec _value_ + +Execute JavaScript statement + +*** + +### --preload _value_ + +Comma separated list of JavaScript files to preload into the console + +*** + +## NETWORKING OPTIONS + +### --bootnodes _value_ + +Comma separated enode URLs for P2P discovery bootstrap (set v4+v5 instead for light servers) + +*** + +### --bootnodesv4 _value_ + +Comma separated enode URLs for P2P v4 discovery bootstrap (light server, full nodes) + +*** + +### --bootnodesv5 _value_ + +Comma separated enode URLs for P2P v5 discovery bootstrap (light server, light nodes) + +*** + +### --port _value_ + +Network listening port (default: 30303) + +*** + +### --maxpeers _value_ + +Maximum number of network peers (network disabled if set to 0) (default: 25) + +*** + +### --maxpendpeers _value_ + +Maximum number of pending connection attempts (defaults used if set to 0) (default: 0) + +*** + +### --nat _value_ + +NAT port mapping mechanism (any|none|upnp|pmp|extip:) (default: "any") + +*** + +### --nodiscover + +Disables the peer discovery mechanism (manual peer addition) + +*** + +### --nodekey _value_ + +P2P node key file + +*** + +### --nodekeyhex _value_ + +P2P node key as hex (for testing) + +*** + +## STAKER OPTIONS + +### --mine + +Enable staking + +*** + +### --minerthreads _value_ + +Number of CPU threads to use for staking (default: 8) + +*** + +### --etherbase _value_ + +Public address for block mining rewards (default = first account created) (default: "0") + +*** + +### --targetgaslimit _value_ + +Target gas limit sets the artificial target gas floor for the blocks to mine (default: 84000000) + +*** + +### --gasprice _"250000000"_ + +Minimal gas price to accept for mining a transactions + +*** + +### --extradata _value_ + +Block extra data set by the miner (default = client version) + +*** + +## LOGGING AND DEBUGGING OPTIONS + +### --metrics + +Enable metrics collection and reporting + +*** + +### --verbosity _value_ + +Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail (default: 3) + +*** + +### --cpuprofile _value_ + +Write CPU profile to the given file + +*** + +## DEPRECATED OPTIONS + +### --fast + +Enable fast syncing through state downloads + +*** + +### --light + +Enable light client mode + +*** + +## MISC OPTIONS + +### --XDCx + +Enable the XDCX protocol + +*** + +### --XDCx.datadir _"/root/.XDC/XDCx"_ + +Data directory for the XDCX databases + +*** + +### --XDCx.dbengine _value_ + +Database engine for XDCX (leveldb, mongodb) (default: "leveldb") + +*** + +### --XDCx.dbConnectionUrl _value_ + +ConnectionUrl to database if dbEngine is mongodb. Host:port. If there are multiple instances, separated by comma. Eg: localhost:27017,localhost:27018 (default: "localhost:27017") + +*** + +### --XDCx.dbReplicaSetName _value_ + +ReplicaSetName if Master-Slave is setup + +*** + +### --XDCx.dbName _value_ + +Database name for XDCX (default: "XDCdex") + +*** + +### --txpool.nolocals + +Disables price exemptions for locally submitted transactions + +*** + +### --txpool.journal _value_ + +Disk journal for local transaction to survive node restarts (default: "transactions.rlp") + +*** + +### --txpool.rejournal _value_ + +Time interval to regenerate the local transaction journal (default: 1h0m0s) + +*** + +### --txpool.pricelimit _value_ + +Minimum gas price limit to enforce for acceptance into the pool (default: 1) + +*** + +### --txpool.pricebump _value_ + +Price bump percentage to replace an already existing transaction (default: 10) + +*** + +### --txpool.accountslots _value_ + +Minimum number of executable transaction slots guaranteed per account (default: 16) + +*** + +### --txpool.globalslots _value_ + +Maximum number of executable transaction slots for all accounts (default: 4096) + +*** + +### --txpool.accountqueue _value_ + +Maximum number of non-executable transaction slots permitted per account (default: 64) + +*** + +### --txpool.globalqueue _value_ + +Maximum number of non-executable transaction slots for all accounts (default: 1024) + +*** + +### --txpool.lifetime _value_ + +Maximum amount of time non-executable transaction are queued (default: 3h0m0s) + +*** + +### --apothem + +XDC Apothem Network + +*** + +### --enable-0x-prefix + +Address use 0x-prefix (default = false) + +*** + +### --rewound _value_ + +Rewound blocks (default: 0) + +*** + +### --announce-txs + +Always commit transactions + +*** + +### --store-reward + +Store reward to file + +*** + +### --rollback _value_ + +Rollback chain at hash + +*** + +### --slave + +Enable slave mode + +*** + +### --shh + +Enable Whisper + +*** + +### --shh.maxmessagesize _value_ + +Max message size accepted (default: 1048576) + +*** + +### --shh.pow _value_ + +Minimum POW accepted (default: 0.2) + +*** + +### --help, -h + +show help + +*** + +![Appendix A - docker-compose.yml](../.gitbook/assets/image15-appendix-header.png) + +## APPENDIX A - docker-compose.yml + +The "docker-compose.yml" file (contents shown below) is a configuration file written in YAML (YAML Ain't Markup Language) format used by Docker Compose. It defines the services, containers, and their configurations for the Dockerized implementation of the XDC Mainnet Client. + +![docker-compose.yml](../.gitbook/assets/image32-docker-compose-yml-file.png) + +Let's go through the contents of the file and their meanings: + +* **version: "3.4":** Specifies the version of the Docker Compose syntax being used. +* **services:** Defines the list of services (containers) that will be created and managed by Docker Compose. +* **xinfinnetwork:** The name of the service or container defined within the Docker Compose file. +* **image: xinfinorg/xinfinnetwork:v1.4.6:** Specifies the Docker image to be used for the "xinfinnetwork" service. In this case, it is using the "xinfinorg/xinfinnetwork" image with version "v1.4.6". This image contains the XDC Mainnet Client software. +* **volumes:** Defines the volumes to be mounted within the container, allowing data to be shared between the host machine and the container. The paths before the colon represent the files/directories on the host machine, while the paths after the colon represent the corresponding locations within the container. +* **restart: "always":** Specifies that the container should always be restarted if it stops or crashes. +* **env\_file: .env:** Specifies an environment file (".env") that contains environment variables to be set within the container. +* **ports:** Defines the port mappings between the host machine and the container. +* **"30303:30303":** Maps port 30303 on the host machine to port 30303 within the container. This port is used for RLPx(TCP)/UDP peer-to-peer communications allowing node discovery and connection to peers. +* **"8989:8545":** Maps port 8989 on the host machine to port 8545 within the container. This port is used for the HTTP JSON-RPC API. +* **"8888:8546":** Maps port 8888 on the host machine to port 8546 within the container. This port is used for the Websocket-RPC interface. + +*** diff --git a/run-a-node/rpc.md b/run-a-node/rpc.md new file mode 100644 index 00000000..7ab7b902 --- /dev/null +++ b/run-a-node/rpc.md @@ -0,0 +1,103 @@ +--- +description: How to deploy a full-node RPC +--- + +# RPC + +A Remote Procedure Call (RPC) allows programs that run on one device, or network, to execute functions and procedures on another. The primary purpose of an RPC is to enable communication and cooperation between distributed components of a system, allowing developers to create applications that leverage the functionality of remote devices or services. To enable a software application to engage with the XDC blockchain, whether it involves accessing blockchain data, smart contract executions, interacting with the network, or executing transactions, it needs to establish a connection with an XDC node. These RPC nodes are deployed on the network, however, they do not participate in validation or consensus. + +JSON-RPC is a streamlined and efficient remote procedure call (RPC) protocol that operates without maintaining a state. It outlines various data structures and their corresponding processing rules. This protocol remains adaptable to different transport mechanisms, such as within the same process, over sockets, over HTTP, or across various message-passing environments. + +## How to deploy RPC + +**Requirements and prerequisites:** + +* A server or cloud instance with at least 16 GB of RAM and 512 GB of storage. +* Ubuntu 22.04 LTS or higher operating system (Recommended) +* Basic knowledge of the Linux command line. + +**Step 1:** Setting up the full node with docker\ +\ +_Clone repository_ + +``` +git clone https://github.com/XinFinOrg/XinFin-Node.git +``` + +_Enter XinFin-Node directory_ + +``` +cd XinFin-Node +``` + +_Install docker & docker-compose_ + +``` +sudo ./setup/install_docker.sh +``` + +Update the .env file with details: + +* Create a .env file by using the sample — .env.example +* Enter either your company or product name in the INSTANCE\_NAME field. +* Enter your email address in the CONTACT\_DETAILS field. + +``` +cd mainnet +cp env.example .env +nano .env +``` + +_Start your Node_ + +``` +cd mainnet +sudo docker-compose -f docker-compose.yml up -d +``` + +_To stop the node, or if you encounter, any issues use_ + +``` +sudo docker-compose -f docker-compose.yml down +``` + +_Attach XDC Console:_ + +``` +cd mainnet +sudo bash xdc-attach.sh +``` + +You can check the status of your full node on the stats page at + +* [https://stats.xdc.org](https://stats.xdc.org) +* [https://stats1.xinfin.network](https://stats1.xinfin.network/) + +If you want your full node to sync faster, you can download the latest Mainet snapshot from: + +* [https://download.xinfin.network/xdcchain.tar](https://download.xinfin.network/xdcchain.tar) + +_**Follow the below steps to unpack and restore the snapshot. This will synchronize the node faster since there will very less blocks to catchup on:**_ + +1. sudo docker-compose -f docker-compose.yml down +2. wget [https://download.xinfin.network/xdcchain.tar](https://download.xinfin.network/xdcchain.tar) +3. tar -xvzf xdcchain.tar +4. rm -rf xdcchain/XDC +5. mv XDC xdcchain/XDC +6. sudo docker-compose -f docker-compose.yml up -d + +After downloading the snapshot, monitor your node on the stats page mentioned above. Once your node is fully synced, you can start using the dedicated RPC. + +To access RPC on your newly configured node use the below format: + + http://_x.x.x.x:8989_, where **x.x.x.x** is your public or private IP address for the node. + +Similarly you can access the webSockets on your newly configured node by using the below sample URL: + +wss://x.x.x.x:8888, where **x.x.x.x** is your public or private IP address for the node. + +### XDC and 0x prefix + +The XDC Network uses an XDC prefix instead of the 0x prefix used by some EVM-compatible networks, however, 0x can still be used when interacting with the network by using an XDC and 0x compatible RPC. The 0x prefix is not enabled by default and needs to be enabled manually by editing and updating startnode.sh file and passing a flag. + +To enable the 0x prefix RPC Endpoint, you can add the flag “— enable-0x-prefix” to your “startnode.sh” script. This will allow the RPC Endpoint to recognize and process 0x-prefixed diff --git a/tools/README.md b/tools/README.md index b410c0f5..af03862a 100644 --- a/tools/README.md +++ b/tools/README.md @@ -1,2 +1,11 @@ +--- +description: XDC network SDKs, programming languages Frameworks, & Network Tools +--- + # Tools +The XDC network's EVM compatibility allows developers to conveniently use tools they're familiar with, making their contributions and building experience on the XDC Network easier. Complimenting that are a set of SDKs,APIS, deployment and test frameworks. Finally, products created to help monitor the network such as explorer and network stats are available with white papers needed to effectively build on the network. + +As new tools and active developer communities are built, more can be added. + + diff --git a/tools/apis-and-packages/xdc-rpcs.md b/tools/apis-and-packages/xdc-rpcs.md index ee48e3fb..c7593cba 100644 --- a/tools/apis-and-packages/xdc-rpcs.md +++ b/tools/apis-and-packages/xdc-rpcs.md @@ -4,7 +4,7 @@ {% tab title="XDC MainNet" %} | Archival Node | Full Node | Web Socket | | :----------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------: | -| [https://arpc.apothem.network](https://arpc.apothem.network) |

https://rpc.xinfin.network
OR
https://erpc.xinfin.network

| [wss://ws.xinfin.network](wss://ws.xinfin.network/) | +| [https://arpc.xinfin.network](https://arpc.xinfin.network) |

Public RPCs :

  1. https://rpc.xinfin.network
  2. https://erpc.xinfin.network
  3. https://rpc.xdc.org

Premium RPCs :

  1. https://rpc.ankr.com/xdc

| [wss://ws.xinfin.network](wss://ws.xinfin.network/) | {% endtab %} @@ -12,6 +12,6 @@ {% tab title="XDC Apothem TestNet" %} | Archival Node | Full Node | Web Socket | | :--------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------: | -| [https://arpc.xinfin.network](https://arpc.xinfin.network) |

https://ws.apothem.network
OR https://rpc.apothem.network

| [wss://ws.apothem.network/ws](wss://ws.apothem.network/ws) | +| [https://arpc.apothem.network](https://arpc.apothem.network) |

https://ws.apothem.network
OR https://rpc.apothem.network

| [wss://ws.apothem.network/ws](wss://ws.apothem.network/ws) | {% endtab %} {% endtabs %} diff --git a/tools/apis-and-packages/xdpos2.0-apis.md b/tools/apis-and-packages/xdpos2.0-apis.md new file mode 100644 index 00000000..960075b8 --- /dev/null +++ b/tools/apis-and-packages/xdpos2.0-apis.md @@ -0,0 +1,216 @@ +# XDPoS 2.0 API + +- [Get V2 Block By Number](#xdpos_getv2blockbynumber) +- [Get V2 Block By Hash](#xdpos_getv2blockbyhash) +- [Get Masternodes By Number](#xdpos_getmasternodesbynumber) +- [Get Latest Pool Status](#xdpos_getlatestpoolstatus) + + +Provide `curl` command as exmaple + +## XDPoS_getV2BlockByNumber + +Parameter can be `number` or reserved words like `latest`, `committed` + +Example 1: By latest block +``` +curl --location 'https://xdc.rpc.node' \ +--header 'Content-Type: application/json' \ +--data '{"jsonrpc":"2.0","method":"XDPoS_getV2BlockByNumber","params":["latest"],"id":1}' +``` + +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "Hash": "0x6867eadf2bb4ecabd020f00f178664144090d08575bc73037d5fa1846c2362a5", + "Round": 597698, + "Number": 597682, + "ParentHash": "0xd3db9d9620c6e99992072cf22b91a4dd666e20891e61fa2064b902f6687c5373", + "Committed": false, + "EncodedRLP": "xxx", + "Error": "" + } +} +``` + +Example 2: By latest committed block + +``` +curl --location 'https://devnetstats.apothem.network/subnet' \ +--header 'Content-Type: application/json' \ +--data '{"jsonrpc":"2.0","method":"XDPoS_getV2BlockByNumber","params":["committed"],"id":1}' +``` + +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "Hash": "0x3e906c03503a17c55a2fcc8553e8b08b8c591586152a3df8043af3c235a6612c", + "Round": 598787, + "Number": 598771, + "ParentHash": "0x05f05c393e08743bd0979cf1cf3125e81b6c14422055cb9b4a802b2ee8f50ad9", + "Committed": true, + "EncodedRLP": "xxx", + "Error": "" + } +} +``` + + +Example 3: By number + +Note: You need to convert block number into **Hexadecimal** +``` +curl --location 'https://xdc.rpc.node' \ +--header 'Content-Type: application/json' \ +--data '{"jsonrpc":"2.0","method":"XDPoS_getV2BlockByNumber","params":["0x91EB2"],"id":1}' +``` + +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "Hash": "0x6867eadf2bb4ecabd020f00f178664144090d08575bc73037d5fa1846c2362a5", + "Round": 597698, + "Number": 597682, + "ParentHash": "0xd3db9d9620c6e99992072cf22b91a4dd666e20891e61fa2064b902f6687c5373", + "Committed": true, + "EncodedRLP": "xxx", + "Error": "" + } +} +``` + +## XDPoS_getV2BlockByHash + +Parameter is `Block Hash` + +Example: +``` +curl --location 'https://xdc.rpc.node' \ +--header 'Content-Type: application/json' \ +--data '{"jsonrpc":"2.0","method":"XDPoS_getV2BlockByHash","params":["0x6867eadf2bb4ecabd020f00f178664144090d08575bc73037d5fa1846c2362a5"],"id":1}' +``` + +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "Hash": "0x6867eadf2bb4ecabd020f00f178664144090d08575bc73037d5fa1846c2362a5", + "Round": 597698, + "Number": 597682, + "ParentHash": "0xd3db9d9620c6e99992072cf22b91a4dd666e20891e61fa2064b902f6687c5373", + "Committed": true, + "EncodedRLP": "xxx", + "Error": "" + } +} +``` + +## XDPoS_getMasternodesByNumber + +This API is mainly for debugging propose and check masternode selection process is fine. Get the current masternode or query by number. + +Parameter: `none` or `Block Number` + +Example 1: latest selection +``` +curl --location 'https://xdc.rpc.node' \ +--header 'Content-Type: application/json' \ +--data '{"jsonrpc":"2.0","method":"XDPoS_getMasternodesByNumber","params":[],"id":1}' +``` + +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "Number": 598597, + "Round": 598613, + "MasternodesLen": 3, + "Masternodes": [ + "xdcefea93e384a6ccaaf28e33790a2d1b2625bf964d", + "xdc888c073313b36cf03cf1f739f39443551ff12bbe", + "xdc5058dfe24ef6b537b5bc47116a45f0428da182fa" + ], + "PenaltyLen": 0, + "Penalty": [], + "Error": null + } +} +``` + +Example 2: By Block Number + +``` +curl --location 'https://xdc.rpc.node' \ +--header 'Content-Type: application/json' \ +--data '{"jsonrpc":"2.0","method":"XDPoS_getMasternodesByNumber","params":["0x91EB2"],"id":1}' +``` + +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "Number": 597682, + "Round": 597698, + "MasternodesLen": 3, + "Masternodes": [ + "xdcefea93e384a6ccaaf28e33790a2d1b2625bf964d", + "xdc888c073313b36cf03cf1f739f39443551ff12bbe", + "xdc5058dfe24ef6b537b5bc47116a45f0428da182fa" + ], + "PenaltyLen": 0, + "Penalty": [], + "Error": null + } +} +``` + +## XDPoS_getLatestPoolStatus + +This API is for mainly for debugging purpose, it will show current voting and timeout pool status. Any good for if block gets stuck and we can check which signer it is waiting for. Fast ping point which master node is having issue. + +``` +curl --location 'https://xdc.rpc.node' \ +--header 'Content-Type: application/json' \ +--data '{"jsonrpc":"2.0","method":"XDPoS_getLatestPoolStatus","params":[],"id":1}' +``` + +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "timeout": {}, + "vote": { + "598031:596250:598015:0x8784d1fbb9b4e9718b2ccad3e14a2148b79a534494c7be60c20857f04b5a6374": { // CurrentRound:GapBlockNumber:ProposedBlockNumber:ProposedBlockHash + "CurrentNumber": 3, + "CurrentSigners": [ + "xdc5058dfe24ef6b537b5bc47116a45f0428da182fa", + "xdcefea93e384a6ccaaf28e33790a2d1b2625bf964d", + "xdc888c073313b36cf03cf1f739f39443551ff12bbe" + ], + "MissingSigners": [] + }, + "598049:596250:598033:0xe50ea51a36a391b2e453e34ec10b7f86ebb459d621240c05efe53bb0cfca148f": { + "CurrentNumber": 2, + "CurrentSigners": [ + "xdc5058dfe24ef6b537b5bc47116a45f0428da182fa", + "xdc888c073313b36cf03cf1f739f39443551ff12bbe" + ], + "MissingSigners": [ + "xdcefea93e384a6ccaaf28e33790a2d1b2625bf964d" + ] + } + } + } +} +``` + diff --git a/tools/sdks-and-programming/README.md b/tools/sdks-and-programming/README.md index 5d0063c4..7969cc9e 100644 --- a/tools/sdks-and-programming/README.md +++ b/tools/sdks-and-programming/README.md @@ -1,2 +1,4 @@ # SDKs & Programming +The XDC network is compatable with a wide assortment of differnt programing languages used to help build applications on a multitude of different platforms. These SDKs interact directly with the XDC network allowing developers to have an interactive experience with their applications and tokens created on-chain. + diff --git a/tools/sdks-and-programming/javascript.md b/tools/sdks-and-programming/javascript.md index 976d85db..4f463b7a 100644 --- a/tools/sdks-and-programming/javascript.md +++ b/tools/sdks-and-programming/javascript.md @@ -131,7 +131,7 @@ Returns the symbol of the token, usually a shorter version of the name. Gets the total amount of tokens stored by the contract. `balanceOf(address account) → uint256`\ -Returns the number of NFTs in the owner's **** account. +Returns the number of NFTs in the owner's account. `ownerOf(tokenId) → address`\ Returns the owner of the NFT specified by `tokenId`. @@ -212,7 +212,7 @@ To add module dependency in your project, follow the steps below: Now, we can interact with the XRC721 read methods. * `name() → string` Returns the name of the token.\ - ****`tokenResponse.getName();` + `tokenResponse.getName();` * `balanceOf(address token,address account) → uint256` Returns the number of tokens owned by `account`.\ `String balance = XDC721Client.getInstance().getBalance(tokenAddress, ownerAddress);` diff --git a/tools/sdks-and-programming/php-sdk.md b/tools/sdks-and-programming/php-sdk.md index 7e32087c..0266c029 100644 --- a/tools/sdks-and-programming/php-sdk.md +++ b/tools/sdks-and-programming/php-sdk.md @@ -141,7 +141,7 @@ This library provides a simple way to interact with XDC XRC20 & XRC721 tokens. XRC721 is the token standard for non-fungible tokens. These are unique tokens that hold different values than other tokens in the same smart contract. All NFTs have a uint256 variable called tokenId, so for any XRC-721 Contract, the pair contract address, uint256 tokenId must be globally unique. -Every XRC-721 compliant contract must implement the **** `XRC721` and `XRC165` interfaces. +Every XRC-721 compliant contract must implement the `XRC721` and `XRC165` interfaces. ### Read Methods @@ -155,7 +155,7 @@ Provides the name of the token. Returns the total amount of tokens in the contract. `balanceOf(address account) → uint256`\ -Provides the number of non-fungible tokens in the owner's **** account. +Provides the number of non-fungible tokens in the owner's account. `ownerOf(tokenId) → address`\ Returns the NFT owner specified by `tokenId`. diff --git a/tools/sdks-and-programming/python.md b/tools/sdks-and-programming/python.md index 2ad3d8ac..63befb04 100644 --- a/tools/sdks-and-programming/python.md +++ b/tools/sdks-and-programming/python.md @@ -1,2 +1,70 @@ -# Python +# Python SDK + + +XDC3PYTHON SDK with support for smart contracts, XDC20 & XRC721. + + + +### Usage + +**pip install XDC3PYTHON** + +#### This SDK supports following Read & Write operations:- + +* xrc20 methods. + * Read methods. + * name(), balanceOf(account), totalSupply(), symbol(), decimals(), allowance(pwner, spender). + * Write methods. + * transferXDC(owner,receiver), approve(spender,amount), transferToken(receiver,amount), increaseAllowance(spender, addedValue), decreaseAllowance(spender, subtractedValue), transferFrom(sender, receiver, amount). +* xrc721 methods. + * Read methods. + * name(), symbol(), totalsupply(), balanceOf(ownerAddr), ownerOf(tokenId), tokenURI(tokenId), tokenByIndex(index), tokenOfOwnerByIndex(ownerAddress,index), supportInterface(interfaceId), getApproved(tokenId), isApprovedForAll(ownerAddress,spenderAddress). + * Write methods. + * setApprovalForAll(spenderAddress, booleanValue), approve(sepnderAddress , tokenId), transferFrom(recipient, tokenId), safeTransferFrom(spender, tokenId). + +#### Example for XRC20. + +``` +from XDC3PYTHON.xrc20 import XRC20 + +if __name__=="__main__": + + NETWORK_URL = "Your endpoint Url" + + obj = XRC20(NETWORK_URL) + + tokenAddr = input('Enter Token Address: ') + + tokenSymbol = obj.name(tokenAddr) + print(tokenSymbol) +``` + +This example returns name of the specified address. + +#### Example for XRC721. + +``` +from XDC3PYTHON.xrc721 import XRC721 + +if __name__=="__main__": + + NETWORK_URL = "Your endpoint Url" + + obj = XRC721(NETWORK_URL) + + tokenAddr = input('Enter Token Address: ') + + tokenSymbol = obj.name(tokenAddr) + print(tokenSymbol) +``` + +This example returns symbol of the specified address. + +## Transports + +**HTTP transport** + +### Required Data Types + +**Token Address** - `str type` **Account Address** - `str type` **amount** & **tokenId** - `int type` diff --git a/tools/sdks-and-programming/soliditiy.md b/tools/sdks-and-programming/soliditiy.md index 797e0803..e46e2e96 100644 --- a/tools/sdks-and-programming/soliditiy.md +++ b/tools/sdks-and-programming/soliditiy.md @@ -1,2 +1,13 @@ +--- +description: >- + Solidity is the most adopted programing language for smart contract + developers and is used for all EVM compatible platforms. +--- + # Solidity +Solidity is a programming language used for writing smart contracts on the Ethereum blockchain. It is a high-level language similar to JavaScript and is designed to be easy to learn and use. Solidity supports inheritance, libraries, and complex user-defined types, making it suitable for developing complex decentralized applications. + +Solidity is used to write the smart contracts that power decentralized applications (dapps) on the Ethereum blockchain. These contracts define the rules and logic of the application, such as how tokens are distributed, how users can interact with the application, and how data is stored and managed. + +Developers use Solidity to write the code for these contracts, which are then compiled into bytecode and deployed to the XDC network on any other EVM compatible network. Once deployed, the contracts can be interacted with by users and other contracts on the blockchain, enabling the decentralized functionality of the dapp. diff --git a/tools/sdks-and-programming/switft.md b/tools/sdks-and-programming/switft.md index 83cd2b25..b98e3d9d 100644 --- a/tools/sdks-and-programming/switft.md +++ b/tools/sdks-and-programming/switft.md @@ -206,7 +206,7 @@ Returns the symbol of the token, usually a shorter version of the name. Gets the total amount of tokens stored by the contract. `balanceOf(address account) → uint256`\ -Returns the number of NFTs in the owner's **** account. +Returns the number of NFTs in the owner's account. `ownerOf(tokenId) → address`\ Returns the owner of the NFT specified by `tokenId`. @@ -255,7 +255,7 @@ Approves another address to transfer the given token ID. The zero address indica /// @param \_owner An address for whom to query the balance -/// @return The number of NFTs owned by `_owner`, possibly zero function **** balanceOf(address \_owner) external view returns (uint256); +/// @return The number of NFTs owned by `_owner`, possibly zero function balanceOf(address \_owner) external view returns (uint256); /// @notice Find the owner of an NFT @@ -433,7 +433,7 @@ interface XRC165 { self.xrc721Enumerable = XRC721Enumerable(client: client) ``` -* To call **** the `name` of the token +* To call the `name` of the token ``` xrc721Metadata.name(contract: address) { (error, name) in print(name) } diff --git a/tools/sdks-and-programming/vyper.md b/tools/sdks-and-programming/vyper.md new file mode 100644 index 00000000..5644c6a7 --- /dev/null +++ b/tools/sdks-and-programming/vyper.md @@ -0,0 +1,47 @@ +--- +description: >- + Vyper is an EVM smart contracts programming language that is based on Python + and used as an alternative to Solidity. +--- + +# Vyper + +Vyper is a programming language used for deploying Ethereum Virtual Machine (EVM) smart contracts. As an alternative to the EVM programming language, Solidity, Vyper inherits many similarities to Python in syntax and structure. A few of its key principles and goals are increased security, language and compiler simplicity, and audibility. While it does have these principles, it also lacks certain features such as inheritance and modifiers. + +\ +As the second most used smart contract language for EVM, it does not have the level of developer community and contributors when compared to solidity. It does, however, make it easier for Python developers to start building and deploying EVM smart contracts. Vyper was not intended to be a replacement for solidity but to act as another tool for developers to use. These languages have key differences for smart contract deployment, which can be used for different uses and applications, but it mainly comes down to the developer's preference. + +### Principles and Goals + +Security: It should be possible and natural to build secure smart contracts in Vyper. + +Language and compiler simplicity: The language and the compiler implementation should strive to be simple. + +Auditability: Vyper code should be maximally human-readable. Furthermore, it should be maximally difficult to write misleading code. Simplicity for the reader is more important than simplicity for the writer, and simplicity for readers with low prior experience with Vyper (and low prior experience with programming in general) is particularly important. + +### Features + +As a Python-based alternative to Solidity, it does have key differences and features. These are just some of the differences for Vyper. More details and information can be found in the resources below. + +Support for signed integers and decimal fixed point numbers + +Decidability: It is possible to compute a precise upper bound for the gas consumption of any Vyper function call. + +Strong typing + +Small and understandable compiler code + +Limited support for pure functions: Anything marked constant is not allowed to change the state. + +#### + +#### Vyper Resources + +[https://docs.vyperlang.org/en/stable/ \ + \ +https://reference.auditless.com/cheatsheet/ \ +](https://docs.vyperlang.org/en/stable/https://reference.auditless.com/cheatsheet/)\ + + +\ +\