0

I am using this as my source for web3js:

<script src="http://raw.githubusercontent.com/ethereum/web3.js/0.16.0/dist/web3.min.js">
    </script>

In my HTML I want to display the account's address on the page and tried by the following code:

<p id="accountAddress">
        <script>
            web3 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io/MYTOKENKEY"));
            var wallet = web3.eth.accounts.create([entropy]);
            document.write('new wallet address ' + wallet.accounts[0]);
            document.getElementById("accountAddress").innerHTML = wallet.accounts[0];
        </script>
    </p>

But nothing displays.

I can't find in the documentation on how to create wallets and display information associated with them so any help is greatly appreciated.

1

The parameters you need are address and privateKey of the object account. See the docs

You can create the account doing:

var newAccount = web3.eth.accounts.create([entropy]);

Then, you can get the address and the privateKey like this:

var address = newAccount.address
var privateKey = newAccount.privateKey

Hope this helps

  • Thanks for your help, I'm still having trouble getting it to display anything. I've uploaded my whole code of what I have now here pastebin.com/21WzQMkN . I was following the Infura tutorial but then decided to try and add a bit that creates an account and displays the info for it. I tried using the help you gave me and info from the docs but it doesn't do anything. Maybe you can see where I am going wrong in my code? Thanks again for helping. – John Murphy Jun 28 '18 at 11:09
  • 1
    The issue seems to be with the web3 version you can do this with 1.0 and you are using 0.1x – Jaime Jun 28 '18 at 12:24
  • Do you know the url I should use for the script @ <script src="raw.githubusercontent.com/ethereum/web3.js/0.16.0/dist/…"> </script> for the web3js 1.0 , also the docs say 1.0 is in development and not yet implemented, is that a problem or just something they say for liability in the docs? – John Murphy Jun 28 '18 at 14:03
  • 1
    You could install web3 uisng mpn but if it is not stable is better not to use it. You can use other libraries to generate the account as this is not related to the nodes. For instance, keyethereum the examples in the link show how to add the *.js files and create accounts. – Jaime Jun 28 '18 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.