Skip to content

Instantly share code, notes, and snippets.

@heyqbnk
Created March 27, 2022 11:58
Show Gist options
  • Save heyqbnk/2ca2812ad85de5faf33e425d28fb2996 to your computer and use it in GitHub Desktop.
Save heyqbnk/2ca2812ad85de5faf33e425d28fb2996 to your computer and use it in GitHub Desktop.
Create TON wallet from mnemonic (24 words).
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)
@dragonwarrior9873
Copy link

Great! It could work.

@Sully116
Copy link

#Ton world

@exaho
Copy link

exaho commented Sep 12, 2024

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