There is an issue with my smart contract not transferring any funds to any other address on the connected ganache instance. Regardless if I choose "JavaScript VM" or connect to my Remix, the contract balance gets reduced to zero, but the transaction ends up failing and not actually transferring any funds. Code:

pragma solidity > 0.6.0 < 0.7.0;

import "github.com/provable-things/ethereum-api/provableAPI_0.6.sol";

contract LoanContract is usingProvable {  
    address payable public ME = 0x6252039C9037A49a62f17edbdb26D9bDFffa9dF2;
    uint public balance;

     fallback() external payable {balance = address(this).balance;}
     function AddLender() payable public {
           balance = address(this).balance;
           num_lenders += 1;
    function BPAYOUT() public {
        balance = address(this).balance;

I have other unrelated functions and everything compiles. I have an Ethereum-bridge setup, Ganache running on 8545, and deposit functions so the contract definitely can receive / had funds on it. Deploys fine with metamask and JS VM, but only when I do the "BPAYOUT" function, I get an error that flashes way too quickly for me to see on Metamask, and Remix prints false Transaction mined but execution failed. It also seems that the "to" txn output from Remix when I execute the function is different from the "ME" address I hardcoded in which seems strange. Please help me understand why the transfers don't go through! =)

Edit: I also get this gas-estimation error message from remix before the metamask errors out: Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? [object Object] { "message": "VM Exception while processing transaction: invalid opcode", "code": -32000, "data": { "stack": "RuntimeError: VM Exception while processing transaction: invalid opcode\n at Function.RuntimeError.fromResults (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/utils/runtimeerror.js:89:13)\n at module.exports (/Applications/Ganache.app/Contents/Resources/static/node/node_modules/ganache-core/lib/utils/gas/guestimation.js:142:32)", "name": "RuntimeError" } }

  • Does the contract deployed at ME have a payable fallback function? – goodvibration Jun 16 '20 at 8:57
  • @goodvibration I added in fallback() external payable {balance = address(this).balance;} in there but am getting a pop-up error on Metamask which fails the transaction when I try to deposit. Is there something else I'm missing? I've tried adding in a receive() function as well which had the same issues =( – dankir Jun 17 '20 at 4:53
  • Yeah, you cannot spend more than 2300 gas in a fallback invoked from another contract (i.e., not from an off-chain transaction). Since balance is a storage variable, setting it to a non-zero value costs 5000 or 10000 if I remember correctly (depending on whether or not it was zero prior to that), which exceeds the stipend of 2300. – goodvibration Jun 17 '20 at 5:13
  • And I wrote the above under the assumption that you've added fallback() external payable {balance = address(this).balance;} in the contract deployed at the ME address. – goodvibration Jun 17 '20 at 5:19
  • @goodvibration thank you for the reply. If I'm deploying the contract from a different address other than ME, does that matter? B/c i'm just looking to disperse ether stored on the contract to that address when called by a non-"ME" address. Also, I'm not exactly sure what should go in the fallback() function. I am also running into what looks like a ganache guestimation error (posted full error above). That likely has something to do with it, but appears even with an empty fallback. – dankir Jun 17 '20 at 5:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.