I'm using web3.jp 1.0

How to connect (log in) my existing account (for example, created through myetherwallet) to make a transaction or call contract?

As I understand it, the list of accounts is provided by the RPC node, because when using testerpc in the Web3.eth.accounts, test accounts were available, but new ones were not added.

const Web3 = require('web3');
console.log(web3.eth.getAccounts()) // []

thank you!


To create new accounts on Ethereum you can use following instructions:

var Accounts = require('web3-eth-accounts');
var accounts = new Accounts('http://localhost:8545');
//Generates an account with public key and private key
> {
    address: "0xb8CE9ab6943e0eCED004cDe8e3bBed6568B2Fa01",
    privateKey: "0x348ce564d427a3311b6536bbcff9390d69395b06ed6c486954e971d960fe8709",
    signTransaction: function(tx){...},
    sign: function(data){...},
    encrypt: function(password){...}

Creating accounts on ethereum -

  1. Make sure you have installed the web3 node module.
  2. If not then you can install it using npm install web3


var Web3 = require('web3')
var web3 = new Web3(Web3.givenProvider || 'http://localhost:7545')

//Now to create an account


> {
    address: "0xF2CD2AA0c7926743B1D4310b2BC984a0a453c3d4",
    signTransaction: function(tx){...},
    sign: function(data){...},
    encrypt: function(password){...}

For more information, refer to the web3.js documentation - https://web3js.readthedocs.io/en/1.0/web3.html

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.