我注意到 Tonkeeper 以某种方式生成不同的钱包地址(无论是 v4、v5、v3 等),即使它使用的是相同的助记符。
下面是我用 Javascript 生成钱包地址的代码,但每当我将相同的助记词导入 TonKeeper 钱包时,它都不匹配。由于这个问题,我不得不承认并且只使用 Tonkeeper 来生成助记符。我注意到的另一件有趣的事情是,由 Tonkeeper 生成的助记词,在这个代码示例中使用时会生成完全相同的钱包地址,但是当用户生成自己的有效助记词时,钱包地址与导入助记词时获得的钱包地址不同给 Tonkeeper。
import { getHttpEndpoint } from "@orbs-network/ton-access"
import { WalletContractV5R1, SendMode, fromNano, internal, WalletContractV4, TonClient } from '@ton/ton'
import { mnemonicToWalletKey } from "@ton/crypto"
//import Tonweb from "tonweb"
async function zoomy(){
const mnemonics = "wheel bargain high plate mistake logic congress lunch among report mammal alert rain frequent pony cause half fine hockey yard green warm file rather"
const key = await mnemonicToWalletKey(mnemonics.split(' '))
const _network = 'mainnet'
const endpoint = await getHttpEndpoint({network: _network})
const client = new TonClient({endpoint})
const walletv4 = WalletContractV4.create({publicKey: key.publicKey, workchain: 0})
const walletv5 = WalletContractV5R1.create({publicKey: key.publicKey, workchain: 0})
//const walletHighLoady = await client.getBalance(walletHighLoad.address)
//console.log(`Wallet Highload Balance: ${fromNano(walletHighLoady)} TON`)
console.log(`wallet address v4 is: ${walletv4.address.toString({bounceable: false})} or ${walletv4.address.toString({bounceable: true})} `)
console.log(`wallet address v5 is: ${walletv5.address.toString({bounceable: false})} or ${walletv5.address.toString({bounceable: true})}`)
}
zoomy()
function sleep(vv){
return new Promise(resolve => setTimeout(resolve, vv))
}
根据我的进一步研究和结论更新了代码:
import { WalletContractV5R1, WalletContractV4 } from '@ton/ton'
import { mnemonicToWalletKey, mnemonicNew, mnemonicValidate } from "@ton/crypto"
async function zoomy(){
const mnemonics = (await mnemonicNew()).join(" ")
const key = await mnemonicToWalletKey(mnemonics.trim().split(' '))
const isValid = await mnemonicValidate(mnemonics.trim().split(' '))
if(isValid){
a(mnemonics)
const walletv4 = WalletContractV4.create({publicKey: key.publicKey, workchain: 0})
const walletv5 = WalletContractV5R1.create({publicKey: key.publicKey, workchain: 0})
console.log(`Wallet V4: ${walletv4.address.toString({bounceable: false})} or ${walletv4.address.toString({bounceable: true})} `)
console.log(`Wallet V5: ${walletv5.address.toString({bounceable: false})} or ${walletv5.address.toString({bounceable: true})}\n`)
}
}
setInterval(() => {
zoomy()
}, 1000)
function a(v){console.log(v)}
钱包地址与任何 TON 合约地址一样,取决于合约代码和合约初始化数据。不同的钱包版本意味着不同的合约代码,因此不同的地址和其他加密参数(例如私钥)。 TK 中使用的钱包代码取决于 TK 版本(和 TK 变体:例如,我的 TK 桌面默认为 v5r1,而 TK for Chrome 默认为 v4r2)。
您可以在像tonviewer这样的浏览器中查找每个地址的钱包版本(至少如果已部署),以了解您的TK实例生成的版本以及它与脚本中使用的版本有何不同。