Wallet address
Wallets in TON are smart contracts. That means that wallet address is derived using the same rules as for any other account on the blockchain - address is derived from State Init. In case of a wallet contract, two fields determine its address:public_key, dependent on mnemonicwallet_id, special salt-like field, dependent on wallet contract type and network
Sometimes
wallet_id is also called subwallet_id in some of the libraries and documentation. They mean the same thing.wallet_id to get the expected wallet address.
Matching wallet applications
The most common use-case for wallet addresses is to match wallet created from the wallet application (e.g. TonKeeper, TonWallet) and the one you get in your source code for programming. The first obvious thing is to use the same mnemonic/public key - you can’t match wallet address without it. Read here to learn more about mnemonics. Next, you will need to matchwallet_id. It is different between wallet versions and network (mainnet and testnet).
Default wallet_id values
| Network | Wallet V4R2 | Wallet V5 |
|---|---|---|
| Mainnet | 0x29a9a317 (698983191) | 0x7FFFFF11 (2147483409) |
| Testnet | 0x29a9a317 (698983191) | 0x7FFFFFFD (2147483645) |
wallet_id is defined as first 4 bytes from TON mainnet blockchain initial state hash. There is no specific logic why this number was chosen, community needed some default value and this one works well enough.
For Wallet V5, as you can see above, wallet_id is different between Mainnet and Testnet. This is implemented for security reasons, so that you will get different wallet addresses for different networks with same mnemonic and it will save some developers and users from fund loss.
This value is obtained from 4 parameters:
network_id:-239for mainnet,-3for testnetwallet_version: for now always0subwallet_number:0by defaultworkchain:0for Basechain
wallet_id from this parameters:
Algorithm here is presented for education purpose, in most cases you won’t need to implement it yourself, instead use existing implementation from libraries.
Examples
We will use@ton/ton Typescript library for wallet wrappers.