Ton.Crypto 0.1.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package Ton.Crypto --version 0.1.5
                    
NuGet\Install-Package Ton.Crypto -Version 0.1.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ton.Crypto" Version="0.1.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ton.Crypto" Version="0.1.5" />
                    
Directory.Packages.props
<PackageReference Include="Ton.Crypto" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Ton.Crypto --version 0.1.5
                    
#r "nuget: Ton.Crypto, 0.1.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Ton.Crypto@0.1.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Ton.Crypto&version=0.1.5
                    
Install as a Cake Addin
#tool nuget:?package=Ton.Crypto&version=0.1.5
                    
Install as a Cake Tool

Ton.NET

A modern, comprehensive .NET SDK for the TON (The Open Network) blockchain. Built from scratch with clean architecture, targeting compatibility with the official TON JavaScript SDK.

Why Ton.NET?

  • โœจ Modern C# 12 with nullable reference types
  • ๐ŸŽฏ Targeting API compatibility with TON JS SDK
  • ๐Ÿ”’ Type-safe primitives and TL-B structures
  • ๐Ÿงช 517+ tests with full coverage
  • ๐Ÿ“ฆ Modular architecture
  • ๐Ÿš€ Production-ready

Note: This is a complete rewrite replacing the legacy TonSdk.NET. It provides a cleaner, more maintainable codebase with improved compatibility.

๐Ÿ“ฆ Packages

Package Version Description
Ton.Core NuGet Core primitives: Cells, BOC, Addresses, Types
Ton.Crypto NuGet Ed25519, Mnemonics (BIP39), SHA, HMAC
Ton.Contracts NuGet Smart contracts: Wallets, Jettons, NFTs
Ton.HttpClient NuGet HTTP API clients (Toncenter v2/v4)
Ton.Adnl NuGet ADNL protocol for direct node communication
Ton.LiteClient NuGet High-level Lite Client for TON blockchain

๐Ÿš€ Quick Start

dotnet add package Ton.Core
dotnet add package Ton.Crypto
dotnet add package Ton.Contracts
dotnet add package Ton.HttpClient
dotnet add package Ton.Adnl
dotnet add package Ton.LiteClient

Create and Use a Wallet

using Ton.Contracts.Wallets.V5;
using Ton.Crypto.Mnemonic;
using Ton.HttpClient;
using Ton.Core.Boc;
using Ton.Core.Addresses;
using Ton.Core.Types;

// Generate mnemonic
var mnemonic = Mnemonic.New(); // 24 words
var keyPair = Mnemonic.ToWalletKey(mnemonic);

// Create WalletV5R1
var wallet = WalletV5R1.Create(
    workchain: 0, 
    publicKey: keyPair.PublicKey
);
Console.WriteLine($"Address: {wallet.Address}");

// Connect to blockchain
var client = new TonClient(new TonClientParameters 
{ 
    Endpoint = "https://toncenter.com/api/v2/jsonRPC",
    ApiKey = "your-api-key" // optional
});

var opened = client.Open(wallet);

// Get balance
var balance = await opened.Contract.GetBalanceAsync(opened.Provider);
Console.WriteLine($"Balance: {balance / 1_000_000_000m} TON");

// Get seqno
var seqno = await opened.Contract.GetSeqnoAsync(opened.Provider);

// Create message with comment
var body = Builder.BeginCell()
    .StoreUint(0, 32) // text comment opcode
    .StoreStringTail("Hello TON!")
    .EndCell();

var message = new MessageRelaxed(
    new CommonMessageInfoRelaxed.Internal(
        IhrDisabled: true,
        Bounce: true,
        Bounced: false,
        Src: null,
        Dest: Address.Parse("EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N"),
        Value: new CurrencyCollection(1_000_000_000), // 1 TON
        IhrFee: 0,
        ForwardFee: 0,
        CreatedLt: 0,
        CreatedAt: 0
    ),
    body,
    StateInit: null
);

// Send transfer
var transfer = wallet.CreateTransfer(
    seqno: seqno,
    secretKey: keyPair.SecretKey,
    messages: new List<MessageRelaxed> { message },
    sendMode: SendMode.SendPayFwdFeesSeparately | SendMode.SendIgnoreErrors
);

await opened.Contract.SendAsync(opened.Provider, transfer);
Console.WriteLine("Transfer sent!");

Working with Cells and BOC

using Ton.Core.Boc;

// Create a cell
var cell = Builder.BeginCell()
    .StoreUint(123, 32)
    .StoreAddress(Address.Parse("EQ..."))
    .StoreStringTail("Hello")
    .EndCell();

// Serialize to BOC
var boc = cell.ToBoc();

// Deserialize from BOC
var cells = Cell.FromBoc(boc);
var loadedCell = cells[0];

// Read from cell
var slice = loadedCell.BeginParse();
var number = slice.LoadUint(32);
var address = slice.LoadAddress();
var text = slice.LoadStringTail();

Using TonClient4 (v4 API)

using Ton.HttpClient;

var client = new TonClient4(new TonClient4Parameters
{
    Endpoint = "https://mainnet-v4.tonhubapi.com"
});

// Get last block
var lastBlock = await client.GetLastBlockAsync();
Console.WriteLine($"Last block: {lastBlock.Last.Seqno}");

// Get account state
var account = await client.GetAccountAsync(
    lastBlock.Last.Seqno, 
    Address.Parse("EQ...")
);

Console.WriteLine($"Balance: {account.Account.Balance}");

Send Modes

TON blockchain supports various send modes that control message behavior:

// Basic send mode - pay fees from message value
SendMode.SendDefault

// Pay fees separately from message value
SendMode.SendPayFwdFeesSeparately

// Ignore errors during action phase
SendMode.SendIgnoreErrors

// Bounce transaction on action failure (no effect with SendIgnoreErrors)
SendMode.SendBounceIfActionFail

// Destroy contract if balance reaches zero
SendMode.SendDestroyIfZero

// Carry remaining inbound message value (+64)
SendMode.SendRemainingValue

// Carry all remaining contract balance (+128)
SendMode.SendRemainingBalance

// Common combinations:
// - Standard transfer: SendPayFwdFeesSeparately | SendIgnoreErrors
// - Send all balance: SendRemainingBalance | SendDestroyIfZero | SendIgnoreErrors

See TON Documentation on Message Modes for details.

๐Ÿ“‹ Implementation Status

โœ… Completed

  • Core Primitives: Cell, BOC serialization, Address, BitString, Dictionary
  • TL-B Types: All 37 types (Message, Transaction, Account, StateInit, etc.)
  • Cryptography: Ed25519, BIP39 mnemonics, SHA-256/512, HMAC, PBKDF2
  • HTTP Clients: Toncenter API v2 and v4
  • ADNL Protocol: TL serialization, AES-CTR encryption, packet framing, TCP client
  • Wallets: V5R1 (transfers, extensions, auth modes)
  • Contract System: IContract, IContractProvider, OpenedContract

๐Ÿšง In Progress

  • Lite Client: High-level API on top of ADNL for querying TON nodes
  • Wallets: V1R1, V1R2, V1R3, V2R1, V2R2, V3R1, V3R2, V4R1, V4R2
  • Jettons: JettonMaster, JettonWallet
  • NFTs: NFTCollection, NFTItem

๐Ÿงช Testing

dotnet test

Test Coverage:

  • 327 tests in Ton.Core.Tests (BOC, TL-B, Dictionaries, Contracts)
  • 18 tests in Ton.Crypto.Tests (Mnemonic, Ed25519, Hashing)
  • 15 tests in Ton.HttpClient.Tests (TonClient v2/v4)
  • 157 tests in Ton.Adnl.Tests (TL serialization, crypto, packets, ADNL client)

Total: 517 passing unit + integration tests

All tests validate compatibility with the TON JavaScript SDK's behavior.

๐Ÿ“š Documentation

๐Ÿ—๏ธ Architecture

Ton.Core          โ†’ Core blockchain primitives (Cell, Address, BOC, etc.)
Ton.Crypto        โ†’ Cryptographic operations (Ed25519, Mnemonics)
Ton.Contracts     โ†’ Smart contract implementations (Wallets, Jettons, NFTs)
Ton.HttpClient    โ†’ HTTP API clients (Toncenter v2/v4)
Ton.Adnl          โ†’ ADNL protocol for direct node communication

Key Design Principles

  • Type Safety: Nullable reference types, records, and pattern matching
  • Zero Dependencies: Only System.Text.Json for HTTP clients
  • Performance: Efficient cell serialization with proper hashing
  • Compatibility: API designed to match TON JS SDK patterns
  • Testability: Every feature has corresponding tests from JS SDK

๐Ÿ› ๏ธ Tools

Wallet Playground

An interactive console app for testing wallet operations:

cd tools/WalletPlayground
dotnet run

Features:

  • Generate or load mnemonic phrases
  • Create WalletV5R1 instances
  • Check balance and seqno
  • Send transfers with comments
  • Deploy wallets
  • Send all remaining balance (destroy wallet)

๐Ÿค Contributing

Contributions are welcome! This project aims for API compatibility with the TON JavaScript SDK.

๐Ÿ“„ License

MIT License - see LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Ton.Crypto:

Package Downloads
Ton.HttpClient

TON blockchain HTTP client library for .NET - Toncenter API v2/v4, wallet contracts (V1-V5), jettons, multisig. 1:1 API compatibility with @ton/ton JavaScript library.

Ton.Contracts

TON smart contract implementations for .NET - Wallet contracts (V1-V5), Jettons, and NFTs. 1:1 API compatibility with @ton/ton JavaScript library.

Ton.Adnl

ADNL (Abstract Datagram Network Layer) client for TON blockchain - Direct node communication with TL serialization, encryption, and auto-generated schema. Enables lite client implementation for TON.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.7 707 12/2/2025
0.2.6 367 11/16/2025
0.2.5 251 11/6/2025
0.2.4 257 10/30/2025
0.2.3 248 10/30/2025
0.2.2 243 10/29/2025
0.2.1 247 10/29/2025
0.2.0 218 10/29/2025
0.1.5 228 10/28/2025
0.1.4 213 10/28/2025
0.1.3 192 10/27/2025
0.1.2 194 10/27/2025
0.1.1 186 10/27/2025
0.1.0 163 10/26/2025
0.0.13 158 10/26/2025
0.0.12 156 10/26/2025
0.0.11 159 10/26/2025
0.0.10 157 10/26/2025
0.0.9 161 10/26/2025
0.0.8 158 10/26/2025
0.0.7 161 10/26/2025
0.0.6 157 10/26/2025
0.0.5 162 10/26/2025
0.0.4 161 10/26/2025
0.0.3 160 10/26/2025