0
votes

I have a very simple solidity function only in place to transfer some ether from one address to another

function transferEtherTo(address _to) payable public {
    _to.transfer(address(this).balance);
}

In remix it works as it's supposed to when Im just on the Javascript VM

But when I switch over to injected web3 I get some unexpected bugs.

For one my meta mask is showing like the ether is going to the contract's address and not the address which im trying to send it to, plus the value in meta mask is 0 for some reason while im trying to send the total contract's balance which i know for sure is 5 ether.

enter image description here

Here is what gets logged in my console:

transact to SimpleDapp.transferEtherTo errored: Error: Error: [ethjs-rpc] rpc error with payload {"id":41874278090,"jsonrpc":"2.0","params":["0xf88a2b8501a13b860082786c9459a42535f42048040c3f5a1152c94af40c7169db80a45c4bade1000000000000000000000000c5fdf4076b8f3a5357c5e395ab970b5b54098fef822d46a09f632a5dbe56be62a9c245f23fa62d9fd8aee230bbda026c6d5822339d2bf9b3a01b4a248bca87bcb491f6f11a572bf158ba86459336e5b1b7eb91f1dda5fde87d"],"method":"eth_sendRawTransaction"} Error: VM Exception while processing transaction: out of gas

Any idea why this works fine in the JavacsriptVM and not with injected web 3?

1
I recently had to do something similar. There are several unique things you need to do for injecting web3. Can you post the code involved with injecting and setting up web3? - Lucas Hendren
So this^ example is just in remix. I'm importing two ganache accounts with private keys in meta mask - benjamin852
But I'm having a similar problem in my real DAPP here's what i'm using there. initWeb3: function() { if (typeof web3 !== 'undefined') { App.web3Provider = web3.currentProvider; console.log("using existing provider"); } else { App.web3Provider = new Web3.providers.HttpProvder('http://127.0.0.1:7545'); console.log("connecting to local Ganache"); } web3 = new Web3(App.web3Provider); console.log("web3 initialized"); return App.initContract(); } - benjamin852
What is the gas usage when you run it in Remix and is it higher than the estimate MetaMask is providing in the UI? Have you tried manually increasing the gas limit in MM before submitting the tx? - Adam Kipnis
By run in remix do you mean use the JavascriptVM? If so I did and it works totally fine there. And im not sure where I find the estimated gas price. But in my metamask I see that the Gas Price is 7 GWEI for each function I try to call. And nope, I haven't touched the Gas Limit at all. - benjamin852

1 Answers

0
votes

I dont think you need to do address(this).balance -- just do this.balance