Skip to main content

Migrating from the WASM wrappers

The native bindings exist for the environments where the WASM wrappers cannot run: React Native and Expo apps, whose Hermes engine has no WebAssembly global. Browsers and Node.js should stay on the WASM path (JavaScript SDK) — it is unchanged.

What stays the same​

  • Function names. The exported surface mirrors the WASM wrappers one-for-one — makeDefaultAccountPrivkey, encodeOutputTransfer, encodeWitness, and the rest keep their names and parameter order.
  • Blob formats. Keys, inputs, outputs, witnesses and transactions are the same runtime SCALE bytes. A blob captured from @mintlayer/wasm-lib decodes identically through the native bindings, and vice versa.
  • Outputs. Byte-for-byte identical to @mintlayer/wasm-lib 1.4.0, verified in CI (see Overview).

What changes​

WASM (JavaScript)Native (Kotlin / Swift)
Uint8Array blobsByteArray / Data (convert at your RN bridge boundary)
JS numbers for amountsdecimal atom strings ("50000000000" for 500 ML)
npm package @mintlayer/wasm-libAAR (Android) / SPM package (iOS), see Installation
requires a WebAssembly globalnone; pure native libraries
error via thrown values / exceptionstyped BindingsException / BindingsError

The amounts change is the one that needs code review everywhere: JavaScript loses precision above 2⁵³, so the WASM wrappers accept JS numbers only for small values, while the native bindings take the exact 128-bit atom count as a decimal string. Convert once at the edge of your app (a formatAmount/parseAmount helper) and keep atoms as the in-app representation.

// Before (WASM): amount as a JS number of atoms
encodeOutputTransfer(50000000000, address, 'testnet');
// After (Kotlin): amount as a decimal atom string
encodeOutputTransfer("50000000000", address, Network.TESTNET)

Custom derivation is native-only​

mnemonicToSeed is the one function in the surface with no WASM counterpart: @mintlayer/wasm-lib exposes no raw seed hash. JavaScript consumers doing custom derivation keep their own BIP39 stack (for example @scure/bip39); on Android and iOS the bindings provide the native path — PBKDF2-HMAC-SHA512 compiled into the artifacts, single-digit milliseconds instead of seconds. See Getting started.

Transaction intents in one call​

An intent flow on the WASM side composes five steps by hand: get_transaction_id on the signed transaction, make_transaction_intent_message_to_sign, one sign_challenge per input key, encode_signed_transaction_intent, and a final verify_transaction_intent. The native bindings add signTransactionIntent, which runs the same steps — including the self-verification — in one call, and produces byte-identical output for the same inputs (see Messages and intents).

// Before (WASM): five intent steps, by hand
const txId = get_transaction_id(signedTx, true);
const message = make_transaction_intent_message_to_sign(intent, txId);
const signatures = inputKeys.map((key) => sign_challenge(key, message));
const encodedIntent = encode_signed_transaction_intent(message, signatures);
verify_transaction_intent(message, encodedIntent, inputDestinations, Network.Testnet);
// After (Kotlin): one call, self-verifying
val encodedIntent = signTransactionIntent(intent, signedTx, inputKeys, inputDestinations, Network.TESTNET)

Porting checklist​

  1. Swap the dependency: AAR for Android, MintlayerWalletBindings product for iOS (Installation).
  2. Update imports: org.mintlayer.wallet.bindings.* / import MintlayerWalletBindings; the function names are unchanged.
  3. Replace Uint8Array with ByteArray/Data at the React Native bridge (or native) boundary.
  4. Move amounts to decimal atom strings.
  5. Handle the typed errors instead of generic exceptions (Reference: Errors).
  6. Re-run your derivation against the public test vectors — the address tmt1qyxqfq37rra32sq6zhayqcpjwh4trc07mcfardwt must appear for the test mnemonic on testnet.

If your app used the high-level connect-sdk Client, note that the bindings are the primitive layer beneath it: there is no Client, no UTXO selection and no broadcast. Keep the connect-sdk patterns for chain data and port only the key/signing/encoding calls.