# This is the Bitcoin LightningATM

Welcome to the documentation for the Bitcoin LightningATM. The following pages will guide you through the installation and setup of your own LightningATM.

Hey 😉 Pleased to have you! You arrived on the documentation website to build your own LightningATM.

![](/files/-M65MCTJvgZBjswWiIdA)

## 🔎 What you'll find here  :

* Hardware and software requirements in detail
* About 1.5 hours of video content to assemble all the hardware parts
* Written documentation for the software and wallet setup
* Trouble shooting and FAQ section

**Please be aware that this is a hobbyist project and it is not secure and reliable enough to withstand attacks. I discourage the use of this setup in a professional environment - but it's rather a good educational tool.**

> 💻 For the code head over to <https://github.com/21isenough/LightningATM>

Feel free to join the "LightningATM" Telegram group for more information and help. Also a great way to communicate with other "ATM builders" and share knowledge and experience:

{% hint style="success" %}
Join the Telegram group here: <https://t.me/lightningatm_building>
{% endhint %}

![](/files/-M5rlSeJrK9LeK3sc2Ms)


# What will it look like?

Well, the LightningATM can take many shapes or forms. It's really up to you how yours will look like. This is how mine looks - newer and older version :sunglasses:&#x20;

![](/files/-M61YlYRHHaiYqWoPRTD)

![](/files/-M61YlYH1yiAv34Vj5df)

![](/files/-M61YlYNE6TqvCLWnZb-)

![](/files/-M61YlYGemW-1fpYO0vp)

![](/files/-M61YlYPTogF1MCoV88v)

![](/files/-M61YlYLwXHpBI3ubiCo)

![](/files/-M61YlYVB7RngWwipmvv)

![](/files/-M61YlYKYUAB3TxMhs6U)

![](/files/-M61YlYQG2Nn7iBZ5cdr)

![](/files/-M61YlYJT9ODMWcLO5Xf)

![](/files/-M61YlYFuEYuCwIjNRK2)

![](/files/-M61YlYD8nBVMK1KRqEZ)


# Hardware requirements

On this page you will find all the details in regards to the hardware requirements. A short and comprehensive overview and "shopping list".

{% hint style="success" %}
Join the Telegram group here: <https://t.me/lightningatm_building>
{% endhint %}

## 🛒 What you will need ...

1. [**Raspberry Pi Zero WH**](/requirements/hardware-requirements#1-raspberry-pi-zero-wh-http-bit-ly-2-maxbr6)
2. [**16 GB SD Card**](/requirements/hardware-requirements#2-16-gb-micro-sd-card-http-bit-ly-39-anm-4-f)
3. [**PaPiRus Zero - ePaper / eInk Screen**](/requirements/hardware-requirements#3-papirus-zero-epaper-eink-screen-http-bit-ly-2-kdsovh)
4. [**Raspberry Pi Zero Camera (5MP)**](/requirements/hardware-requirements#4-raspberry-pi-zero-camera-5-mp-http-bit-ly-2-kupvt1)
5. [**Coin Acceptor 616**](/requirements/hardware-requirements#5-coin-acceptor-616-http-bit-ly-2-lhfowk)
6. [**Button**](/requirements/hardware-requirements#6-button-http-bit-ly-2-lk-4-aqr)
7. [**Jumper Cables**](/requirements/hardware-requirements#7-jumper-cables-http-bit-ly-2-kfgns4)
8. [**USB Cable**](/requirements/hardware-requirements#8-usb-cable)
9. [**Power supply (Option 1 or 2)**](/requirements/hardware-requirements#9-power-supply)
10. [**Blue tack and double-sided tape or glue**](/requirements/hardware-requirements#10-blue-tack-and-double-sided-tape-or-glue)
11. [**Case for the ATM**](/requirements/hardware-requirements#11-case-for-the-atm)

Price hardware: $50-$70 (only hardware) Price case: as little as $30 (depending on your supplier)

### 1. Raspberry Pi Zero WH - <http://bit.ly/2maXBr6>

If you can, get the version WH (not just W). It comes with pre-soldered headers and can be used out of the box. You should technically also be able to make this work on other versions of the Raspberry Pi but I haven't tried it.

### 2. 16 GB Micro SD Card - <http://bit.ly/39anM4f>

8 GB Micro SD card will also work. Just pick any brand with a reasonably good rating. Make sure you've got an adapter to insert your SD card into a computer.

### 3. PaPiRus Zero - ePaper / eInk Screen - <http://bit.ly/2kdSOVh>

This is the 2 inch ePaper display that I'm using in my build - it's designed for the RPi Zero and comes with a PHAT. My Python scripts are built to talk to the manufacturers library. Future version of the software will support other brands as well for example from the brand waveshare.

### 4. Raspberry Pi Zero Camera (5MP) - <http://bit.ly/2kuPvt1>

Make sure you buy a camera which also comes with the narrower ribbon cable (Pi Zero Ribbon Cable). The RPi Zero has a different CSI camera connector than the other versions. The "Pi Zero Ribbon Cable" can also be bought separately.

### 5. Coin Acceptor 616 - <http://bit.ly/2lHfoWK>

This coin acceptor can accept up to 6 different coins. It can learn what coins you want to use it with. The setup process happens manually on the acceptor itself.

### 6. Button - <http://bit.ly/2lK4AqR>

Any button that can close a power circuit will do the trick. Don't use a switch that stays permanently in its new position - a click button that is only closed while pressing it. If you are planning to use my laser cut design for the case, make sure the diameter of the thread is just about shy of 16mm.

### 7. Jumper Cables - <http://bit.ly/2kfGns4>

You will need a bunch of jumper cables to connect all the components with each other. Make sure you've got some variety (male and female) as you will need to connect different types of pins with each other.

### 8. USB Cable

You need at least one USB cable to power the RPi Zero (if you choose "Option 1" in point 9 you need another one for the coin acceptor).

### 9. Power supply

1. Option 1 (recommended): Buy a 5V power supply and a small transformer to step up 5V to 12V (this is the one I use <http://bit.ly/36UypXy>). This option will allow you to run the whole ATM completely on 5V power. Make sure your power supply or power bank can supply 2 amps.
2. Option 2: Buy a 5V and a 12V power supply. 5V for the RPi Zero (simple USB adapter) and 12V for the coin acceptor.

### 10. Blue tack and double-sided tape or glue

Choose the right adhesive for your setup depending on how permanent you want to assemble it. I travel with my ATM often so I work mainly with Blue tack - anything that "sticks things to other things" will work.

### 11. Case for the ATM

If you are planning to laser cut my current design of the ATM, you can find the dxf files for your laser cutter here: [Laser cut template on GitHub](https://github.com/21isenough/LightningATM/tree/master/resources/3dmodels) However, the hardware setup is quite flexible so that you can mount it into any box that you see fit.

![Laser Cut Design for ATM](/files/-M61XTxl-Eq-14Qk_Oxd)

## 📒 Further Details

* The LightningATM talks over Wifi Internet to API endpoints in order to facilitate the payout of bitcoin to the end-users lightning wallet. Make sure there's Wifi available and you know the Wifis name (SSID) and the password.
* Luster terminals make your life easier when connecting cables and can prevent soldering.
* A soldering iron and solder are handy and some connections might be better soldered then clamped/wrapped/screwed. This again depends on how permanent you want it to be.
* Make sure you have different screw drivers and knifes available
* For my laser cut case, I bought small little plastic knobs that I attached to the bottom of the case as feet.
* For my laser cut design you would also need M2.5x10mm screws to assemble the pieces <http://bit.ly/382jufj>


# Software requirements

On this page you will find all the details in regards to the software requirements. There is not much.

## 🔨 What you will need ...

There's not much you really need to prepare for. The major part of the software requirements comes directly with the code from the GitHub repository.

**Don't be frightened if you've never done this before. It's all thoroughly explained in the videos. Anyone can do it** 🤩 **!**

* Linux / Mac / Windows - all fine
* Software to flash an SD card (e.g. [Balena Etcher](https://www.balena.io/etcher/))
* SSH client (e.g. [Putty](https://putty.org/) or your standard command line)
* Everything else will be directly installed onto the Raspberry Pi during the installation of the ATM. Just follow along with the videos, it's quite straightforward.
  * Visit <https://github.com/21isenough/LightningATM>

![https://www.youtube.com/watch?v=A9JKUQvvmYM](/files/-M673zOkY-cuGM5kfbzQ)

{% hint style="success" %}
Join the Telegram group here: <https://t.me/lightningatm_building>
{% endhint %}


# Hardware Setup


# Hardware Overview

{% embed url="<https://www.youtube.com/watch?v=14JfEhNSdZE>" %}

{% hint style="success" %}
Join the Telegram group here: <https://t.me/lightningatm_building>
{% endhint %}


# RaspberryPi and Display

{% embed url="<https://www.youtube.com/watch?v=GJ4iwHK7y2Q>" %}


# Assembly and Software

{% embed url="<https://www.youtube.com/watch?v=A9JKUQvvmYM>" %}

## Setup process as shown in the video

* Download the Raspbian ATM Image ([https://www.dropbox.com/s/kg5swxhdb9h2a4m/2019-04-08-raspbian-stretch-lightningatm.gz\\](https://www.dropbox.com/s/kg5swxhdb9h2a4m/2019-04-08-raspbian-stretch-lightningatm.gz\)\\)
* Flash the Image to the SD Card with Etcher.
* Add one file to the /boot folder on the SD Card.
  * Create "wpa\_supplicant.conf" file and add the Wifi credentials.

```
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
        ssid="You_WiFi_SSID"
        psk="You_WiFi_Password"
}
```

* Connect to it via the console with the user "pi"
  * $ ssh <pi@192.168.X.XXX>
* Confirm to add the ECDSA key fingerprint with "yes"
* Login with the default password "raspberry"
* Change the default password of the user "pi" to your own
  * $ passwd
  * After confirming the current password, type your new password twice.
* Upgrade the RPi Zero to the newest versions of all Software
  * $ sudo apt update && sudo apt upgrade
* Clone the current version of the LightningATM Software
  * $ git clone <https://github.com/21isenough/LightningATM.git>
  * $ cd LightningATM
  * $ pip3 install -r requirements.txt
* After reboot connect again to the RPi Zero with your new password.
  * $ ssh <pi@192.168.X.XXX>


# Wiring Details

![](/files/-M9cPLoVohGtSmV1O60l)

## Wiring Details

1. USB power cable to supply 5V power to the step up converter (standard USB micro cable can be cut in half and the `USB type A` part used for this).
2. USB micro cable to provide 5V power to the Raspberry Pi Zero (second half of the cable cut in half in step 1).
3. If you are using a step up transformer, that can supply a variable amount of voltage, make sure it is properly set to 12V with a multi meter (by twisting and adjusting the tiny screw).
4. The output of the step up transformer (set to 12V) supplies to coin acceptor with 12V power.
5. The ground connection of the step up transformer must also be connected to a ground pin of the Raspberry Pi Zero (see pin out details below`CoinAcc(G)`).
6. Attach the camera to the CSI camera port of the Raspberry Pi.
7. To detect button presses, pins`BCM5`and`3v3 power`(see pinout below) need to be connected to the button (normally closed connection (NC)).
8. (Optional)`BCM13`and `Ground` (see pinout below) can be used, if your button has an LED inside, that can be controlled by the ATM software.
9. Cables that connect the Papirus E-Ink display to the Raspberry Pi Zero (see pinout below).

![](/files/-M6WLz2yRxSL_-6_8Cfy)

This pinout is only applicable if you use the "PaPiRus Zero - ePaper / eInk Screen". For other eInk displays please refer to its manual or ask in the Telegram group for help:

{% hint style="success" %}
Join the Telegram group here: <https://t.me/lightningatm_building>
{% endhint %}


# Software Setup


# Configuring the ATM

## 💻 Access the ATMs configuration file

There is a configuration file that lets us make changes to the core configurations of the ATM such as the currency displayed and more.

The configuration file will be created, the first time the ATM is turned on an run with `./app.py`. Make sure you've run `./app.py` at least once, otherwise this configuration file won't exist.

The configuration file can be found here: `~/.lightningATM/config.ini`

Let's inspect 🔎 what is inside this file with the editor `nano`. Type in the following to open the file with the `nano` editor:

```
nano ~/.lightningATM/config.ini
```

The beginning of this configuration file will look something like this and we'll quickly check the most important values in there:

```
[atm]
# Set your fiat currency with the three letter
# currency code (https://www.xe.com/symbols.php)
cur = eur

# Define what a cent is called in the currency
# of your choice for price display (singular).
centname = cent

# Set the Fee in %
fee = 2
```

* `cur = eur`

  The variable `cur` defines what fiat currency will be used at your ATM.
* `centname = cent`

  The variable `centname` defines the name of one cent of your base currency (0.01)
* `fee = 2`

  The variable `fee` defines how much fee you charge those who use your ATM

You can now move with your cursor to the desired variable and simply change it to your liking. I'd recommend to only change those three values and leave the rest as it is (unless you know exactly what you are doing 👆 ).

In order to save the file and exit you will have to press `Ctrl + x` and it will ask you `Save modified buffer?`. You can confirm by entering `y` (for yes) and hitting `Enter` to confirm.

{% hint style="success" %}
Join the Telegram group here: <https://t.me/lightningatm_building>
{% endhint %}


# Activating the camera

We will now enable the camera 📸 on the ATM since it is set to `disabled` by default. Whenever you encounter an error in the log file, that is related to the camera, make sure this is setup correctly.

Go into the config menu of the Raspberry Pi with:

```
sudo raspi-config
```

1. Choose `5 Interfacing Options`
2. Then `P1 Camera`

   It will ask you `Would you like the camera interface to be enabled?`
3. Confirm `<Yes>`
4. Confirm `<Finish>`

   Then you'll be asked `Would you like to reboot now?`
5. Confirm `<Yes>`

As your ATM has restarted, it should now have the camera enabled and be ready to take pictures 🖼 and scan QR codes.

{% hint style="info" %}
If your camera doesn't recognize QR codes, make sure the focus of the camera is properly adjusted. You might need to adjust it manually with a pair of pliers. Check this [link for more details.](https://www.jeffgeerling.com/blog/2017/fixing-blurry-focus-on-some-raspberry-pi-camera-v2-models)
{% endhint %}


# Monitoring the log file

## 💻 Install tmux

In order to see what is going on the ATM and check the log file, we will first install `tmux`. Tmux is a terminal multiplexer for Unix-like operating systems and allows us to split our terminal screen in half (among other things). Install `tmux` with the following command on your ATM:

```
sudo apt install tmux
```

## 👷 Using tmux

After it has finished installing you can start a new tmux session by typing `tmux` into the command line.

```
tmux
```

Every action in `tmux` has to be "announced" with the key combination `Ctrl + b`. Let's try this 🍪 ! First do `Ctrl + b` and then the percent sign `%` (you might have to use the `Shift` key for this). This should have split your terminal window vertically in half.

You can jump between the two sides with `Ctrl + b` and then `left arrow` or `right arrow`. You can adjust the size of the two windows by typing `Ctrl + b` and while keeping the `Ctrl` key pushed down , use the left/right arrow keys to adjust it to your liking (press the arrow keys multiple times).

You can detach from your current `tmux` session with `Ctrl + b` and the key `d`. If you want to get back into that same session type:

```
tmux a
```

(This only works, if you have just one `tmux` session).

A pretty good cheat sheet for an advanced usage of tmux [can be found here](https://tmuxcheatsheet.com/).

## 🖥 Monitoring the ATMs log file

We will start following our debug log file in our right side of the session. The logfile has been created automatically as you started your ATM for the very first time here: `~/.lightningATM/debug.log`

Move to the right side of the terminal session with the cursor and then type:

```
tail -f ~/.lightningATM/debug.log
```

You will get to see the last 10 entries in that log file and it will automatically update as soon as a new entry shows up in the log file (The file might not exist yet, if you have a completely fresh installation. Just the start the ATM once with `./app.py` and then try again).

Move back to the left side of your screen and there we start the ATM software with:

```
cd ~/LightningATM
./app.py
```

As the ATM starts, you will now see an additional line appear on the right side saying `Application started`. Perfect, we can now monitor closely what is going on inside the ATM. It should now look something like this:

![Tmux Setup](/files/-M5NDolN_uQwmghWUEGg)

{% hint style="success" %}
Join the Telegram group here: <https://t.me/lightningatm_building>
{% endhint %}


# Wallet Setup

In the following sections you will learn how to setup different Bitcoin Lightning Wallets with your LightningATM. The balance of these wallets will then be used to payout the satoshis that are being b

{% hint style="info" %}
Make sure, you have finished the hardware video part 3, before you attempt to setup your wallet (<https://www.youtube.com/watch?v=A9JKUQvvmYM>)
{% endhint %}

## Supported Wallets

Currently there is two wallets that you can use with the LightningATM:

* LND (best supported with BTCPayServer Setup)
* Lntxbot


# LND (on BTCPayServer)

This part of the guide will show you, how to connect your LND node on a BTCPayServer setup to your LightningATM.

{% hint style="info" %}
Make sure, you have finished the hardware video part 3, before you attempt to setup your wallet (<https://www.youtube.com/watch?v=A9JKUQvvmYM>)
{% endhint %}

## ⚡ LND (on BTCPayServer)

### ⏫ Updating your current installation

Before you continue, make sure you are on the latest version of the ATM software. For this we go into the `LightningATM` folder and execute one git command:

```
cd ~/LightningATM
git pull
sudo pip3 install -r requirements.txt
```

You should now have the latest changes and therefore the latest version of the LightningATM software on your Raspberry Pi.

### 🤯 For a little more advanced users

The coming steps will involve a pretty automated process and the ATM literally configures itself. If you feel like you could take up a little challenge then stop reading and set it up yourself with the following hints of mine. If not, just skip this step and move down to `Displaying your BTCPayServer QR code`.

* In your BTCPayServer go to `SERVER SETTTINGS` and then `Services`.
* Go down to the table and where it says `LND (REST server)` and click `See information`
* Go all the way down and where it says `More details...` click on "by clicking `here`"
* What we need here is `REST Uri` and the `Macaroon`

In order for the ATM to connect with your LND node on BTCPayServer, `REST Uri` and the `Macaroon` will now have to be inserted into the configuration file of the ATM. The configuration file of your AT can be found here: `~/.lightningATM/config.ini`

Let's inspect what is inside this file with the editor `nano`. Type in the following to open the file with the `nano` editor:

```
nano ~/.lightningATM/config.ini
```

Towards the end of the file you will find a section that's named `[btcpay]` and there is a variable `url`. Just below there is another section `[lnd]` with a variable `macaroon`.

You will now have to set those variables equal to the values that you've found in your BTCPayServer interface. Save the file, exit and restart your ATM. It's now configured with your LND node on your BTCPayServer! Congrats 🎉 , you can now skip the next steps and move all the way down to [First transaction with the ATM](/lightningatm-setup/wallet-setup/lnd_btcpay#first-transaction-with-the-atm)

### 📱 Displaying your BTCPayServer QR code

Log into your BTCPayServer where you have your LND node running. In the menu choose the item `SERVER SETTINGS` and then `Services`. That's what this will look like, on a mobile phone:

![Menu BTCPayServer](/files/-M5rSkslDiUIAehdJsWq)

At the bottom in the table you can see the column `Access Type` and in there `LND (REST server)`. Next to `LND (REST server)` click on the link `See information`. Scroll down a little and find the green button that reads `Show QR Code` an click it.

![QR Code for LND REST](/files/-M5rSksos_wd-3D0fgk5)

This is all we need - have this QR ready for the next step. Be aware that this QR code is only valid for 10 minutes so you might need to refresh your browser and create a new one when you'll get an error at the ATM.

### 👩🔧 Connecting to the ATM

We will now connect the LND node to your ATM. For this we access our ATM again through SSH, change into the `LightningATM` directory and start the software with:

```
cd ~/LightningATM
./app.py
```

It's best to monitor the log file with `tmux`, while you are doing this. Check out how to do that here:

{% content-ref url="/pages/-M5N7OP7jMlq3mBnx6IF" %}
[Monitoring the log file](/lightningatm-setup/software-setup/monitoring_log_file)
{% endcontent-ref %}

This will again start the ATM software and we get to see `Welcome to the LightningATM` on our screen.

We'll now have to put our ATM into the "credentials scanning" mode. This can be done by pushing the button 3 times.

After you pushed the button three times your display should say `Please scan your wallet credentials`. Now take your mobile phone with the LND BTCPayServer QR code and show it to the camera.

It will now scan your credentials, evaluate its content and safe it to the configuration file of the ATM. If you've been successful, your screen will say `Success!!` and your LND node is successfully linked with your ATM ⚡ .

### 🤑 First transaction with the ATM

Let's make a first proper transaction now!

Insert some coins into the coin acceptor of the ATM and see how the balance increases on the display (give the ATM some time between coins for coin recognition). When you've inserted enough, press the button once to start the payout process.

The ATM will now go into the "invoice scanning" mode and say `Please scan your invoice` and a short countdown will appear. Your ATM is now in an indefinite loop and will constantly scan for Lightning Invoices. If you want to stop it, you will have to press `Ctrl + c` to manually interrupt the process.

Now take another Lightning Wallet (people often use their mobile phone wallet) and create and Lightning Invoice. You have two options:

1. Show a "zero satoshi" invoice.

   This is an invoice that does not request a specific amount of satoshis (some wallets let you do that).
2. Create an invoice with the exact amount of satoshis.

   This is an invoice in which the mount of satoshis requested is encoded into the QR code (higher or lower value invoices will be rejected.)

Once the invoice has been scanned and was evaluated successfully, your LND node will try to pay it through the Lightning Network. If successful, both your mobile wallet and your ATM will confirm the transaction. Congratulations!! 😎

{% hint style="success" %}
Join the Telegram group here: <https://t.me/lightningatm_building>
{% endhint %}


# Lntxbot

This part of the guide will show you how to setup Lntxbot, a Bitcoin Lightning Wallet in your Telegram messenger on your mobile phone.

{% hint style="info" %}
Make sure, you have finished the hardware video part 3, before you attempt to setup your wallet (<https://www.youtube.com/watch?v=A9JKUQvvmYM>)
{% endhint %}

## 🤖 Lntxbot

### A word of caution

{% hint style="warning" %}
The Lntxbot is a "Custodial Bitcoin Wallet". This means, you are trusting those who run the software behind this wallet with your satoshis and you are not in control of your private keys. Be careful and don't keep too many satoshis on there.
{% endhint %}

### ⏫ Updating your current installation

Before you continue, make sure you are on the latest version of the ATM software. For this we go into the `LightningATM` folder and execute one git command:

```
cd ~/LightningATM
git pull
sudo pip3 install -r requirements.txt
```

You should now have the latest changes and therefore the latest version of the LightningATM software on your Raspberry Pi.

### 👩💻 Installing Lntxbot

Install the mobile application "Telegram" on your phone and after you have created your account, go into the search bar and type `Lntxbot`or click here <https://t.me/lntxbot>.

![Searching Lntxbot](/files/-M5MpPF0Yclg9uipPs9w)

You should now be able to talk to the Lntxbot. If you type `/help` you will get a list of commands that are available.

![Hello Lntxbot](/files/-M5MuS8p6f4-gzdShjCU)

You can inspect all the different commands that are available for you on this mobile Lightning Wallet.

![Commands Lntxbot](/files/-M5MuS8rImGafeThRhgA)

### 💰 Funding the Lntxbot

In order for this Lightning Wallet to work with our ATM, we need to fund it and have some satoshis on there. Type `/invoice <amount>` into the message box and replace `<amount>` by a certain amount of Satoshis you want to fund it with.

Now, you will have to pay this invoice with another wallet in order for your Lntxbot to receive them and later be available at your ATM.

After you payed this invoice check your balance with `/balance` to make sure it all worked out.

### 👨🔧 Connecting the Lntxbot to the ATM

We will now connect the Lntxbot to your ATM. For this we access our ATM again through SSH, change into the `LightningATM` directory and start the software with:

```
cd ~/LightningATM
./app.py
```

It's best to monitor the log file with `tmux`, while you are doing this. Check out how to do that here:

{% content-ref url="/pages/-M5N7OP7jMlq3mBnx6IF" %}
[Monitoring the log file](/lightningatm-setup/software-setup/monitoring_log_file)
{% endcontent-ref %}

This will again start the ATM software and we get to see `Welcome to the LightningATM` on our screen.

Next, we will generate a QR code with our Lntxbot credentials. Go to the message box in Lntxbot and type `/lightningatm`. This will generate a QR code with the credentials that we need.

We'll now have to put our ATM into the "credentials scanning" mode. This can be done by pushing the button 3 times.

After you pushed the button three times your display should say `Please scan your wallet credentials`. Now take your mobile phone with the Lntxbot and show the previously generated QR code with your credentials to the camera.

It will now scan your credentials and safe it to the configuration file of the ATM. If you've been successful, your screen will say `Success!!` and show you the current balance of your Lntxbot.

{% hint style="info" %}
If you every wanted to renew your API credentials just send the command `/api_refresh` to the Lntxbot. This will revoke the current credentials and replace them with new ones.
{% endhint %}

### ✅ First transaction with the ATM

Let's make a first proper transaction now!

Insert some coins into the coin acceptor of the ATM and see how the balance increases on the display (give the ATM some time between coins for coin recognition).

When you've inserted enough, press the button once (your balance on the Lntxbot needs to be big enough to cover the requested satoshis).

The ATM will now create a QR code and display it on the screen with a note that says `Scan to receive`. Take your mobile Lightning Wallet and scan this QR code to receive the satoshis.

{% hint style="success" %}
Join the Telegram group here: <https://t.me/lightningatm_building>
{% endhint %}


# Wallet Communication

This section will answer some questions in regards to how the ATM communicates with the wallets that you connect it to. We'll be looking into API calls and what actually happens "under the hood".

## :speaker:How the ATM "talks"

When someone uses the LightningATM, they insert a certain amount of coins into the ATM and expect bitcoin / satoshis back for it (from now on, I'll just simply write "satoshis", the smallest denomination of one bitcoin). The ATM must therefore be connected to a Lightning Wallet :zap: from which it sends satoshis to the person who has inserted the coins.

To ATM doesn't have any satoshis "on it". It will always have to "communicate" to a Lightning Wallet over a network and tell the wallet to send the satoshis. This communication is happening over an API ([Application Programming Interface](https://www.freecodecamp.org/news/what-is-an-api-in-english-please-b880a3214a82/)) of a Lightning Wallet.

APIs can be talked to in various ways. Most often the ATM will talk to them through a URL. Almost all API communication also requires a username and a password :key: .

1. The API might be accessed at <https://my-lightning-wallet.com/api>
2. To prove that the ATM is allowed to use this API, it will have to provide a username and a password

It's therefore clear that we have to store this information (URL, username and password) on the ATM. The easiest way to do this, is by encoding all that information into a QR code and showing it to the camera of the ATM ([as explained here](https://docs.lightningatm.me/lightningatm-setup/wallet-setup/lnd_btcpay#connecting-to-the-atm)).

The ATM will then read the content of the QR code and store those three pieces of information in a configuration file. From then on, it uses that information to talk to that Lightning Wallet to facilitate payouts and other communication like requesting the current state of the Lightning Wallet such as "balance" or "channel information".

## :desktop: API endpoint, usernames and passwords

Let's take a closer look at the kind of information that is needed to talk to the API of a Lightning Wallet. Be aware that these pieces of information come in various shapes and encodings.

The URL to access an API might contain an IP address or a domain and can have a multitude of different paths (called "API endpoints"). Some examples:

* <https://my-lightning-wallet.com/api/payinvoice>
* <https://api.my-lightning-wallet.com/v1/channelbalance>
* <https://localhost:8080/v1/payments>
* <https://btcpayserver.mydomain.me/v1/balance/blockchain>

The URL to which your ATM will be talking to, depends on the software of the Lightning Wallet and the location where the wallet is "run" or operated (maybe a LND Lightning Node/Wallet on a [RaspiBlitz](https://github.com/rootzoll/raspiblitz) or a [BTCPayServer](https://github.com/btcpayserver/btcpayserver-docker)).

The username and password might need to be supplied as you're used to it from logging into websites but could as well be encoded in a [hexadecimal](https://www.lifewire.com/what-is-hexadecimal-2625897) or [base64](https://base64.guru/learn/what-is-base64) string.

## :woman\_technologist: Talking to an API in practice

Now, let's get a little bit more practical and actually talk to an API. For this example, I'll be using the API of the Lntxbot because it is available to everyone with Telegram no their phone and can easily be followed along (more information on how to install Lntxbot can [be found here](https://docs.lightningatm.me/lightningatm-setup/wallet-setup/lntxbot#installing-lntxbot)).

First, let's find out what the URL, username and password of the API is, so we can talk to it. Send the command `/lightningatm` to your Lntxbot and you will get back a QR code and some text. The text comes back in the following format:

* \<username:password>@\<url\_of\_lntxbot>

### \<username:password>

You won't be able to distinguish here between username and password because it has already been encoded in the base64 format. However, before that, it was actually a separate username and password.

If you type `/bluewallet` into your Lntxbot, you will get to see your username and password (don't get confused about the command "bluewallet", this is just because Lntxbots API is compatible with a piece of software from bluewallet called [LndHUB](https://bluewallet.io/lndhub/).

The 5 digit number between `lndhub://` an the `:` is your username. The long string between the `:` and the `@` symbol is your password.

Let's take the username and the password and convert it into the base64 string from the `/lightningatm` command and we'll see that they match. Log into your Raspberry Pi and execute the following command:

```
echo -ne "<username:password>" | base64 --wrap 0
```

Now you can go back to the result that you've gotten from the `/lightningatm` command and you will see that this result is the same. You just manually encoded your username and password in base64 with the above command.

### \<url\_of\_lntxbot>

What follows after the `@` symbol from the `/bluewallet` command is the base URL. This URL needs to be appended with the API endpoint that we want to call. This might be `/balance` or `/payinvoice` depending on the action that we want to execute.

We will now request the balance from our Lntxbot through the command line with the `/balance` endpoint. Your base URL is most likely `https://lntxbot.bigsun.xyz` so the final URL the we want to call is `https://lntxbot.bigsun.xyz/balance`.

We are going to do that with the command line tool called `cURL` (client for URLs). Not only do we need to call the correct URL but we also have to supply the username and password. Username and password will be sent in the base64 encoded format (as you've done above and can get from the `/lightningatm` command). It will be sent in what is called the [http header](https://www.geeksforgeeks.org/http-headers/) of this request.

```
curl -H "Authorization: Basic <BASE64_ENCODED_PASS_AND_USERNAME>" https://lntxbot.bigsun.xyz/balance
```

This command will make a request to the URL at the end and supply your username and password in the http header and back comes - your current balance in the Lntxbot (in json format).

## Summary

You've just manually done a HTTP request to an API endpoint and supplied your username and password as a base64 encoded string in the header of the request. Bravo :partying\_face::tada: .

And that is all the ATM really does when it comes to "talking with Lightning Wallets :zap: ". Different wallets have different APIs and therefore different URLs and endpoints. Some might want the username and password to be sent in base64 or HEX encoding. In the case of LND the "username and password" takes the form of a `cookie` that is called a `macaroon` and has to be sent in its HEX format \[(more info here)(<https://github.com/lightningnetwork/lnd/blob/master/docs/macaroons.md#macaroon-delegation>)].

As mentioned above: When you show the QR code with your wallet information to the ATMs camera and it scans it, it will use that information later in various API calls as you or others interact with the ATM. It stores these details in the configuration file of your ATM, which you can take a look at when you run the command `nano ~/.lightningATM/config.ini`.

Happy satoshi buying!! :moneybag:&#x20;

{% hint style="info" %}
Take a look at the source code of the ATM where we request the balance for the ATM in python rather than through the command line here: [Requesting Lntxbot balance in python](https://github.com/21isenough/LightningATM/blob/a35a0a128f016620a27b2c03b7539439fc396fdf/lntxbot.py#L80)
{% endhint %}


# Starting Automatically

A quick description on how you can start the ATM automatically, as soon as the Raspberry Pi has booted.

## 🚀 Starting the ATM automatically

If you want that the ATM software starts automatically, every time you boot the Raspberry Pi, you can do this with the systemd file that is part of the software files.

In order to activate the daemon, you first have to copy the file into the right folder on your Rasperry Pi 🍓 and then enable the daemon with these commands:

```
cd ~/LightningATM
sudo cp LightningATM.service /etc/systemd/system/LightningATM.service
sudo systemctl enable LightningATM.service
```

You can check it the daemon is up and running as well as check the log file with these commands:

```
# With this command you can check if it is active and running
sudo systemctl status LightningATM.service

# With this command you can check the log/debug file for errors
tail -f ~/.lightningATM/debug.log
```


