This is NEAR Application for the Ledger Nano S/X/SP and Stax.
You can quickly setup a convenient environment to build and test your application by using Ledger's VSCode developer tools extension which leverages the ledger-app-dev-tools docker image.
It will allow you, whether you are developing on macOS, Windows or Linux to quickly build your apps, test them on Speculos and load them on any supported device.
app-near
with git clone git@github.com:LedgerHQ/app-near.git
.app-near/workdir/app-near
folder with VSCode.ctrl + shift + b
(command + shift + b
on a Mac) to conveniently execute actions :
Build
.Run with Speculos
.:information_source: The terminal tab of VSCode will show you what commands the extension runs behind the scene.
The ledger-app-dev-tools docker image contains all the required tools and libraries to build, test and load an application.
You can download it from the ghcr.io docker repository:
sudo docker pull ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest
You can then enter this development environment by executing the following command from the directory of the application git
repository:
Linux (Ubuntu)
sudo docker run --rm -ti --user "$(id -u):$(id -g)" --privileged -v "/dev/bus/usb:/dev/bus/usb" -v "$(realpath ./workdir/app-near):/app" ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest
macOS
sudo docker run --rm -ti --user "$(id -u):$(id -g)" --privileged -v "$PWD/workdir/app-near:/app" ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest
Windows (with PowerShell)
docker run --rm -ti --privileged -v "$(Get-Location):/app" ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest
The application's code will be available from inside the docker container, you can proceed to the following compilation steps to build your app.
To easily setup a development environment for compilation and loading on a physical device, you can use the VSCode integration whether you are on Linux, macOS or Windows.
If you prefer using a terminal to perform the steps manually, you can use the guide below.
Setup a compilation environment by following the shell with docker approach.
From inside the container, use the following command to build the app :
make DEBUG=1 # compile optionally with PRINTF
You can choose which device to compile and load for by setting the BOLOS_SDK
environment variable to the following values :
BOLOS_SDK=$NANOS_SDK
BOLOS_SDK=$NANOX_SDK
BOLOS_SDK=$NANOSP_SDK
BOLOS_SDK=$STAX_SDK
By default this variable is set to build/load for Nano S.
This step will vary slightly depending on your platform.
:information_source: Your physical device must be connected, unlocked and the screen showing the dashboard (not inside an application).
Linux (Ubuntu)
First make sure you have the proper udev rules added on your host :
# Run these commands on your host, from the app's source folder.
sudo cp .vscode/20-ledger.ledgerblue.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules
sudo udevadm trigger
Then once you have opened a terminal in the ledger-app-builder/ledger-app-dev-tools
image and built the app for the device you want, run the following command :
# Run this command from the app-builder container terminal.
make load # load the app on a Nano S by default
NOTE: ledger-app-builder/ledger-app-builder
image is not suitable for loading built app onto device, it's suitable only for building app.
Setting the BOLOS_SDK environment variable will allow you to load on whichever supported device you want.
macOS / Windows (with PowerShell)
:information_source: It is assumed you have Python installed on your computer.
Run these commands on your host from the app's source folder once you have built the app for the device you want :
# Install Python virtualenv
python3 -m pip install virtualenv
# Create the 'ledger' virtualenv
python3 -m virtualenv ledger
Enter the Python virtual environment
source ledger/bin/activate
.\ledger\Scripts\Activate.ps1
# Install Ledgerblue (tool to load the app)
python3 -m pip install ledgerblue
# Load the app.
python3 -m ledgerblue.runScript --scp --fileName bin/app.apdu --elfFile bin/app.elf
The app comes with functional tests implemented with Ledger's Ragger test framework.
To test your app on macOS or Windows, it is recommended to use Ledger's VS Code extension to quickly setup a working test environment.
You can use the following sequence of tasks and commands (all accessible in the extension sidebar menu) :
Select build target
Build app
Or simply run the app on the Speculos emulator :
Run with Speculos
.Run the functional tests (here for nanos but available for any device once you have built the binaries) :
# from root of the repo
docker run --rm -tdi --privileged -v "/dev/bus/usb:/dev/bus/usb" -v "$(realpath .):/app" --name app-near-container ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest
docker exec -it -u 0 app-near-container bash -c 'cd ./workdir/app-near && make -j'
docker exec -it -u 0 app-near-container bash -c ' [ -f ./workdir/app-near/tests/requirements.txt ] && pip install -r ./workdir/app-near/tests/requirements.txt'
docker exec -it app-near-container bash -c 'pytest ./workdir/app-near/tests --tb=short -v --device nanos'