Skip to main content

JavaScript SDK

The @mintlayer/sdk package is the JavaScript/TypeScript SDK for Mintlayer. It provides a typed Client class that builds and signs transactions through a pluggable account provider, by default the Mojito Wallet browser extension, or standalone key-based providers for Node.js scripts, bots, and tests.

npm install @mintlayer/sdk
  • Works in browsers (dApps) and Node.js (scripts, faucets, bots)
  • Type-safe transaction builders for all major Mintlayer transaction types
  • Pluggable architecture: swap the wallet extension for private keys or a mnemonic seed without changing application code
  • Source: github.com/mintlayer/mintlayer-connect-sdk

Architecture

The SDK is built around three interfaces. Everything else is an implementation you can replace.

ComponentPurpose
ClientHigh-level API: connection lifecycle, balances, delegations, orders, and ready-made methods for every transaction type
AccountProviderWhere addresses come from and who signs. Implementations: MojitoAccountProvider (browser extension, default), PrivateKeyAccountProvider, MnemonicAccountProvider, or your own
ApiProviderChain-data backend used for UTXO selection, fees, and queries. MintlayerApiProvider targets the public API
SignerLow-level transaction signing with explicit private keys (also usable on its own)
TransactionTransaction object: JSON/binary/hex representations, fee, UTXO selection
WalletStateHeadless wallet state: transaction log, UTXOs, and balances derived from your own sync source

Quick start

Connect to the user's Mojito wallet and send coins:

import { Client } from '@mintlayer/sdk';

const client = await Client.create({ network: 'testnet' });

await client.connect(); // opens the wallet connection prompt

const signedTx = await client.transfer({
to: 'tmt1q9mfg7d6ul2nt5yhmm7l7r6wwyqkd822rymr83uc',
amount: 10, // human-readable units
});

Without a browser extension (Node.js, scripts, tests), derive an account from a mnemonic or explicit keys:

import { Client, MnemonicAccountProvider } from '@mintlayer/sdk';

const client = await Client.create({
network: 'testnet',
accountProvider: new MnemonicAccountProvider('word1 word2 ... word12', 'testnet'),
});

const signedTx = await client.transfer({ to: 'tmt1q...', amount: 10 });

Guides

GuideContents
SDK ClientClient creation, connection lifecycle, network, events, queries
Account providersMojito, private-key, mnemonic, and custom providers
TransactionsBuild, sign, broadcast; fees; HTLCs; message signing
TokensFungible tokens and NFTs: issuance, minting, freezing
StakingDelegation creation, staking, withdrawal
OrdersOn-chain trading orders: create, fill, conclude
Wallet stateHeadless UTXO/balance tracking for bots and scanners

Amounts passed to the SDK are human-readable values; the SDK converts them to atoms internally. For display, use the exported helpers atomsToDecimal, decimalsToAtoms, and decimals.