Skip to content

Dart bindings for Trust Wallet Core, used in Flutter and Dart.

License

Notifications You must be signed in to change notification settings

xuelongqy/wallet_core_bindings

Repository files navigation

wallet_core_bindings

License

Dart bindings for Trust Wallet Core, used in Flutter and Dart.

Packages

Package Pub
wallet_core_bindings Pub
wallet_core_bindings_native Pub
wallet_core_bindings_wasm Pub
wallet_core_bindings_libs Pub
wallet_core_bindings_wasm_assets Pub

Features

  • TrustWalletCore include files and Protobuf file bindings.
  • Provides Native and WebAssembly System Interface, supporting all platforms.
  • APIs are repackaged for easier use.
  • Combined with Dart GC, there is no need to control memory.
  • Update the TrustWalletCore version synchronously and keep the APIs consistent.

Getting Started

There are two ways to use wallet_core_bindings, Native and Web Assembly. Please follow the instructions below to make your choice.

Platform Native Web Assembly wallet_core_bindings_libs
Android ✔️ ✔️ ✔️
iOS ✔️ ✔️ ✔️
macOS ✔️ ✔️ ✔️
Linux ✔️ ✔️ ✔️
Windows ❌️ ✔️ ❌️
Web ❌️ ✔️ ❌️

Native

The native features of the platform rely on the dynamic library compiled by Wallet Core, Binding with dart:ffi.

  • wallet_core_bindings_libs contains native dynamic libraries. Windows is not supported at present.
  • For more information, see wallet_core_bindings_libs.
dependencies:
  wallet_core_bindings: version
  wallet_core_bindings_native: version
  wallet_core_bindings_libs: version
import 'package:wallet_core_bindings/wallet_core_bindings.dart';
import 'package:wallet_core_bindings_native/wallet_core_bindings_native.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await WalletCoreBindingsNativeImpl().initialize();
  runApp(const MyApp());
}

Web Assembly

Build WalletCore for WASM,Binding with WASI wasi_snapshot_preview1 and wasm_run.

  • It is suitable for use on platforms that do not support native, such as Web and Windows. However, wasm itself has strong cross-platform features and is not limited to these two platforms.
dependencies:
  wasm_run_flutter: version
  wallet_core_bindings: version
  wallet_core_bindings_wasm: version
  wallet_core_bindings_wasm_assets: version
import 'package:wallet_core_bindings/wallet_core_bindings.dart';
import 'package:wallet_core_bindings_wasm/wallet_core_bindings_wasm.dart';
import 'package:wasm_run_flutter/wasm_run_flutter.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await WasmRunLibrary.setUp(override: false);
  await WalletCoreBindingsWasmImpl().initialize();
  runApp(const MyApp());
}

Usage

wallet_core_bindings provides the complete test cases, you can find usage here. See tests.

Generate

We need to extract the files from wallet-core and generate the corresponding Dart code so that Dart can communicate with TrustWalletCore.

C Bindings

Extract header files in include/TrustWalletCore and generate Dart bindings code.

cd wallet_core_bindings_native
dart run ffigen

Protobuf

Refer to the TrustWalletCore build documentation and complete the steps to generate files. Extract proto files in src/proto and use protoc_plugin to compile them into Dart code.

cd ./proto/TrustWalletCore/
protoc --dart_out=../../wallet_core_bindings/lib/proto/ ./*

License

Commercial license

If you want to use wallet_core_bindings in your commercial app, website or plugin, you need to obtain a commercial license from the author. Please contact [email protected] for more information.Once you obtain the license, your authorization information will appear in the AUTHORIZED.md.

Open-source license

GNU AGPLv3