1

I am using web3js to create a local account using the following function

    function makeaccount() {
        var account = web3.eth.accounts.create();
        console.log(account);
        var walletprivate = account["privateKey"];
        var phppasswallet = "THE_PASSWORD";
    }

This functions generates an account locally but I can even access the balance of this address from Already Deployed Contract Token using

contract.methods.balanceOf(address).call().then(function (balance) {
            $("#balance").html(balance);
        });

However when I try to send tokens from Metamask to this address. It keeps spinning and balance of the address created using makeaccount is always zero. I am using a private network and have setup metamask and web3js to use the localhost network.

1 Answer 1

1

For some reason the account created byweb3.eth.accounts.create() creates the address without 0x prefix. My script wasn't addressing this and metamask would get the address without 0x prefix and I was unable to send the transaction.

1
  • A good gotcha! This is a common mistake and roots from the fact that JavaScript does not have native big number support or good binary data support. It is documented here web3js.readthedocs.io/en/v1.2.7/… May 11, 2020 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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