Detalhes do pacote

@ton-community/ton-ledger

ton-community35.4kMIT7.3.0

This library allows you to connect to a ledger device and with with TON from browser (only Chrome), NodeJS and React Native.

readme (leia-me)

TON Ledger Library

This library allows you to connect to a ledger device and with with TON from browser (only Chrome), NodeJS and React Native.

How to install

To add library to your project execute:

yarn add @ton-community/ton-ledger

Connecting to a Device

First you need to select transport library for you environment.

Browser:

Node:

React Native:

After connecting to a device create a TonTransport instance:

import { TonTransport } from '@ton-community/ton-ledger';
let transport = new TonTransport(device);

Deriviation Path

For hardware wallets you need to specify deriviation path of your account for TON it is specified as:

function pathForAccount(testnet: boolean, workchain: number, account: number) {
    let network = testnet ? 1 : 0;
    let chain = workchain === -1 ? 255 : 0;
    return [44, 607, network, chain, account, 0]; // Last zero is reserved for alternative wallet contracts
}

You can specify any path that starts with [44, 607], but it could be incompatible with other apps.

Get an Address and Public Key

To get an address without confimration on device you can perform next things:

let testnet = true;
let workchain = 0;
let accountIndex = 0;
let bounceable = false;
let path = pathForAccount(testnet, workchain, accountIndex);
let response = await transport.getAddress(path, { chain, bounceable, testOnly: testnet });
let publiKey: Buffer = response.publicKey;
let address: string = response.address;

Validate Address

The same as getting address, but returns address and key only when user confirms that address on the screen is correct. This method usually used after the non-confirming one and displaying address in dApp ad then requesting address validation.

let testnet = true;
let workchain = 0;
let accountIndex = 0;
let bounceable = false;
let path = pathForAccount(testnet, workchain, accountIndex);
let response = await transport.validateAddress(path, { chain, bounceable, testOnly: testnet });
let publiKey: Buffer = response.publicKey;
let address: string = response.address;

Sign simple transaction

Ledger Nanoapp works with Wallet v4 for now, we recommend you to continue to use it:

import { WalletV4Contract, WalletV4Source } from 'ton';
import { TonPayloadFormat } from '@ton-community/ton-ledger';
import { TonClient, Address, SendMode, toNano } from 'ton-core';

let client = new TonClient({ endpoint: 'https://toncenter.com/api/v2/jsonRPC' });
let source = WalletV4Source.create({ workchain: 0, publicKey: deviceAddress.publicKey });
let contract = new WalletV4Contract(address, source);
let seqno = await contract.getSeqNo();

// Parameters
let path: number[]; // Account path from above
let to: Address = Address.parse('...'); // Destination
let amount: bigint = toNano('100'); // Send 100 TON
let sendMode = SendMode.IGNORE_ERRORS | SendMode.PAY_GAS_SEPARATLY;
let timeout = Math.floor((Date.now() / 1000) + 60);
let bounce = false;
let payload: TonPayloadFormat | null = null; // See below

// Signing on device
let signed = await transport.signTransaction(path, {
    to,
    sendMode,
    amount,
    seqno,
    timeout: Math.floor((Date.now() / 1000) + 60),
    bounce,
    payload: payload ? payload : undefined
});

// Send transaction to the network
await c.sendExternalMessage(contract, signed);

Payload formats

Transaction with a comment

Comments are limited to ASCII-only symbols and 127 letters. Anything above would be automatically downgraded to Blind Signing Mode that you want to avoid at all cost.

const payload: TonPayloadFormat = {
    type: 'comment',
    text: 'Deposit'
};

Jetton transfer

const payload: TonPayloadFormat = {
    type: 'jetton-transfer',
    queryId: null, // null will be replaced with 0; you can pass any value of the BigInt type
    amount: 1n,
    destination: Address.parse('EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c'),
    responseDestination: Address.parse('EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c'),
    customPayload: null, // you can pass any value of the Cell type
    forwardAmount: 0n,
    forwardPayload: null // you can pass any value of the Cell type
};

NFT transfer

const payload: TonPayloadFormat = {
    type: 'nft-transfer',
    queryId: null, // null will be replaced with 0; you can pass any value of the BigInt type
    newOwner: Address.parse('EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c'),
    responseDestination: Address.parse('EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c'),
    customPayload: null, // you can pass any value of the Cell type
    forwardAmount: 0n,
    forwardPayload: null // you can pass any value of the Cell type
};

License

MIT

changelog (log de mudanças)

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[7.3.0] - 2025-08-21

  • New jettons
  • Fixed includeWalletOp

[7.2.0] - 2025-02-07

  • Added support for TON Ledger App 2.2.0 features, including:
  • Hardcoded jettons
  • Wallet specifiers support in more methods

[7.1.0] - Not released

Added

  • Added parseMessage helper to parse messages into TON Ledger App format
  • Added support for TON Ledger App 2.1.0 features, including:
  • New message types
  • Wallet specifiers (subwallet ID and wallet op inclusion for v4 support)
  • getSettings method

[7.0.1] - 2024-01-17

Fixed

  • Fixed incorrect VarUInt encoding of 0 (0 nanoTON, 0 jetton units, etc)

[7.0.0] - 2023-09-15

Changed

  • Switched ton-core and ton-crypto to @ton/core and @ton/crypto

[6.0.0] - 2023-07-11

Removed

  • Removed unsafe payload format

[5.0.0] - 2023-06-29

Removed

  • Removed decimals and ticker from jetton-transfer request

[4.1.0] - 2023-06-16

Added

  • Added signData method along with SignDataRequest type

[4.0.1] - 2023-06-16

Fixed

  • Fixed the address flags communication

[4.0.0] - 2023-06-09

Added

  • Added payload types for NFT and Jetton transfers
  • Added TON Connect 2.0 address proof request

Removed

  • Removed old payload types except for comment and unsafe

Changed

  • Updated dependencies
  • Changed APDU format to be the same as the latest embedded app version (breaking change)

[3.0.0] - 2023-01-08

Changed

  • Migration to ton-core

[2.3.2]

  • Update documentation