Wallets

創建我自己的錢包的剝奪地址?

  • July 26, 2020

我想導出我自己使用 web3 框架開發的錢包的**地址,而不需要通過 etherscan 來查找地址。

var Web3 = require("web3");
var url = 'https://ropsten.infura.io';
var web3 = new Web3(url);
var address = '0x8690F1feff62008A396B31c2C3f380bD0Ca6d8b8';
var balance = web3.eth.getBalance(address);
var wallet = web3.utils.toWei(balance, 'ether');

在這裡,我不想提供Address,而是通過 Web3 中的一些程式碼訪問它。我可以知道要遵循的步驟嗎?

最後,我得到了答案:

它是通過兩種不同的方法:

方法一:

var Web3 = require("web3");
var web3 = new Web3('https://mainnet.infura.io');
var wallet = web3.eth.accounts.wallet.create(1);

console.log(wallet['0'].address); 

輸出:

0x798bd25e7e299a6621a4a8e7fa31926d9fc27d0c

方法二:

var Web3 = require("web3");
var url = "https://mainnet.infura.io/v3/60968ff3b2f84a0ebdff7a993f4d080b";
var web3 = new Web3(url);
var wallet = web3.eth.accounts.wallet.create(5);
var encryptKey = web3.eth.accounts.wallet.encrypt('Aditi');

var keys = encryptKey.map((accounts)=>{console.log('0x' + accounts.address)});

輸出:

0x798bd25e7e299a6621a4a8e7fa31926d9fc27d0c
0x9039ecca623fd6e16eb8550085ae0575b6e15763
0xf5008447d7abb3fad1fcfef9a6f85b84ab64732e
0x829126afab3894a0da0cb0b0949c8e8e736466c0
0x97ebdc82777bd6650e316de8e59f8e7de0076e82
0xda81d921ec088c2bf4627e94e99c5c2a8dccf00d

引用自:https://ethereum.stackexchange.com/questions/85265