11 releases (4 breaking)

0.22.4 Dec 13, 2024
0.22.3 Dec 13, 2024
0.21.1 Nov 27, 2024
0.20.3 Oct 30, 2024
0.18.1 Sep 18, 2024

#20 in #ton

Download history 225/week @ 2024-09-13 185/week @ 2024-09-20 266/week @ 2024-09-27 162/week @ 2024-10-04 185/week @ 2024-10-11 419/week @ 2024-10-18 664/week @ 2024-10-25 253/week @ 2024-11-01 212/week @ 2024-11-08 256/week @ 2024-11-15 903/week @ 2024-11-22 454/week @ 2024-11-29 625/week @ 2024-12-06 415/week @ 2024-12-13

2,446 downloads per month
Used in 2 crates

MIT and LGPL-3.0+

275KB
7K SLoC

Rust SDK for The Open Network

Rust SDK for The Open Network

Features

  • Support parsing and generation of Cell and BagOfCell for more convenient interaction with data structures
  • Support of existing Wallet versions
  • Derive wallet address
  • Support of TON Mnemonics
  • NaCl-compatible Ed25519 signing of transactions

Usage

To use this library in your Rust application, add the following to your Cargo.toml file:

[dependencies]
tonlib-core = "version"

Then, in your Rust code, you can import the library with:

use tonlib_core;

Package contents

Cell

Data structures and helpers for building and parsing Cell and Bag of Cells. See the documentation on ton.org for details.

Message

Data structures, builders, and parsers for Message See the documentation on ton.org for details.

Includes standard messages for Jetton, NFT, and Soulbound NFT, specified by TON Enhancement Proposal.

Mnemonic

Data structure to store mnemonic.

Types

Data structures for storage and easy conversion of Ton Smart-contract Address and Ton Transaction Id

Wallet

Data structure for deriving wallet addresses.

Usage examples

Cell

Creating a Cell and writing data to it:

use anyhow::anyhow;
use tonlib_core::TonAddress;
use tonlib_core::cell::CellBuilder;

fn write_cell() -> anyhow::Result<()> {
let mut writer = CellBuilder::new();
let addr = TonAddress::from_base64_url("EQDk2VTvn04SUKJrW7rXahzdF8_Qi6utb0wj43InCu9vdjrR")?;
let cell = writer
    .store_u32(32, 0xFAD45AADu32)?
    .store_bit(true)?
    .store_u8(8, 234u8)?
    .store_slice(&[0xFA, 0xD4, 0x5A, 0xAD, 0xAA, 0x12, 0xFF, 0x45])?
    .store_address(&addr)?
    .store_string("Hello, TON")?
    .build()?;
    # Ok(())
}

Reading data from a Cell:

use tonlib_core::cell::Cell;
fn read_cell(cell: Cell) -> anyhow::Result<()> {
    let mut reader = cell.parser();
    let u32_value = reader.load_u32(32)?;
    let bit_value = reader.load_bit()?;
    let u8_value = reader.load_u8(8)?;
    let bytes_value = reader.load_bytes(8)?;
    let address_value = reader.load_address()?;
    let str_value = reader.ensure_empty()?;
    Ok(())
}

Dependencies

~2.9–4MB
~73K SLoC