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.
$ dotnet add package Ton.HttpClientA 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?
Note: This is a complete rewrite replacing the legacy TonSdk.NET. It provides a cleaner, more maintainable codebase with improved compatibility.
| Package | Version | Description |
|---|---|---|
| Ton.Core | Core primitives: Cells, BOC, Addresses, Types | |
| Ton.Crypto | Ed25519, Mnemonics (BIP39), SHA, HMAC | |
| Ton.Contracts | Smart contracts: Wallets, Jettons, NFTs |
| Ton.HttpClient | HTTP API clients (Toncenter v2/v4) |
dotnet add package Ton.Core
dotnet add package Ton.Crypto
dotnet add package Ton.Contracts
dotnet add package Ton.HttpClientusing 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!");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 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}");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 | SendIgnoreErrorsSee TON Documentation on Message Modes for details.
dotnet testTest Coverage:
Total: 360 passing unit + integration tests
All tests validate compatibility with the TON JavaScript SDK's behavior.
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)
An interactive console app for testing wallet operations:
cd tools/WalletPlayground
dotnet runFeatures:
Contributions are welcome! This project aims for API compatibility with the TON JavaScript SDK.
MIT License - see LICENSE file for details.