*UPDATE, RAN OUT OF TIME. WILL SORT IMAGES IN A FEW HOURS!!*
This guide will take you through building and running a headless x42 Full Node! The OS I am using here is Ubuntu 18.04, this guide picks up from a complete/fresh ubuntu install.
This is meant to setup a staking node and so this guide will run you through building, configuring and setting up staking. It will not cover sending transactions or anything else.
The things we are going to do:
- Install .net core
- download the x42 node source & compile it
- Setting the x42 node up to run on boot
- setup a new wallet
- configure the x42 daemon
- Get Address
- Check Balance
Install .net Core
Here is the reference link:
https://dotnet.microsoft.com/download/linux-package-manager/ubuntu18-04/sdk-current
Register Microsoft Key’s & Install Their repos:
cd /tmp wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb sudo add-apt-repository universe sudo apt -y install apt-transport-https sudo apt update sudo apt -y install dotnet-sdk-2.2
Microsoft collect telemetry data by default, if you are part of the “tin foil hat brigade” you can set the following environment variable to turn it off:
echo "DOTNET_CLI_TELEMETRY_OPTOUT=1" >> /etc/environment
now you should be at a point where .net core is installed on your system… that wasn’t so hard was it! You can check by running the following command:
dotnet--list-sdks
The output should look like this:
$ dotnet --list-sdks 2.2.103 [/usr/share/dotnet/sdk]
Download & compile the x42 node
This part assumes you have GIT installed, if not:
apt -y install git
Now to pull down the source and compile it!
cd ~/ git clone https://github.com/x42protocol/X42-FullNode.git # “cd” into the source folder cd X42-FullNode/src/
Now .net core uses NuGet for package management, before we compile, we need to pull down all of the required packages.. its as simple as running (this will take a couple of minutes) inside of “X42-FullNode/src/”:
dotnet restore
now we are ready to compile the source, execute (inside of “X42-FullNode/src/”):
dotnet build --configuration Release
ignore the yellow warnings, this is just the rosyln compiler having a grumble.. if you get red ones then something went wrong! The “--configuration Release” will strip out all debug symbols and slim things down.. only a little, this optional parameter is not mandatory.
Once this is done everything is built/compiled, you can run the daemon directly from the repository, this can be done by going to:
cd ~/X42-FullNode/src/x42.x42D/bin/Release/netcoreapp2.1 dotnet x42.x42D.dll
this will kick off the node, however if you exit SSH at this time it will kill the process! however I always recommend copying out the binaries to a separate folder. This can be done with the following:
mkdir ~/x42node mv ~/X42-FullNode/src/x42.x42D/bin/Release/netcoreapp2.1/*.* ~/x42node/
now we have everything we need to run the node outside the git repository! What we need to do now is run the node and have it create the default x42.conf file.. so
cd ~/x42node dotnet x42.x42D.dll
feel free to hit “CTRL + C” to exit the application after a couple of seconds, by then the folders/files would have been created at the following path:
~/.x42node/x42/x42Main/
Setting the x42 node up to run on boot
Now we are going to create a service file so our x42 node automatically starts when the system is rebooted.
THINGS TO NOTE ABOUT BELOW.. CHANGE THE ##USER## to the username your currently using as these files are within your home directory!
We need to drop to root for this..
sudo -i cat <<EOF > /etc/systemd/system/x42node.service [Unit] Description=x42 Node [Service] WorkingDirectory= /home/##USER##/x42node ExecStart=/usr/bin/dotnet /home/##USER##/x42node/x42.x42D.dll Restart=always # Restart service after 10 seconds if the dotnet service crashes: RestartSec=10 SyslogIdentifier=x42node User=##USER## Environment=ASPNETCORE_ENVIRONMENT=Development [Install] WantedBy=multi-user.target EOF
To enable the service, run the following (as the root user):
systemctl enable x42node.service
BOOM.. the node isn’t running yet.. but next time the system restarts it will automatically run!
now lets exit out of root!
exit
We can now start the node up and begin downloading blocks, by running the following command:
sudo systemctl start x42node.service
if you want to check its loaded and see some of the output, you can run:
sudo systemctl status x42node.service
an example of the output:
$ sudo systemctl status x42node.service ● x42node.service - x42 Node Loaded: loaded (/etc/systemd/system/x42node.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2019-01-24 15:47:55 UTC; 14s ago Main PID: 5456 (dotnet) Tasks: 23 (limit: 1112) CGroup: /system.slice/x42node.service └─5456 /usr/bin/dotnet /home/darthnoodle/x42node/x42.x42D.dll Jan 24 15:48:09 x42staking x42node[5456]: Batch Size: 0 Mb (0 headers) Jan 24 15:48:09 x42staking x42node[5456]: Cache Size: 0/50 MB Jan 24 15:48:09 x42staking x42node[5456]: Jan 24 15:48:09 x42staking x42node[5456]: =======Mempool======= Jan 24 15:48:09 x42staking x42node[5456]: MempoolSize: 0 DynamicSize: 0 kb OrphanSize: 0 Jan 24 15:48:09 x42staking x42node[5456]: Jan 24 15:48:09 x42staking x42node[5456]: info: Stratis.Bitcoin.Connection.ConnectionManagerBehavior[0] Jan 24 15:48:09 x42staking x42node[5456]: Peer '[::ffff:86.184.76.255]:52342' connected (outbound), agent 'x42:1.2.13 (70012)', height 213920 Jan 24 15:48:09 x42staking x42node[5456]: info: Stratis.Bitcoin.Connection.ConnectionManagerBehavior[0] Jan 24 15:48:09 x42staking x42node[5456]: Peer '[::ffff:86.184.76.255]:52342' offline, reason: 'Receiving cancelled.'. All node screen output can be found in the /var/log/syslog file.
Setup a New Wallet
With the Node running, we now need to setup and/or restore a wallet!
Everything will be performed through the API’s, however by default these API’s are listening on localhost (127.0.0.1), if you are connecting in remotely then this would be a problem since you cant hit that IP. The solution, SSH TUNNEL!
Execute the following command on your local system:
ssh -L 42220:localhost:42220 <user>@<remotehost>
This binds the local port (on your system) with 127.0.0.1:42220 on the remote system, once you have executed the command you can type the following address in your laptop/desktop’s web browser and be able to access the API’s:
http://127.0.0.1:1337/swagger/index.html
It should look something like this:
📷
To Create a new wallet, first we have to generate some mnemonic works (e.g. the seed), you can do that by going to the following API:
/api/Wallet/mnemonic
Hit the “Try it out” button which then prompts you for 2 fields:
📷
Enter “English” and I would recommend 24 words as this greatly increases the seed strength! Once that is done you hit execute and then scroll down to see the “Response Body”, this should contain the mnemonic which you are going to use to create the wallet! This looks something like below:
📷
THIS IS VERY IMPORTANT, BACKUP THIS MNEMONIC TO A SAFE SECURE LOCATION THAT IS ENCRYPTED!!!
So now we have our nemonic, its time to generate the wallet, for this we need to use the API:
/api/Wallet/create
There are a number of paramiters which are required in order to create a wallet:
WalletCreationRequest{ mnemonic string password* string passphrase* string name* string }
It should be noted that the password and mnemonic are is the most important parts of this request where the “password” will encrypt the wallet and Is required to unlock it.
- Hit the “Try it out” button
- input the nessesary data
- Insert the nmumonic
- Put a password & passphrase
- “Name” is what your wallet will be called
It should look something like the following:
📷
Hit “Execute”, the “Loading” sign may spin for a few minutes while the wallet is created… once the wallet has been created the “Response Body” will return the mnemonic you have just used.. we now have a wallet!!
HOWEVER IT IS NOT LOADED INTO THE NODE JUST YET!
This is where we will now jump back out and to configure the node to automatically load the wallet and automatically start staking when it first loads.
AGAIN BACKUP YOUR NMEMONIC AND PASSWORD, MAKE SURE THEY ARE ENCRYPTED AND STORED SOMEWHERE SAFE!
Configure the x42 Daemon
Now we are going to modify the x42.conf file in order to automatically load our wallet and start staking 😊
First things first, lets stop our node by running the following command:
sudo systemctl stop x42node.service
CD to the following folder and view its contents:
~/.x42node/x42/x42Main ls -lah
within that folder there should be 2 files you are interested in:
-rw-r--r-- 1 darthnoodle darthnoodle 18K Jan 28 16:01 TestWallet.wallet.json -rw-rw-r-- 1 darthnoodle darthnoodle 3.1K Jan 24 15:25 x42.conf
So TestWallet.wallet.json is our physical wallet that will be loaded, but for right now we want to modify the x42.conf file.. fire up your favorite text editor (if you use VI you’re a masochist)..
nano x42.conf
The area we are interested in is the following:
####Miner Settings#### #Enable POW mining. #mine=0 #Enable POS. #stake=0 #The address to use for mining (empty string to select an address from the wallet). #mineaddress=<string> #The wallet name to use when staking. #walletname=<string> #Password to unlock the wallet. #walletpassword=<string> #Maximum block size (in bytes) for the miner to generate. #blockmaxsize=1000000 #Maximum block weight (in weight units) for the miner to generate. #blockmaxweight=1000000 #Enable splitting coins when staking. #enablecoinstakesplitting=1 #Minimum size of the coins considered for staking, in satoshis. #minimumstakingcoinvalue=10000000 #Targeted minimum value of staking coins after splitting, in satoshis. #minimumsplitcoinvalue=10000000000
Uncomment (remove the #) of the following lines and change their value:
stake=1 (changed to 1) walletname=TestWallet (changed to our Wallet Name) walletpassword=password123 (changed to the wallet password)
save the file and exit back to the command prompt, now we shall restart the node with the following command:
sudo systemctl status x42node.service
now the wallet is automatically loaded and ready for action!
YES I KNOW YOU HAVE PUT YOUR PASSWORD IN CLEARTEXT, THIS IS WHERE YOU SHOULD HARDEN YOUR BOX. IF THEY CAN GET TO THE POINT WHERE THEY CAN READ YOUR CONF FILE THEY CAN JUST GRAB YOUR WALLET AND BRUTEFORCE THE PASSWORD.
You can check its loaded by going back to the API and executing the following command:
/Dashboard
Or execute the following command on the NODE:
curl -X GET "http://127.0.0.1:42220/Dashboard" -H "accept: application/json"
both will produce the same output, if you scroll to the bottom you should see something like this:
======Wallets====== TestWallet/account 0, Confirmed balance: 0.00000000 Unconfirmed balance: 0.00000000
This means the wallet is loaded and ready for action!!
Get Addresses
Next thing you are probably going to want is a receive address and to check the balance and TX history.. so lets start with getting an address!
Go to the following API:
/api/Wallet/unusedaddress
Fill in the Wallet name which is “TestWallet” (in this example) and “account 0” (which is the first/default account):
📷
Hit execute and you should have an x42 address within the “Response Body”:
📷
BOOM… ok now we can send funds! 😊
Check TX History
Go to the API and the following call:
/api/Wallet/history
The 2 fields we are most concerned about are:
📷
Input the name of the wallet and account you want to view the history of, then hit execute. The other fields can be black. This will return a list of TX’s that the wallet has received:
This should look like the following:
📷
There is an easier way of doing this, that doesn’t require you to be connected to your node.. especially if your only interested in viewing your staking rewards… THE EXPLORER!
Access the following URL:
https://explorer.x42.tech/address/<PUT YOUR x42 ADDRESS HERE>
this will allow you to easily see all TX’s associated with this address, it should look something like below:
📷
… and your done! By this point your node should be running, staking and you have an easy way to view transactions/rewards 😊
Happy staking!
If you found this post helpful, then buy me a beer and send a donation to XQXeqrNFad2Uu7k3E9Dx5t4524fBsnEeSw
No comments:
Post a Comment