Initialization
- First, obtain the signer. It can be instantiated from a mnemonic, from a private key, or be made custom.
-
Then, select a wallet adapter — it is an implementation of the
WalletInterfacetype for a particular TON wallet contract. Currently, WalletKit provides two:WalletV5R1Adapter(recommended) andWalletV4R2Adapter. Adapter takes in a signer from the previous step and a number of options, namely:network— TON Blockchain network:Network.mainnet(),Network.testnet(), orNetwork.custom(chainId).client— API client to communicate with TON Blockchain. Usekit.getApiClient(network)to get the client for the specified network from thenetworksconfiguration passed during WalletKit initialization.walletId— identifier of the new wallet, which is used to make its smart contract address unique.workchain— either0for the basechain (default), or-1for the masterchain.
TypeScript -
Finally, pass the adapter to the
addWallet()method of the kit to complete the wallet initialization process:TypeScript
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 thefromMnemonic() 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 thefromPrivateKey() 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 typeWalletSigner 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 asarray,Uint8Array, orBuffer, and asynchronously produces an Ed25519-encoded signature of the input asHex. TheHextype is a string containing a hexadecimal value that starts with an explicit0xprefix.TypeScript -
Relevant Ed25519 public key of type
Hex.TypeScript
TypeScript
Multiple wallets
You can add multiple TON wallets to WalletKit and switch between them as needed.TypeScript
Methods
Get a single wallet
ThegetWallet() 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 thegetWallets() method of the initialized kit.
TypeScript
Remove a single wallet
Thekit.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 theclearWallets() method of the initialized kit.
TypeScript