I am creating a new Ton wallet address using the following code. It should be v4 address based on the API documentation of TonConnect:
import crypto from "@ton/crypto";
import {toUserFriendlyAddress} from "@tonconnect/ui";
import ton from "@ton/ton";
export async function makeV4Address(mnemonics) {
const workchain = 0; // Usually you need a workchain 0
const keyPair = await crypto.mnemonicToPrivateKey(mnemonics);
const wallet = ton.WalletContractV4.create({ workchain, publicKey: keyPair.publicKey });
console.log(wallet);
const rawFormat = `${workchain}:${wallet.publicKey.toString("hex")}`;
return toUserFriendlyAddress(rawFormat);
}
//const mnemonics = await crypto.mnemonicNew();
// Hardcoded word list for testing - do not use this address
const mnemonics = `
circle
sword
pet
letter
door
woman
sure
cage
milk
uniform
eyebrow
quit
response
kitchen
learn
dumb
march
peanut
climb
deposit
claw
system
plastic
ship`.trim().split(/\r?\n/)
console.log("Mnemonics are:", mnemonics.join(" "));
const address = await makeV4Address(mnemonics);
console.log("Created address", address);
The created address is: UQClm0SeSxKQ5WSAw3xjT8skrzAsQrWoFET50KvGfoZ-tY-h
However this is different address from any of addresses TonKeeper gives in its version selector:
You're creating an address based on the public key that controls the wallet contract, not the address of the deployed wallet.
export async function makeV4Address(mnemonics) {
const workchain = 0; // Usually you need a workchain 0
const keyPair = await crypto.mnemonicToPrivateKey(mnemonics);
const wallet = ton.WalletContractV4.create({ workchain, publicKey: keyPair.publicKey });
console.log(wallet);
const rawFormat = `${workchain}:${wallet.publicKey.toString("hex")}`;
return toUserFriendlyAddress(wallet.address.toRawString()); // change here
Will output
UQBfg1VcidHBC88HaNXxyZgl9PhK34J1PaPqCbjqEB72hISE
Which matches your TONKeeper address.