目录
初始化
keyStore 导出账户
1.walletObj 导出
2.web3导出
privatekey Get Wallet Address
初始化
npm install bip39@3.1.0
npm install ethereumjs-wallet
import { onMounted } from 'vue'
import * as bip39 from 'bip39'
import { hdkey } from 'ethereumjs-wallet'
const MyMnemonic = ref(
'Your Mnemonic Word'
)
onMounted(async () => {
const Seed = await bip39.mnemonicToSeed(MyMnemonic.value)
//通过hdkey将seed生成HD Wallet
const hdkeyWallet = hdkey.fromMasterSeed(Seed)
//生成wallet中在m/44'/60'/0'/0/i路径的keypair
const keypair = hdkeyWallet.derivePath("m/44'/60'/0'/0/0")
//通过keypair 获取wallet地址和私钥
//获取wallet对象
const walletObj = keypair.getWallet()
})
keyStore 导出账户
介绍:两种导出方式
1.walletObj 导出
2.web3导出
1.walletObj 导出
import ethwallet, { hdkey } from 'ethereumjs-wallet'
onMounted(async () => {
let keystore = await walletObj.toV3('111111') // 参数必须为 字符串
//通过keystore解密私钥
const Decode = await ethwallet.fromV3(keystore, '111111')
const walletObjDecode = Decode.getPrivateKey().toString('hex')
console.log('wallet对象', walletObjDecode)
})
2.web3导出
初始化
npm install web3
import Web3 from 'web3'
//初始化网络
const Web3Network = new Web3( Web3.givenProvider || '你的网络地址')
keyStore导出文章来源:https://www.toymoban.com/news/detail-537082.html
const MyprivateKey = ref(
'你的privateKey 地址'
)
onMounted(async () => {
const Web3keystore = Web3Network.eth.accounts.encrypt(
MyprivateKey.value,
'111111'
)
//通过keystore解密私钥
const web3Decode = Web3Network.eth.accounts.decrypt(Web3keystore, '111111')
console.log('web3', web3Decode.privateKey)
})
privatekey Get Wallet Address
npm install buffer文章来源地址https://www.toymoban.com/news/detail-537082.html
import ethwallet from 'ethereumjs-wallet'
const MyprivateKey = ref('你的privatekey')
const privatekey = Buffer(MyprivateKey.value, 'hex')
const wallet = ethwallet.fromPrivateKey(privatekey)
const KeywalletAddress = wallet.getAddressString()
console.log(`wallet地址:`, KeywalletAddress)
到了这里,关于【Web3】keyStore导出帐户、privatekey Get Wallet Address的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!