Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Rust SDK for The Open Network
Rust SDK for The Open Network
Features
- Rust SDK for The Open Network
- Using
tonlibjsonas data provider - Support parsing and generation of Cells methods for more convenient interaction with data structures
- Support of Wallet versions (3, 3 revision 2, 4 revision 2)
- Derive wallet address
- Support of TON Mnemonics
- NaCL-compatible Ed25519 signing of transactions
- Support jetton functions: getting of jetton data and wallet address for jetton
- Support internal and external jetton metadata loading
- Connection pooling & retries support for better server-level interaction
- Support of IPFS jetton metadata
Dependencies
tonlib-sys - https://github.com/ston-fi/tonlib-sys
Build library
You can build the library using the following command:
Usage
To use this library in your Rust application, add the following to your Cargo.toml file:
[]
= "0.5.0"
Then, in your Rust code, you can import the library with:
use tonlib_rs;
Cell
Creating a Cell and writing data to it:
let mut writer = new;
let addr = from_base64_url?;
let cell = writer
.store_u32?
.store_bit?
.store_u8?
.store_slice?
.store_address?
.store_string?
.build?;
Reading data from a Cell:
let mut reader = cell.parser;
let u32_value = reader.load_u32?;
let bit_value = reader.load_bit?;
let u8_value = reader.load_u8?;
let bytes_value = reader.load_bytes?;
let address_value = reader.load_address?;
let str_value = reader.load_string?;
TON blockchain client
To call methods, create a client:
set_log_verbosity_level; //setup of logging level
let client = new
.with_pool_size
.with_keystore_dir
.build
.await?;
TonClient::set_log_verbosity_level(2); sets the logging level.
By default, the connection is made to mainnet. But you can also specify a test network when creating the client:
let client = new
.with_connection_params
.with_pool_size
.build
.await?;
After creating the client, you can call methods on the TON blockchain:
let info: BlocksMasterchainInfo = client.get_masterchain_info.await?;
println!;
let block_id = BlockId ;
let block_id_ext = client.lookup_block.await?;
println!;
let block_shards: BlocksShards = client.get_block_shards.await?;
let mut shards = block_shards.shards.clone;
println!;
shards.insert;
for shard in &shards
You can get the account state for any contract:
let r = client
.get_account_state
.await;
Working with contracts and jettons
Methods for working with tokens and wallets:
let master_contract = new;
let jetton_data = master_contract.get_jetton_data.await?;
let wallet_contract = new;
let wallet_data = wallet_contract.get_wallet_data.await?;
To load the metadata of the token, there is JettonContentLoader:
let loader = new?;
let content_res = loader.load.await?;
Get the wallet address for the token:
let contract = new;
let owner_address = from_base64_url?;
let wallet_address = contract.get_wallet_address.await?;
Send message to TON
Create key pair from secret phrase (mnemonic)
let mnemonic_str = "<your secret phrase composed of 24 words>"
let mnemonic: Mnemonic = from_str.unwrap;
let key_pair: KeyPair = mnemonic.to_key_pair.unwrap;
And now you are ready to send transfer messages to TON blockchain.
Create a jetton transfer:
const SELF_ADDR: TonAddress = "<wallet address>"
.parse
.unwrap;
const JETTON_MASTER_ADDR: TonAddress = "EQDCJL0iQHofcBBvFBHdVG233Ri2V4kCNFgfRT-gqAd3Oc86"
.parse
.unwrap;
let client = default.await?;
let jetton_master = new;
let self_jetton_wallet_addr = jetton_master.get_wallet_address.await?;
let wallet = derive?;
let dest: TonAddress = "<destination wallet address>".parse?;
let jetton_amount = from;
let jetton_transfer = new
.with_query_id
.with_response_destination
.build?;
let ton_amount = from; // 0.2 TON
let transfer = new
.with_data
.build?;
let now = now
.duration_since?
.as_secs? as u32;
let body = wallet.create_external_body?;
let signed = wallet.sign_external_body?;
let wrapped = wallet.wrap_signed_body?;
let boc = from_root;
let tx = boc.serialize?;
let hash = client.send_raw_message_return_hash.await?;
Create a simple transfer:
let client = default.await?;
let wallet = derive?;
let dest: TonAddress = "<destination wallet address>".parse?;
let value = from; // 0.01 TON
let transfer = new.build?;
let now = now
.duration_since?
.as_secs? as u32;
let body = wallet.create_external_body?;
let signed = wallet.sign_external_body?;
let wrapped = wallet.wrap_signed_body?;
let boc = from_root;
let tx = boc.serialize?
let hash = client.send_raw_message_return_hash.await?;
Contributing
If you want to contribute to this library, please feel free to open a pull request on GitHub.
License
This library is licensed under the MIT license. See the LICENSE file for details.