How to install Coin Magi wallet on your raspberry PI

in cryptocurrency •  last year

Before we begin:

I have tested the following solution with raspberry B+ / 3 and Raspberry Pi Zero W with Raspbian OS installed. It appeared to be very slow with Zero, each command took about a minute to process, so I wouldn’t recommend using it. This is also true for Raspberry pi B+ or the very first model. With raspberry PI 3 it was possible to set up miner for 3 out of the 4 cores alongside the wallet and it works like a charm. I didn’t bother installing QT wallet version as, in my opinion, this is too much with the PI resources.

So let’s get started.

1. Get your SD card flashed

Go to the official raspberry pi website and download image: https://www.raspberrypi.org/downloads/raspbian/
Go for the Raspbian Lite as you don’t really need desktop for this setup (At this moment it is 2017-09-07-raspbian-stretch-lite.img). Then follow the link below and follow the instructions provided there to flash your SD card: https://www.raspberrypi.org/documentation/installation/installing-images/README.md
Choose the version that is compatible with your OS.

2. Set up WiFi

If you want to keep your PI connected to the network by the cable you can skip this part.
Otherwise mount the card you just flashed.
Edit file etc/wpa_supplicant/etc/wpa_supplicant.conf
It should have something like:

country=GB
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

Add the following lines below:

network={
    ssid="YOUR_SSID"
    psk="YOUR_PASSWORD"
    key_mgmt=WPA-PSK
}

Replace YOUR_SSID and YOUR_PASSWORD with the ones for your network. And the last line corresponds to the security type of your box, usually WPA. Save this file.

3. Enable SSH

SSH is disabled by default. Mount the card you just flashed (you need boot disk) and create the empty file named ssh right in the root directory there. This is very important to keep no extension for this file, so it should be just `ssh` and nothing else.
Now it is time to boot your raspberry up. But before you do this you need to take care of one more detail. Right after Raspberry boots up, the new device will appear in the network, but in order to log in you need to know the IP address of the device. There are actually many techniques which vary depending on your OS.
If you’re a Linux user you can use something like this:

sudo nmap -sP 192.168.1.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}' 

You have to run it before powering up your PI and after so you can spot the IP address which just has appeared. You can also use your mobile phone (e.g. nmap scanner for android) or you can check your router’s admin panel and find it there.

4. Set up your PI

So I assume you already know the IP address of your device, so let’s log in there and do some necessary work.

ssh pi@192.168.55.55

(use IP address you have discovered, this is just example)

default login is pi and default password is raspberry
As soon as you’re in, update your system:

sudo apt update && sudo apt upgrade -y

It will take some time (10 minutes or so).
Then you need to configure Raspberry pi

sudo raspi-config

This will run Raspberry Pi Software Configuration Tool. Use arrows and tab for navigation, Enter for confirmation or cancellation.

  1. First of all change the default password to something a little bit more secure.
  2. Expand the filesystem: Go to advanced options and select first menu entry – Expand Filesystem
  3. Select your timezone and localisation: Go to Localisation options, then change your timezone and locale (if you need to of course)
  4. You may also want to update your hostname, so you will see the machine name when you log in, e.g. pi@xmgwallet:~$
  5. Finish and reboot

5. Prepare

In order to compile the wallet it is necessary to increase the swap otherwise it will fail during the compilation due to the lack of virtual memory.
Open swap config file:

sudo nano /etc/dphys-swapfile

change the line CONF_SWAPSIZE=100 to CONF_SWAPSIZE=2048
Save file (Use Ctrl + X followed by Y then Enter)
Apply changes:

sudo dphys-swapfile setup && sudo dphys-swapfile swapon

Now you can check that everything has been applied by running either of the following:

free -m

or just run top command

Install all required dependencies

sudo apt install -y git libdb-dev libboost-all-dev libminiupnpc-dev libgmp-dev libdb5.3++-dev

And here we have quite a interesting problem with dependencies. Magi won’t compile with the current libssl-dev which goes with `stretch`. We need to get an older version of the library which is actually not valid with the current OS version. Here is the solution:

  1. Remove current libssl-dev (1.1.0f-3) if you have it installed

sudo apt-get remove libssl-dev
sudo nano /etc/apt/sources.list
  1. Update your system to receive jessie packages list
sudo apt update
  1. Check that you have correct library version available:
    It should display something like this:
sudo apt-cache policy libssl-dev
libssl-dev:
  Installed: (none)
  Candidate: 1.0.1t-1+deb8u6
  Version table:
  1.0.1t-1+deb8u6 500
        500 http://mirrordirector.raspbian.org/raspbian jessie/main armhf Packages
  1. Install desired package
sudo apt install libssl-dev
  1. Point your repository back to stretch. Save file.
sudo nano /etc/apt/sources.list
  1. Lock package so it won’t be upgraded in the future
sudo apt-mark hold libssl-dev

6. Download and compile wallet

It is time to download the source code:

cd ~ && git clone https://github.com/magi-project/magi.git

I cloned the repo at the time of making this article, so if there are any changes in the source code you can use the fork with the code which works 100% for this article (https://github.com/gridcat/magi)
Now it is time to compile the wallet.
I highly recommend using the screen for this, otherwise you will need to keep your connection open all the time until it finishes compilation and according to your model it might take hours. With the screen you can create new session, run everything there, log out and just go back few hours later – your terminal will be in place.
You can also skip the screen installation – this isn’t a mandatory step, this is just for the convenience.

sudo apt install screen

Create new screen

screen

Press space or enter and you will end up in the terminal as before.

Check your architecture:

uname -a

Find armv6l or armv7l there and use the same in the make command down below.
For the raspberry pi 3 your’e going to have arm7l, for B+ it will be arm6l

cd ~/magi/src
make -f makefile.unix xCPUARCH=armv6l

You can add attribute -j{CORES_NUM} to the make command to get it faster, just change {CORES_NUM} to the number of cores your device have. I’ve tried to compile it for the Rpi3 tith -j4 and I got stuck at the certain moment. So I used -j3 (CORES_NUM – 1) and it worked just well.
Now you can relax and take care of your other duties.
If you’re using screen then click Ctrl + A then D, so you detach the screen. Next time when you login, you can just resume it by typing

screen -r

When creation is done just close screen using Ctrl + D combination.
As a result you have to have magid file in the src directory.
Let’s install binary file now

cd ~/magi/src
sudo install -m 755 magid /usr/bin/magid

7. Download blockchain

Now it is time to download blockchain. You can always skip this part but you will then need to wait again until it synchronises with the blockchain by itself. I would suggest to download it instead. It won’t be the full blockchain though, but it will allow you to save about 90% of the time.

cd ~
wget http://coinmagi.org/bin/block-chain/m-block-chain.tar.gz
mkdir ~/.magi
tar -xvf ./m-block-chain.tar.gz
mv ~/m-block-chain/* ~/.magi/
rm -rf ~/m-block-chain.tar.gz ~/m-block-chain

8. Configure wallet

Create config file in the wallet directory

touch ~/.magi/magi.conf

Open it using nano

nano ~/.magi/magi.conf

And put in there the following:

# You must set rpcuser and rpcpassword to secure the JSON-RPC api
rpcuser=magirpc
rpcpassword=7dhf8SRjR8R5P9icfqjjbqAZqysYXeQSuX539JhXseLz
# Listen for RPC connections on this TCP port:
rpcport=8232
# server=1 to accept JSON-RPC commands
server=1
# listen=1 to accept connections from outside
listen=1
# RPC connection from localhost allowed
rpcallowip=127.0.0.1
# Add nodes to connect to specific peers
addnode=104.128.225.215
addnode=45.35.251.73
# posii=1 to enable PoS staking; default = 0
posii=1
# Transaction under stake with a value greater than the threshold is being splitted
stakesplitthreshold=500
# Transactions with values less than the threshold will combine into one
stakecombinethreshold=500

9. Run headless daemon

At this point you can actually start the wallet in a daemon mode

magid -daemon

The initial run will take some time to synchronise the rest of the blockchain, it will create your wallet too.
If you check your wallet directory you will see wallet and logs file in the following place:

$ ls -l ~/.magi
blocks  database  db.log  debug.log  magi.conf  magid.pid

To check your wallet status type the following:

magid getinfo

The first time it will show you something like: error: couldn't connect to server
Don’t panic, just be patient: this is normal, client should synchronise the blockchain first, it will be in place in an hour or so, depends on you Pi model.

10. Set up a service

Things will go fine until the first reboot. The daemon won’t start by itself and you need to start it manually. Not very convenient is it? Let’s set up the service so it will start automatically after reboot.

Create service file

sudo touch /lib/systemd/system/magid.service

Create configuration. Open the file

sudo nano /lib/systemd/system/magid.service

Put this content there:

[Unit]
Description=Coin Magi daemon services
After=tlp-init.service

[Service]
PIDFile=/home/pi/.magi/magi.pid
RemainAfterExit=yes
ExecStart=/usr/bin/magid -daemon
Restart=on-failure
RestartSec=15
User=pi

[Install]
WantedBy=multi-user.target

Save the file

Enable autorun

sudo systemctl enable magid.service

Try to reboot, log in again

sudo reboot

And check the daemon status

systemctl status magid

And if you need to restart it

systemctl restart magid

Or in case if you don’t want to autorun it anymore for any reason

sudo systemctl disable magid

11. Encrypt and backup your wallet

As soon as you are up to date you should get something like this when you run the getinfo command

magid getinfo
{
    "version" : "v1.4.4.1",
    "protocolversion" : 71062,
    "walletversion" : 60000,
    ……….
    "balance" : 0.00000,
    "errors" : ""
}

This means your wallet is up and running. The good practice would be to encrypt your wallet, as the coins have a real value, you don’t want to be hacked. In order to do so type the following:

magid encryptwallet YOUR_PASSWORD

Then restart the service (or just reboot). It will take some time to run it again.

sudo systemctl restart magid

or just

$ sudo reboot

Now make a backup

$ magid backupwallet ~/21.05.19.magi.wallet.dat

It will create this .dat file right in your home directory. Copy it somewhere and keep it secure.

12. Enjoy

Tips:

You can check available commands list by typing

magid help

You can create toy wallet address by typing

magid getnewaddress

You can check transactions by typing this:

magid listtransactions

Unlock your wallet for staking only:

magid walletpassphrase YOUR_PASSWORD 9999999 true

So, you’re done at this step. You’ve got a fully functional coin magi wallet up and running on your raspberry pi. Good luck.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

This tutorial is great, it could be enhanced for N00bs like me.

  1. There's a typo, when you are going to compile where should read armv7l says arm7l

Took me a while to find the issue as I was receiving a SSE compilation error.

2.When "Update your system to receive jessie"
You can add: For this, just change the word stretch for jessie

  1. Configuring the wallet
    Please add where to get the Username & Password
    To my knowledge this came when you join a Pool, so Joining a Pool should be before that point.
    Also to Join a Pool you need a Coin Address, should I use one generated with the command: "magid getnewaddress"?

  2. magid getinfo
    After more than two hours and you still get the error "couldn't connect to server", what should I check?

  3. After you begin to mine, when in time you should have a Balance when you run the magid getinfo command?

  4. Can the Mining process be added to this tutorial?

·

Hey! For your address:
~/magi $ magid getaddresses
Later!

How do you upgrade the wallet. I just got the following error message:

magid getbalance
error: {"code":-2,"message":"Safe mode: URGENT: Mandatory wallet upgrade required before hard fork on block 1825101"}