Building and using Libwally
You can build Libwally on a variety of platforms and for different languages (including Mac OS, Android, WebAssembly).
Build Details of how to build Libwally are provided on the Libwally GitHub repository, along with steps of how to build the Swig wrappers needed to enable languages like Python and Java to use the library.
For Python use you can also install wally with pip, use the binary release or build the wrappers using the configure options.
There are also instructions on how to use the WASM-based JavaScript bindings for Node.js and the browser via the npm
package manager. An example of how to use the npm wallycore WASM package is shown here.
To build the WASM file yourself from source you can follow the instructions here which are targeted at a clean Ubuntu 22.04.1 minimal install.
Below we provide a detailed step process of how to build and use Libwally with Java.
Java example
Prerequisites
Swig is needed to wrap the compiled Libwally C++ code to provide an interface for Java. You can install Swig following the instructions here: http://swig.org/.
You also need to initialize the libsecp
sources before trying to build Libwally. Note that you only need to run this step once.
git submodule init
git submodule sync --recursive
git submodule update --init --recursive
Compiling Libwally with Java wrapper on Ubuntu
From the command line, run the following steps to configure and compile Libwally with Java wrappers and with Elements (and therefore Liquid) support:
git clone https://github.com/ElementsProject/libwally-core
cd libwally-core
./tools/autogen.sh
./configure --enable-elements --enable-swig-java --enable-debug
make
make check
The make check
step will run the test that have been created in libwally-core/src/swig_java/src/com/blockstream/test
. The tests run are listed below and can be used as templates for any tests you want to add to check your own code additions. The .class
files are compiled and run as .java
files.
test_assets.class
test_bip32.class
test_mnemonic.class
test_pegs.class
test_scripts.class
test_tx.class
If you need to later delete the generate files you can run the following before then running autogen
, configure
, make
etc again:
./tools/cleanup.sh
Running the existing Java examples and creating your own
The Java examples are located in libwally-core/src/swig_java/src/com/blockstream/test
and presented as tests that are run during the make check
step covered above.
You can run each test individually by moving to the src
folder:
cd libwally-core/src
And then calling the test while setting the path to the Wally jar file:
LD_LIBRARY_PATH=.libs java -Djava.library.path=.libs -classpath swig_java/src com.blockstream.test.test_tx
If you make you own tests and examples within the test folder, you can compile them and run them by following the steps below, which assumes your test file is called your_test
:
cd swig_java/src
javac com/blockstream/test/your_test.java
cd ..
cd ..
LD_LIBRARY_PATH=.libs java -Djava.library.path=.libs -classpath swig_java/src com.blockstream.test.your_test
Java interface definitions
The src/swig_java/src/com/blockstream/libwally/Wally.java
file contains the Java interface definitions that are available to you.
Updated almost 2 years ago