How can I generate ethereum account address and private key that works on ethereum main network using web3 in nodejs?

1 Answer 1


It is very simple,

const Web3 = require('web3')

const web3 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io/Your API key here#"));

async function createAccount(){
    var wallet = await web3.eth.accounts.create();
    console.log('Address:' + wallet.address);
    console.log('Private Key: ' + wallet.privateKey)


And run this js file in the console using node filename.js. You will get what you want.

Your Answer

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

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