简体   繁体   中英

how i can get all the addresses in wallet using web3?

I am trying to print to the user all the addresses that he generate in the past in his wallet . I have the seed phase as input how can I get all addresses using js and web3 ?

  function getWalletAddress(seed) 
    {
    if(seed == undefined)
   {
     seed = document.getElementById("Info1").value; 
   }

     var password = Math.random().toString();//creating random password

     lightwallet.keystore.createVault({
     password: password,
     seedPhrase: seed
   }, function (err, ks) {
   ks.keyFromPassword(password, function (err, pwDerivedKey) {
    if(err)
    {
        document.getElementById("details").placeholder = err;
          console.log(err);
    }
    else
    {
        ks.generateNewAddress(pwDerivedKey, totalAddresses);
        var addresses = ks.getAddresses();//getting the adresses in array 
     from the keystore 
            
        var web3 = new Web3(new 
  Web3.providers.HttpProvider('https://ropsten.infura.io/v3/......'));
        var html = "";

        for(var count = 0; count < addresses.length; count++)//for each 
       adress in the addresses
        {
            var address = addresses[count];//getting the addresses 
     console.log(address);

        }
     }
    });
   });
const mnemonic = "cow chicken hen pig and company ..." // <= Use your own beast
const Web3 = require('web3')
const HDWalletProvider = require('@truffle/hdwallet-provider')
const provider = new HDWalletProvider(mnemonic, "http://localhost:8545")

console.log(provider.addresses) // <= What are you looking for.

[
  '0x81ca3152ba96f6df21c5c58e1120a0fe1074bb32',
  '0xca3b46a64b10690c6803ce99591ce74f11935a92',
  '0xe40c56ddfaff79c4434f69cea32c29410a47c7a8',
  '0xc6ab9330f402f027c68e95f75f5119092feb243f',
  '0x20da51a6174a9952fb8a6e9955ffdfa1ecfa7eeb',
  '0x7cf5b4384a530d8d17ac21dd0465897af2ce56c8',
  '0x7e0b9493051671d337492feecb59d73ee2487f6a',
  '0x727b82fc92c2362843a8ea3d75a07b925a413a25',
  '0x30d038789a57708c3d8f16331f8dc5f1db1549d6',
  '0x4d6b2138d65e6108c3ab80bee5951ca9961c2a8e'
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM