If your server application (most likely on Linux) language supports FFI to C, it is possible to call wallet core.
Here is a step by step example of cgo, using Wallet Core docker image.
-
Run
docker run -it trustwallet/wallet-core
The librabry is already built in this image (Build instructions here) Note: may not be the most recent version. -
Install go:
apt-get update && apt-get install golang
(or download from here go1.13.3, configureGOROOT
and appendGOROOT/bin
toPATH
). -
Save the sample code below to file called
main.go
package main
// #cgo CFLAGS: -I/wallet-core/include
// #cgo LDFLAGS: -L/wallet-core/build -L/wallet-core/build/trezor-crypto -lTrustWalletCore -lprotobuf -lTrezorCrypto -lc++ -lm
// #include <TrustWalletCore/TWHDWallet.h>
// #include <TrustWalletCore/TWString.h>
import "C"
import "fmt"
func main() {
fmt.Println("==> calling wallet core from go")
str := C.TWStringCreateWithUTF8Bytes(C.CString("confirm bleak useless tail chalk destroy horn step bulb genuine attract split"))
defer C.TWStringDelete(str)
valid := C.TWHDWalletIsValid(str)
fmt.Println("<== mnemonic is valid: ", valid)
}
- Compile it by
go build -o main
- Run
./main
and you will see the output below:
==> calling wallet core from go
<== mnemonic is valid: true
- You might want to copy and run
main
outside of the docker container, make sure you havelibc++1
andlibc++abi1
installed in your host Ubuntu.