Using GDK to receive and send Blockstream AMP Assets

This page explains how to download, install, and use Blockstream’s Green Development Kit (GDK) with AMP assets.

GDK enables you to develop solutions that benefit from the infrastructure that supports the Blockstream Green mobile and desktop wallets.

The page provides a link to some example Python code that creates a GDK wallet with a Managed Assets sub account. This allows the wallet to be capable of holding Blockstream AMP issued assets.

Using GDK in this way is useful for anyone wanting to hold AMP assets outside of Green mobile or Green desktop. It can be used to automate wallet processes involving AMP assets. If you need an example covering some common features needed by those who act as custodians of AMP assets on behalf of others, please contact us.

The linked example covers:

  1. Logging with an existing 24 word mnemonic or generating a new mnemonic.

  2. Set a pin for the wallet and login with the pin.

  3. Check and set the wallet’s Two Factor Authentication (2FA) status.

  4. Handle calls to methods that use 2FA, such as creating a spending transaction.

  5. Handle events in the Green notification queue, such as new blocks.

  6. Get a new address and an address pointer.

  7. Send an asset from the wallet to a Liquid address.

  8. Get all wallet related transactions from Green, or only ones from a certain block height.

GDK Overview

Blockstream’s Green Development Kit (GDK) is a cross-platform library for Blockstream Green wallets that can curently be used through Python and Java wrappers.

GDK cannot be called directly from languages like Node.js or JavaScript. In the future it is likely a Node.js wrapper will be included in the build process. JavaScript (client) support will not be included due to the nature of the GDK application layer.

If you are a developer that uses languages other than Python and Java, you may want to work around this limitation by using a service that wraps GDK within a simple HTTP API. A Flask-based example of this approach is provided here and includes a sample of calling the API using Node.js. A JavaScript example can be created using the Node.js version as a reference. This example API wrapper is provided purely as a way to demonstrate the concept and has not been offcially provided by Blockstream, so it is advised you check and amend the example as you see fit.

The GDK documentation can be used to expand the example further. A good example of a well-featured client application using GDK is green-cli, An example of using green-cli can be found in the GDK Command Line Example section.

How to install GDK and run the example

Create a new directory named gdk-example-python.

Within that directory, create a new file named gdk-example-python.py and copy and paste the example code from the GDK repository’s AMP example into it. Save the file.

From the terminal, move into the new directory:

cd gdk-example-python

Create a virtual environment (optional):

virtualenv -p python3 venv

If you did use a virtual environment, activate it:

source venv/bin/activate

You may prefer to build and install GDK from source but it is simpler to download and install the GDK python wheel for your platform from the GDK release page.

Note

If the version provided in the releases page does not match your Python version you will have to build GDK and use the build options to specify the version you have.

On the release page note that the ‘cp’ in the name refers to the Python version you have installed. You can check the version you have installed by running:

python --version

For example for a Python 3.9.* install on a 64 bit Linux platform you would download greenaddress-0.0.55-cp39-cp39-linux_x86_64.whl, move it to the gdk-example-python directory and install it using pip:

pip install greenaddress-0.0.55-cp39-cp39-linux_x86_64.whl

Now you can run the example code:

python gdk_example.py