1

Here is the code below, I want to create accounts using web3 js and logged the private keys. But am having an error Reference Error and keys not logging. I followed the docs at https://web3js.readthedocs.io/en/v1.2.6/web3-eth-accounts.html# , I want to do it from client side, no node JS needed

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript" src="web3.min.js"></script>
</head>
<body>


<script>


var Accounts = require('web3-eth-accounts');

// Passing in the eth or web3 package is necessary to allow retrieving chainId, gasPrice and nonce automatically
// for accounts.signTransaction().
var accounts = new Accounts('ws://localhost:8546');

console.log(web3.eth.accounts.create());


    </script>
</body>
</html>
  • Are u using ganache at Port 8546? – Majd TL Mar 5 at 8:23
1

Please check this tool. You need to make your javascript browser compatible to use require() features.

| improve this answer | |

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.