Trust Wallet Core Documentation

repository·master·Indexed 25 days ago

https://github.com/trustwallet/wallet-core

An open-source, cross-platform library providing low-level cryptographic wallet functionality for over 130 blockchains. It offers idiomatic interfaces for Swift, Java/Kotlin, and C++, with additional support for Flutter, Go, NPM, and Kotlin Multiplatform (KMP). The library includes tools for generating Swift bindings via codegen-v2 and Protobuf serialization for method parameters.

Tokens
66.8K
Snippets
92
Records
538
Agent score
85%

What's inside Trust Wallet Core

  1. Understand C++ sample application operations

    master

    The C++ sample application (found in cpp/sample.cpp) demonstrates the following core WalletCore workflows:

    • Import a wallet: Creating a wallet by importing an existing recovery phrase (mnemonic) using HDWallet.
    • Derive address: Deriving a blockchain address from the HDWallet.
    • Create send transaction: Constructing a transaction (including sender, receiver, and amount) and signing it using the private key.
  2. Use the WalletConsole utility

    master

    The walletconsole is an interactive command-line utility provided with the Wallet Core library. It allows you to access key management and address management functionality directly from your terminal. Once running, you can interact with the console using specific commands to manage coins and generate addresses.

    $ ./build/walletconsole/walletconsole
  3. Build and run the C++ sample application

    master

    To build the C++ sample application, you must first clone the repository and ensure you have built the main WalletCore library, as there are no official binary distributions. You will need the TrezorCrypto and protobuf dependencies, which are included with WalletCore.

    1. Clone the repository and navigate to the sample directory:
    git clone https://github.com/trustwallet/wallet-core.git
    cd wallet-core/samples/cpp
    1. Configure and build using cmake, providing the path to the top-level Wallet Core library folder:
    cmake . -DWALLET_CORE=../../
    make
    1. Run the application:
    ./sample
    git clone https://github.com/trustwallet/wallet-core.git
    cd wallet-core/samples/cpp
    cmake . -DWALLET_CORE=../../
    make
    ./sample
  4. Set up Kotlin Multiplatform Mobile development environment

    master

    To use the Kotlin Multiplatform Mobile (KMP) sample, ensure your development environment meets the following requirements:

    1. Core Tools: Install Android Studio with Kotlin plugins, JDK, Xcode, and CocoaPods.
    2. Verification: On macOS, install kdoctor and run it to verify your setup. A successful environment should show checkmarks for Operation System, Java, Android Studio, Xcode, and Cocoapods.
    kdoctor
  5. Generate Swift bindings using codegen-v2

    master

    The codegen-v2 tool is a work-in-progress parser designed to replace the existing Ruby parser. Currently, it only supports generating Swift bindings. To execute the generator, navigate to the codegen-v2 directory and run the tool with the swift argument. The generated bindings will be saved to the bindings/ directory.

    $ cd codegen-v2
    $ cargo run -- swift
  6. Use the Rust Sample Application to link wallet-core

    master

    The Rust Sample Application demonstrates how to link and use the wallet-core C/C++ library within a Rust environment. It handles the linking of TrustWalletCore, TrezorCrypto, protobuf, and the platform libc (c++ or stdc++).

    To use this sample, you must ensure the build.rs file is configured with the correct path to your compiled wallet-core directory.

  7. Run the Android Sample Application

    master

    To explore the usage of Wallet Core on Android, you can use the provided sample application. Open the samples/android directory in Android Studio and run the project. The application's output will be visible both on the device screen and in the Android Studio logs.

    Open in Android Studio and run.
  8. Prerequisites for Wasm Sample

    master

    Before building the Wasm sample, ensure you have the following installed and configured:

    1. Wallet Core Build Environment: Follow the standard building instructions for Wallet Core.
    2. Emscripten (emsdk): Requires python3 and cmake.
    3. Dependency Installation:
      • If you just cloned the repository, run tools/install-dependencies.
      • Run tools/install-wasm-dependencies.
    4. Node.js: Required for managing npm packages and running codegen scripts.