2

I am trying to develop an dapp, but since I am running a small server (Windows Sever 2012 R2) with limited space I don't want to host/install an ethereum node, nor geth in my server, because as many of you know it takes many Gb of hard drive.

However, my "dapp" is a simple HTML page for registration. Essentially this page allows users to register and every time a registration occur; I need to designate/create a new ethereum public address with it corresponding private keys for the user. I am planning to save this information in my database (don't judge). Since I am not hosting a node in my server, I know that I need a third party to connect to mainnet in blockchain, therefore, I am using infura! I know some developer say that you can create wallets with: web3.eth.accounts.create() but the fact is that I can use this code in node.js manually and I am able to create new wallets just fine with the following code:

var Web3 = require('web3');     
var infura = "ws://mainnet.infura.io/v3/xxxxxxxxxxxxxxxxxxxxxx";   
var web3 = new Web3(Web3.givenProvider || infura);  
web3.eth.accounts.create(["this is my seed phrase"]);

but when I try to implement the same approach in HTML it doesn't work. I also try keythereum.js to create wallets with the following code:

var keythereum = require("keythereum");
var dk = keythereum.create();
var readableAddress = keythereum.privateKeyToAddress(dk.privateKey);
console.log("public address:" + readableAddress);
console.log("private key in hex:" + dk.privateKey.toString('hex')

but not luck. I suspect that I may need other dependencies ir order to make it work. Can someone guide me please?

This is the code of my page!

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

<scrip> <!-- keythereum.js code -->
var keythereum = require("keythereum");
var dk = keythereum.create();
var readableAddress = keythereum.privateKeyToAddress(dk.privateKey);
console.log("public address:" + readableAddress);
console.log("private key in hex:" + dk.privateKey.toString('hex')
</script>

<script> <!-- web3.js code -->
var Web3 = require('web3');      
var infura = "ws://mainnet.infura.io/v3/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";   
var web3 = new Web3(Web3.givenProvider || infura);  
web3.eth.accounts.create(["this is my seed phrase"]);   
</script>
    </head>
<body>
<h1>Registration</h1>
</body>
</html>

Error I get:

Error: Provided address "undefined" is invalid, the capitalization checksum test failed, or its an indrect IBAN address which can't be converted. web3.min.js:1:349717

  • The error appear to be unrelated to your code. Can you determine the exact line that generates that error? – Ismael Oct 17 '18 at 3:27
  • It shows web3.min.js:1:349717 – Mula Oct 17 '18 at 17:58
  • I saw that line in the first error message that is because you are using the minified versions of web3. Can you try with unminified versions? Also which line of your code does generate that error message? (try commenting out lines until you find it). – Ismael Oct 17 '18 at 18:30
  • I have changed web3.min.js to web3.js as you recommended, I also downgrade the beta 36 version to 34 because there is not web3.js file in the last version. Now with the same code I have the following error: " ReferenceError: require is not defined " – Mula Oct 17 '18 at 18:59
  • You do not have to use require from a web page, when the web3.js is load it will create a Web3 object (same for keythereum). – Ismael Oct 17 '18 at 21:10
0

I would suggest to use web3-eth-accounts package for account's creation

const Accounts = require('web3-eth-accounts');
const accounts = new Accounts();

const { address, privateKey } = accounts.create();
  • Aquila. The code that you share, can be implemented in html without node or geth? – Mula Oct 17 '18 at 11:16
  • @Mula yes, you can – Aquila Oct 17 '18 at 11:37
  • I appreciate your input but you code doesn't work. – Mula Oct 18 '18 at 2:18
  • most probably you didn't add script to your page, there is CDN you can use jsdelivr.com/package/npm/web3-eth-accounts – Aquila Oct 18 '18 at 8:09

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.