Skip to main content
In this article we will overview how to create wallet programmatically, how to match it with wallets created from mnemonic in user applications (e.g. TonKeeper, TonWallet) and how to deploy it, if it has state uninit

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: This means that if you have correct mnemonic, you will need to match 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 match wallet_id. It is different between wallet versions and network (mainnet and testnet).

Default wallet_id values

Explanation: For Wallet V4R2 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: -239 for mainnet, -3 for testnet
  • wallet_version: for now always 0
  • subwallet_number: 0 by default
  • workchain: 0 for Basechain
Algorithm for generating wallet_id from this parameters:

Examples

We will use @ton/ton Typescript library for wallet wrappers.

Wallet V4R2

Wallet V5

After creating wallet contract instance, you can use it to send messages to the blockchain.