Skip to content

2. DAppNode SDK Tutorial: Basic package

Lanski edited this page May 13, 2020 · 1 revision

Super basic tutorial to get the basics

The setup

If you haven't already, install the dappnodesdk package

npm install -g @dappnode/dappnodesdk

Set up and bootstrap our demo project. We recommend the naming convention of DAppNodePackage-${package_name}.

mkdir DAppNodePackage-demo
cd DAppNodePackage-demo

The init command will create a convenient basic starting point. To auto answer the init questions use the flag -y, you can edit the resulting information latter.

dappnodesdk init -y

The resulting file structure should be similar to

DAppNodePackage-vipnode/
├── build/
│   └── Dockerfile
├── avatar-default.png
├── dappnode_package.json
└── docker-compose.yml

Develop your package

Our demo package will read an environment variable provided by the user and output it to the logs. The bare minimum to grasp the basics

Make sure the Dockerfile is equal to

FROM busybox

WORKDIR /usr/src/app

ENTRYPOINT echo "happy buidl $USERNAME!"

To add the $NAME environment variable it must be declared in the package's docker-compose, so add the environment to the docker-compose.yml file

version: "3.4"
services:
  demo.public.dappnode.eth:
    ...
    environment:
      - "USERNAME="

So the user can provide this variable in a UX friendly way add a setup wizard. Create a setup-wizard.json file in the project root:

{
  "version": "2",
  "fields": [
    {
      "id": "username",
      "target": {
        "type": "environment",
        "name": "USERNAME"
      },
      "title": "Username",
      "description": "Enter your username so your DAppNode can greet you"
    }
  ]
}

The DAppNode Admin UI will ask users to provide their username when installing our demo package and show the provided metadata. The target section maps this value to the environment variable we declared before in the docker-compose.yml.

Build and test

Now your package is ready for being tested locally in your DAppNode!

The dappnodesdk build command will prepare the necessary files, build the docker image and upload the package directory to IPFS. The resulting IPFS hash will allow you to install and run the package. Make sure that you are connected to your DAppNode's VPN or Wi-Fi hotspot and run:

$ dappnodesdk build

The command should end with an output similar to this

DNP (DAppNode Package) built and uploaded
  Manifest hash : /ipfs/QmfDSDeK9fiWpB7tEAiFKzuXvcvJr7yPiYr2jZmto6ZPRa
  Install link : http://my.dappnode/#/installer/%2Fipfs%2FQmfDSDeK9fiWpB7tEAiFKzuXvcvJr7yPiYr2jZmto6ZPRa

You can open the install link in your browser and install the package in your DAppNode. Click the INSTALL button and you should see a setup wizard view similar to this.

demo-sdk-enter-username

Provide the username, click submit and the package should install. After successful installation, go to the logs tab and you should see logs similar to this with your custom username.

demo-sdk-view-username

That wraps up our basic tutorial about the development flow of the dappnodesdk.