32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { mnemonicNew, mnemonicToPrivateKey } from '@ton/crypto';
|
|
import { WalletContractV4 } from '@ton/ton';
|
|
import { mkdirSync, writeFileSync } from 'fs';
|
|
|
|
export async function createWallet() {
|
|
let mnemonic = await mnemonicNew();
|
|
let kp = await mnemonicToPrivateKey(mnemonic);
|
|
let contract = WalletContractV4.create({
|
|
workchain: 0,
|
|
publicKey: kp.publicKey,
|
|
});
|
|
// Create wallets directory
|
|
mkdirSync('wallets', { recursive: true });
|
|
|
|
console.log('Mnemonic:', mnemonic);
|
|
console.log('Address:', contract.address.toString());
|
|
// create file with wallet data in readable format
|
|
const content = `WALLET_MNEMONIC="${mnemonic.join(' ')}"
|
|
WALLET_VERSION="V4"
|
|
WALLET_ADDRESS="${contract.address.toString()}"`;
|
|
writeFileSync('wallets/wallet.env', content);
|
|
console.log('Wallet data saved to wallets/wallet.env');
|
|
return { mnemonic, contract };
|
|
}
|
|
|
|
createWallet()
|
|
.then(() => process.exit(0))
|
|
.catch((err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|