Note: This is a fork of TonSdk.NET with critical bug fixes and improvements.
Key changes:
- Thread-safety fixes: Replaced
DictionarywithConcurrentDictionaryin LiteClient for concurrent request handling- Bounds checking: Added BOC deserialization safety checks to prevent "Index out of range" errors
- Address struct: Rewritten
Addressas a high-performancestructusingfixed byteandReadOnlySpan<byte>- EF Core integration: New extension package for Entity Framework Core value converters
- Atomic operations: Proper use of
TryAdd/TryRemovefor thread-safe request managementStatus: Currently only Core, Adnl, and EntityFrameworkCore packages are published. Other packages (Client, Contracts, Connect, DeFi) will be added incrementally with improvements.
Core library with types and structures for TON Blockchain. Includes:
Addressas high-performancestructwithfixed bytehash storageCoinsfor TON, Jetton amounts- BOC serialization/deserialization with bounds checking
- Cell, Builder, Slice
- Mnemonic (BIP39 and TON standards)
- Ed25519 signing
dotnet add package Dzeta.TonSdk.CoreThread-safe ADNL client and LiteClient for interacting with TON blockchain nodes. Includes:
- ADNL protocol implementation
- LiteClient with concurrent request handling (
ConcurrentDictionary) - Atomic operations for safe multi-threaded access
- Block and account state queries
dotnet add package Dzeta.TonSdk.AdnlEntity Framework Core integration for TonSdk.Core types. Includes:
AddressValueConverter- stores Address as 36 bytes (4 bytes workchain + 32 bytes hash)AddressStringValueConverter- stores Address as human-readable string (~80 bytes)- Extension methods for easy configuration
dotnet add package Dzeta.TonSdk.Core.EntityFrameworkCoreUsage example:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Wallet>()
.Property(e => e.Address)
.HasAddressConversion<Wallet>(); // Binary storage (36 bytes)
}- Builder, Cell, Slice
- BOC (de)serialization with bounds checking
- Hashmap(E) (dictionary) (de)serialization
- Mnemonic BIP39 standard
- Mnemonic TON standard
- Coins (class for TON, JETTON, etc.)
- Address (struct with
fixed bytefor high performance) - Message layouts (MessageX, etc.)
- Popular structures from block.tlb
- Ed25519 signing of transactions
- ADNL client (thread-safe)
- Lite client over ADNL client (thread-safe)
- EF Core value converters for TON types
- Client with HTTP API (coming soon)
- Contracts abstraction (coming soon)
- TON Connect 2.0 (coming soon)
- DeFi integrations (coming soon)
Install via NuGet Package Manager or .NET CLI:
dotnet add package Dzeta.TonSdk.Core
dotnet add package Dzeta.TonSdk.Adnl
dotnet add package Dzeta.TonSdk.Core.EntityFrameworkCore # Optional, for EF Core usersusing TonSdk.Core;
// Parse address
var address = new Address("EQDk2VTvn04SUKJrW7rXahzdF8_Qi6utb0wj43InCu9vdjrR");
// Get raw format
string raw = address.ToRaw(); // "0:e4d954ef9f4e1250a26b5bbad76a1cdd17cfc08babaddf4c23e37227..."
// Get workchain and hash
int workchain = address.Workchain; // 0
ReadOnlySpan<byte> hash = address.Hash; // 32 bytesusing TonSdk.Adnl;
using TonSdk.Adnl.LiteClient;
var client = new LiteClient(LiteClientOptions.GetFromUrl("https://ton-blockchain.github.io/global.config.json"));
await client.Connect();
var masterchain = await client.GetMasterchainInfo();
Console.WriteLine($"Last block: {masterchain.Last.Seqno}");using TonSdk.Core;
using TonSdk.Core.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
public class Wallet
{
public int Id { get; set; }
public Address Address { get; set; } // TON address stored efficiently
public decimal Balance { get; set; }
}
public class MyDbContext : DbContext
{
public DbSet<Wallet> Wallets { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Binary storage (36 bytes) - recommended
modelBuilder.Entity<Wallet>()
.Property(e => e.Address)
.HasAddressConversion<Wallet>();
}
}MIT License