Ton (ton v0.2.0)
Documentation for Ton
.
Link to this section Summary
Functions
Create a transfer boc which can be used to submit a transaction
Initializes a Wallet
struct from public_key, workchain and wallet_id. The version of the wallet contract is v4 r2.
Converts a mnemonic to an entropy.
Generates a key pair from a mnemonic.
Converts a mnemonic to a seed.
Parses and validates an address
Generates a friendly adress from a wallet struct
Link to this section Functions
create_transfer_boc(wallet, params)
@spec create_transfer_boc(Ton.Wallet.t(), Keyword.t()) :: binary() | no_return()
Create a transfer boc which can be used to submit a transaction
examples
Examples
iex> keypair = Ton.mnemonic_to_keypair("rail sound peasant garment bounce trigger true abuse arctic gravity ribbon ocean absurd okay blue remove neck cash reflect sleep hen portion gossip arrow") iex> wallet = Ton.create_wallet(keypair.public_key) iex> {:ok, to_address} = Ton.parse_address("EQAHJQ6gs2NYAXsxsfsucpqhpneZaGP0qCdu9lCEzysMGzst") iex> params = [seqno: 5, bounce: true, secret_key: keypair.secret_key, value: 1, to_address: to_address, timeout: 60] iex> <<181, 238, 156, 114, 65, 1, 2, 1, 0, 167, 0, 1, 225, 136, 0, 5, 230, 220, 65, 102, 30, 28, 201, _tail::binary>> = Ton.create_transfer_boc(wallet, params)
create_wallet(public_key, workchain \\ 0, wallet_id \\ 698_983_191)
@spec create_wallet(binary(), integer(), integer()) :: Ton.Wallet.t()
Initializes a Wallet
struct from public_key, workchain and wallet_id. The version of the wallet contract is v4 r2.
examples
Examples
iex> keypair = Ton.mnemonicto_keypair("rail sound peasant garment bounce trigger true abuse arctic gravity ribbon ocean absurd okay blue remove neck cash reflect sleep hen portion gossip arrow") iex> %Ton.Wallet{initial_code: , initialdata: , workchain: 0, wallet_id: 698983191, public_key: <<73, 245, 11, 185, 76, 95, 180, 99, 83, 74, 157, 13, 240, 216, 227, 155, 203, 147, 16, 149, 137, 218, 246, 81, 151, 233, 21, 28, 55, 119, 64, 47>>} = Ton.create_wallet(keypair.public_key)
mnemonic_to_entropy(mnemonic, password \\ "")
Converts a mnemonic to an entropy.
examples
Examples
iex> Ton.mnemonic_to_entropy("rail sound peasant garment bounce trigger true abuse arctic gravity ribbon ocean absurd okay blue remove neck cash reflect sleep hen portion gossip arrow")
# "1ab77da4f35581bd6f8efdcaef689ec180c6f77d214e4dd960f1619f6c40599f04798cb4e93e30edceeb02ab36f450df1c359e7b3395f13646134046cc6a7f3a"
<<26, 183, 125, 164, 243, 85, 129, 189, 111, 142, 253, 202, 239, 104, 158, 193, 128, 198, 247, 125, 33, 78, 77, 217, 96, 241, 97, 159, 108, 64, 89, 159, 4, 121, 140, 180, 233, 62, 48, 237, 206, 235, 2, 171, 54, 244, 80, 223, 28, 53, 158, 123, 51, 149, 241, 54, 70, 19, 64, 70, 204, 106, 127, 58>>
mnemonic_to_keypair(mnemonic, password \\ "")
Generates a key pair from a mnemonic.
## Examples
iex> Ton.mnemonic_to_keypair("rail sound peasant garment bounce trigger true abuse arctic gravity ribbon ocean absurd okay blue remove neck cash reflect sleep hen portion gossip arrow") %Ton.KeyPair{
secret_key: <<149, 222, 63, 223, 23, 72, 240, 224, 233, 177, 155, 16, 101,
229, 182, 172, 23, 131, 54, 43, 195, 139, 217, 194, 100, 19, 252, 105, 68,
30, 96, 95, 73, 245, 11, 185, 76, 95, 180, 99, 83, 74, 157, 13, 240, 216,
227, 155, 203, 147, 16, 149, 137, 218, 246, 81, 151, 233, 21, 28, 55, 119,
64, 47>>,
public_key: <<73, 245, 11, 185, 76, 95, 180, 99, 83, 74, 157, 13, 240, 216,
227, 155, 203, 147, 16, 149, 137, 218, 246, 81, 151, 233, 21, 28, 55, 119,
64, 47>>
}
mnemonic_to_seed(mnemonic, password \\ "")
Converts a mnemonic to a seed.
examples
Examples
iex> Ton.mnemonic_to_seed("rail sound peasant garment bounce trigger true abuse arctic gravity ribbon ocean absurd okay blue remove neck cash reflect sleep hen portion gossip arrow")
# 95de3fdf1748f0e0e9b19b1065e5b6ac1783362bc38bd9c26413fc69441e605f
<<149, 222, 63, 223, 23, 72, 240, 224, 233, 177, 155, 16, 101, 229, 182, 172, 23, 131, 54, 43, 195, 139, 217, 194, 100, 19, 252, 105, 68, 30, 96, 95>>
parse_address(address)
@spec parse_address(binary()) :: {:ok, Ton.Address.t()} | {:error, atom()}
Parses and validates an address
examples
Examples
iex> Ton.parse_address("UQCAIBANQeQX6UHmRgxHGR44oUL7VOQE9v4dxmla23KpjKIj") {:ok, %Ton.Address{test_only: false, bounceable: false, workchain: 0, hash: <<128, 32, 16, 13, 65, 228, 23, 233, 65, 230, 70, 12, 71, 25, 30, 56, 161, 66, 251, 84, 228, 4, 246, 254, 29, 198, 105, 90, 219, 114, 169, 140>>}}
iex> Ton.parse_address("address")
wallet_to_friendly_address(wallet, params \\ [])
@spec wallet_to_friendly_address(Ton.Wallet.t(), Keyword.t()) :: binary()
Generates a friendly adress from a wallet struct
examples
Examples
iex> keypair = Ton.mnemonic_to_keypair("rail sound peasant garment bounce trigger true abuse arctic gravity ribbon ocean absurd okay blue remove neck cash reflect sleep hen portion gossip arrow") iex> wallet = Ton.create_wallet(keypair.public_key) iex> Ton.wallet_to_friendly_address(wallet) "EQAC824gsw8OZLoMV6_nr4nkxaEQFlbzoiHHOWIYY81eM5rQ"
iex> keypair = Ton.mnemonic_to_keypair("rail sound peasant garment bounce trigger true abuse arctic gravity ribbon ocean absurd okay blue remove neck cash reflect sleep hen portion gossip arrow") iex> wallet = Ton.create_wallet(keypair.public_key) iex> Ton.wallet_to_friendly_address(wallet, [url_safe: false, bounceable: false, test_only: true]) "0QAC824gsw8OZLoMV6/nr4nkxaEQFlbzoiHHOWIYY81eM3yf"