#ton #address #blockchain

ton_smart_contract_address

TON smart contract addresses

5 releases

0.0.4 Jan 31, 2023
0.0.3 Jan 4, 2023
0.0.2 Dec 27, 2022
0.0.1 Dec 21, 2022
0.0.0 Dec 20, 2022

#18 in #ton

MIT license

34KB
684 lines

TonSmartContractAddress

Provides functions to work with TON smart contract addresses.

See Smart Contract Address for more info.

Parse any address into any other address.

    let raw = "0:ba60bfbd527c0cd2d70c6396630c50a498af015b987adaad1d4a9e287f604536";
    let bounceable = "EQC6YL-9UnwM0tcMY5ZjDFCkmK8BW5h62q0dSp4of2BFNvnA";
    let non_bounceable = "UQC6YL-9UnwM0tcMY5ZjDFCkmK8BW5h62q0dSp4of2BFNqQF";

    let raw1 = RawAddress::from_raw_str(raw).unwrap();
    let raw2 = RawAddress::from_user_friendly_str(bounceable).unwrap();
    let raw3 = RawAddress::from_user_friendly_str(non_bounceable).unwrap();

    let user_friendly1 = UserFriendlyAddress::from_raw_str(raw).unwrap();
    let user_friendly2 = UserFriendlyAddress::from_user_friendly_str(bounceable).unwrap();
    let user_friendly3 = UserFriendlyAddress::from_user_friendly_str(non_bounceable).unwrap();

Convert any address to any other address.

    let raw1 = user_friendly1.to_raw();
    let raw2 = RawAddress::from_user_friendly(&user_friendly2);

    let user_friendly1 = raw1.to_user_friendly(UserFriendlyFlag::Bounceable);
    let user_friendly2 = UserFriendlyAddress::from_raw(&raw2, UserFriendlyFlag::Bounceable).unwrap();

Build strings in any format.

    let raw_string1 = raw1.to_string();
    let user_friendly_string1 = raw1.to_user_friendly_str(UserFriendlyFlag::Bounceable);

    let raw_string2 = user_friendly1.to_raw_str();
    let user_friendly_string2 = user_friendly1.to_string();

Customize addresses

    let mut raw1 = RawAddress::from_raw_str(raw).unwrap();
    raw1.set_workchain(Workchaain::MasterChain);

    let custom_flag = unsafe{ UserFriendlyFlag::custom(0x01) };
    let user_friendly1 = raw1.to_user_friendly(custom_flag);

Dependencies

~280KB