How to transfer Ethereum from one wallet to another wallet by using web3?

7.8k views Asked by At

I am in the process of developing a custom ETH wallet, I am able to generate the public/private keys by using vanity eth. After receiving the amount in this wallet, I need to send ETH to another wallet for which I am trying to use web3. How do I do this? The wallet currently have few ETH in it but when I try to check the balance with web3 code it shows zero balance. So how do I transfer ETH from one wallet to another using web3 code, please advice.

My code for get balance of my wallet address is as below.

<script src="./node_modules/web3/dist/web3.min.js"></script>
<script type="text/javascript">
    var Web3 = require('web3');
    var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
    console.log("Balance = " + web3.fromWei(web3.eth.getBalance('Wallet_address'), 'ether').toNumber());
</script>
1

There are 1 answers

7
Lucas Hendren On

Try this.

web3.eth.sendTransaction({from: acct1, to:acct2, value: web3.toWei(1, 'ether'), gasLimit: 21000, gasPrice: 20000000000})

This is how I performed an ether transaction in a previous project. Also in the future posting here, for the time being, may get you a quicker response https://ethereum.stackexchange.com/