DEV Community

Axat Bhardwaj
Axat Bhardwaj

Posted on • Updated on

Tron Private network setup (Complete guide 2022)

Tron network setup

Prereq

Have necessary pre req installs

I have used Ubuntu as my host OS

sudo apt-get -y install apt-transport-https ca-certificates
sudo apt-get install -y build-essential checkinstall libssl-dev

mkdir ~/nftron
cd ~/nftron

Enter fullscreen mode Exit fullscreen mode

copy paste in the current shell

echo 'JDK_MD5="0029351f7a946f6c05b582100c7d45b7"
JDK_DIR="jdk1.8.0_202"
JDK_TAR="jdk-8u202-linux-x64.tar.gz"
JAVA_HOME=/usr/local/$JDK_DIR
CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME=/usr/local/$JDK_DIR' > .envs

source .envs

Enter fullscreen mode Exit fullscreen mode

Lets install Java

sudo wget -P /usr/local <https://github.com/frekele/oracle-java/releases/download/8u202-b08/$JDK_TAR>

echo "Ensure you have "OK" status for chksum"

sudo echo "$JDK_MD5 /usr/local/$JDK_TAR" | md5sum -c
sudo tar -zxf /usr/local/$JDK_TAR -C /usr/local

Enter fullscreen mode Exit fullscreen mode

We will move with three tron repos for now,
1, Tron private network Deployment -
git clone <https://github.com/tronprotocol/java-tron.git>

2, Tron wallet address creation
git clone <https://github.com/tronprotocol/wallet-cli.git>

3, Tronbox for compiler & smart contract deployment , equalent to truffle

git clone <https://github.com/tronprotocol/tronbox.git>

or
you can use npm install -g tronbox

Enter fullscreen mode Exit fullscreen mode

1. Now you have set all prerequisites, we will build tron network now

echo  "Building the  Source code "

cd ~/nftron/java-tron
./gradlew build

mkdir srnode
cd srnode
cp ~/nftron/java-tron/build/libs/FullNode.jar .
cp ~/nftron/java-tron/build/libs/SolidityNode.jar .
cp ~/nftron/java-tron/framework/build/resources/main/config.conf .

Enter fullscreen mode Exit fullscreen mode

Lets start the node

java -jar ./FullNode.jar --witness -c ../config.conf

Enter fullscreen mode Exit fullscreen mode

To start Solidity node (optional)

java -jar ./FullNode.jar  -c ../config.conf

Enter fullscreen mode Exit fullscreen mode

2. Now lets start wallet -cli

Clone the repo from above link

cd ~/nftron/wallet-cli
cp src/main/resources/config.conf ~/nftron/wallet-cli/

#Modify the config.conf in src/main/resources with the fullnode/solidity details.
ie. port number or ip address if its different ec2 instance.

./gradlew build

Enter fullscreen mode Exit fullscreen mode

now you can run the wallet

java -jar build/libs/wallet-cli.jar

Enter fullscreen mode Exit fullscreen mode

1, Register wallet

registerwallet user1
(input your complex password)

2, login with register user

login user1

3, generate the account for tests

generateaddress

{
"address": "27abQWJo3mc2b6kRY8Dng8ZzE7GWGpNgFpF",
"privateKey": "f70c5503e6f7e83a76f12373ddb478bfd04f10b4f78de5046a7dc75532f84c81"
}

3. Now lets do with Tronbox for solidity code deployment on the private network

You can clone the repo or use npm commands to install

npm install  -g tronbox
mkdir samplecode
cd samplecode
tronbox init

Enter fullscreen mode Exit fullscreen mode

Note : Edit the tronbox.js file and update the fullnode ip address and port and private key in developement
tronbox.js

Use the below solidity sample contracts, just copy paste in the current shell

echo 'pragma solidity >=0.4.23 <0.9.0;
contract Test{
function f() public pure returns (string memory){
return "method f()";
}
function g() public pure returns (string memory){
return "method g()";
}
}' > samplecode/contracts/Test.sol

Enter fullscreen mode Exit fullscreen mode
echo 'var Test = artifacts.require("./Test.sol");
var Migrations = artifacts.require("./Migrations.sol");

module.exports = function(deployer) {

deployer.deploy(Test);
deployer.deploy(Migrations);
}; '  > samplecode/migrations/2_deploy_contracts.js

Enter fullscreen mode Exit fullscreen mode

Lets compile and migrate

tronbox compile
tronbox migrate --network development

Enter fullscreen mode Exit fullscreen mode

Cheers !!
Axat Bhardwaj
Blockchain Developer & Technologist
https://www.linkedin.com/in/axatbhardwaj

Top comments (0)