Created
March 27, 2022 11:58
-
-
Save heyqbnk/2ca2812ad85de5faf33e425d28fb2996 to your computer and use it in GitHub Desktop.
Create TON wallet from mnemonic (24 words).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import TonWeb, {HttpProvider} from 'tonweb'; | |
import {mnemonicToSeed} from 'tonweb-mnemonic'; | |
(async () => { | |
// First of all, create seed from mnemonic. Mnemonic is a | |
// combination of 24 words. For example, you could already | |
// create your wallet in TON Keeper application, where these 24 | |
// words were used. You can use them here too, to get access | |
// to your wallet. | |
const seed = await mnemonicToSeed([/* Array of 24 words goes here. */]); | |
// Create HTTP Provder to perform requests to API. | |
const provider = new HttpProvider(); | |
// Create key pair from our seed. | |
const keyPair = TonWeb.utils.nacl.sign.keyPair.fromSeed(seed); | |
// Create wallet. | |
const wallet = new TonWeb.Wallets.all.v3R2(provider, { | |
publicKey: keyPair.publicKey, | |
wc: -1 | |
}); | |
// Get wallet address. | |
const address = await wallet.getAddress(); | |
// Get current wallet address. | |
const balance = await provider.getBalance(address); | |
return balance; | |
// Don't forget that different versions of wallets create | |
// different addresses. I have already created a wallet in | |
// TON Keeper and its version was V3R2, so I create wallet | |
// of this type here too. | |
})() | |
.then(console.log) | |
.catch(console.error) |
#Ton world
why address generated is different with my real address at tonkeeper app?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great! It could work.