Skip to main content
The basic configuration earlier is enough to outline necessary wallet information and initialize the WalletKit, but it isn’t enough for deeper interactions with the blockchain. For that, you need to set up at least one TON wallet contract.

Initialization

  1. First, obtain the signer. It can be instantiated from a mnemonic, from a private key, or be made custom.
  2. Then, select a wallet adapter — it is an implementation of the WalletInterface type for a particular TON wallet contract. Currently, WalletKit provides two: WalletV5R1Adapter (recommended) and WalletV4R2Adapter. Adapter takes in a signer from the previous step and a number of options, namely:
    • network — TON Blockchain network: Network.mainnet(), Network.testnet(), or Network.custom(chainId).
    • client — API client to communicate with TON Blockchain. Use kit.getApiClient(network) to get the client for the specified network from the networks configuration passed during WalletKit initialization.
    • walletId — identifier of the new wallet, which is used to make its smart contract address unique.
    • workchain — either 0 for the basechain (default), or -1 for the masterchain.
    TypeScript
  3. Finally, pass the adapter to the addWallet() method of the kit to complete the wallet initialization process:
    TypeScript
See the complete example for each signer kind:

Mnemonic

Private key

Custom signer

From mnemonic

To initialize a TON wallet from an existing BIP-39 or TON-specific mnemonic seed phrase, the signer should be instantiated with the fromMnemonic() method of the utility Signer class of the WalletKit.
TypeScript

From private key

To initialize a TON wallet from an existing private key, the signer should be instantiated with the fromPrivateKey() method of the utility Signer class of the WalletKit. If there is a mnemonic, one can convert it to an Ed25519 key pair with public and private key by using the MnemonicToKeyPair() function.
TypeScript

From custom signer

To provide a custom signing mechanism as an alternative to using a mnemonic phrase or a private key, create an object of type WalletSigner and then pass it to the target wallet adapter’s create() method. The signer object has to have two fields:
  • Signing function of type ISigner, which takes an iterable bytes object, such as array, Uint8Array, or Buffer, and asynchronously produces an Ed25519-encoded signature of the input as Hex. The Hex type is a string containing a hexadecimal value that starts with an explicit 0x prefix.
    TypeScript
  • Relevant Ed25519 public key of type Hex.
    TypeScript
A custom signer is useful to maintain complete control over the signing process, such as when using a hardware wallet or signing data on the backend.
TypeScript

Multiple wallets

You can add multiple TON wallets to WalletKit and switch between them as needed.
TypeScript
Providing the same wallet adapter to the kit multiple times will return the wallet that was already added in the first attempt.

Methods

Get a single wallet

The getWallet() method expects a wallet identifier string. Note that the same wallet on different chains must have different identifiers. Compose it via the createWalletId() helper function:
TypeScript

Get all wallets

To obtain all added wallets, use the getWallets() method of the initialized kit.
TypeScript

Remove a single wallet

The kit.removeWallet() method accepts either a walletId or the adapter instance itself. Compose the identifier via the createWalletId() helper function or pass the adapter used when adding the wallet:
TypeScript

Clear all wallets

To remove all previously added wallets from the kit, use the clearWallets() method of the initialized kit.
TypeScript

Next steps

Handle connections

See also