tonutils

Creator: coderz1093

Last updated:

0 purchases

tonutils Image
tonutils Images

Languages

Categories

Add to Cart

Description:

tonutils

πŸ’Ž Dart/Flutter library for TON blockchain #
A composable and versatile library for all things TON!


WARNING: Some underlying APIs of this library are subject to change in near future, so it's advised to pin down specific minor version rather than specifying ranges in your pubspec.yaml. At least until we hit stable 1.0.0 release.

If you love this library and want to support its development you can donate any amount of coins to this TON address ☺️EQDew1rvHuMmMkmxG_fQahGymzIOF2_9TpgLftMUuxpKLE_u
To donate in other cryptocurrencies, use:
🍰 Features #

jsonRPC client to work with TON network: lib/client
Cell, Slice, Builder, and BOC (de)serialization: lib/dataformat
Support for popular structures from block.tlb: lib/dataformat
Support of TON base64 addresses: lib/dataformat
Support of HashmapE: lib/dataformat
Support of TON & BIP39 Mnemonics: lib/mnemonic
Support of wallets (v3, v3r2, v4r2): lib/wallet
Ed25519 signing of transactions and crypto primitives: lib/crypto
Workings with Jettons: lib/jetton
Workings with NFTs: lib/nft
...and much more!

πŸš€ Usage #
Install via dart pub: #
dart pub add tonutils
copied to clipboard
Get it all or use a few #
Most common way is to import the whole library and cherry-pick the needed elements:
import 'package:tonutils/tonutils.dart' show Mnemonic;
copied to clipboard
Alternatively, consider using only the sub-libraries if you know precisely what you need:
import 'package:tonutils/mnemonic.dart'; // provides Mnemonic and WordList classes
copied to clipboard
All the individual things you can import and use are listed in the root of lib/ folder.
RPC Client (Toncenter API) #
You can use one of the public endpoints:

Mainnet: https://toncenter.com/api/v2/jsonRPC
Testnet: https://testnet.toncenter.com/api/v2/jsonRPC

Or host your own instance of TON HTTP API.
// Client uses testnet by default:
final testnetClient = TonJsonRpc();

// But you can specify an alternative endpoint, say, for mainnet:
final client = TonJsonRpc('https://toncenter.com/api/v2/jsonRPC');

// You can also specify an API key obtained from https://t.me/tonapibot!

// Generate a new key pair
var mnemonics = Mnemonic.generate();
var keyPair = Mnemonic.toKeyPair(mnemonics);

// Wallet contracts use workchain = 0, but this can be overriden
var wallet = WalletContractV4R2.create(publicKey: keyPair.publicKey);

// Opening a wallet contract (this specifies the TonJsonRpc as a ContractProvider)
var openedContract = client.open(wallet);

// Get the balance of the contract
var balance = await openedContract.getBalance();
print(balance);

// Create a transfer
var seqno = await openedContract.getSeqno();
var transfer = openedContract.createTransfer(
seqno: seqno,
privateKey: keyPair.privateKey,
messages: [
internal(
to: SiaString('EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N'),
value: SbiString('1.5'),
body: ScString('Hello, world!'),
)
],
);
print(transfer.toString());
copied to clipboard
As you can see from this example, this library is 90% compatible with the API of the ton-core and ton-community TypeScript libraries. The main sources of divergence are types: this library uses sealed classes and extends from them to provide union-like types, while maintaining compile-time checked type safety and soundness.
But worry not β€” editor hints in VS Code, Emacs, Vim, NeoVim, Helix and other editors with Language Server Provider (LSP) support won't leave you astray and provide all the answers if you ever find yourself stuck.
πŸ“Ί Videos #
Playlist with examples on YouTube: link
πŸ”§ Tests #
Tests are positioned to mirror the structure inside lib/src/, and grouped by the relative path from test folder to the test file (excluding the _test.dart suffix).
Examples:

Tests for mnemonics are located in the file test/mnemonic/mnemonic_test.dart, and the test group name is mnemonic/mnemonic
Tests for addresses are located in the file test/dataformat/address/address_test.dart, and the test group name is dataformat/address/address

To invoke a group of tests by their name, run:
dart test -N 'group name'
copied to clipboard
For example, to test mnemonics:
dart test -N 'mnemonic/mnemonic'
copied to clipboard
πŸ“„ License #
Apache License 2.0

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.