2
votes

I'm trying to test simple transfer method(move someone's ether to another), but the remix(solidity web compiler) says

transact to browser/Exchange.sol:Exchange.transfer pending ... 
transact to browser/Exchange.sol:Exchange.transfer errored: Error: VM Exception while executing eth_estimateGas: invalid opcode
at /Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:59368:17
at /Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:69306:5
at /Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:11335:9
at /Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:7895:16
at replenish (/Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:8415:25)
at iterateeCallback (/Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:8405:17)
at /Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:8380:16
at /Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:11332:13
at /Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:69302:9
at /Users/strender/.nvm/versions/node/v8.8.1/lib/node_modules/ethereumjs-testrpc/build/cli.node.js:63982:7 

and, my Solidity file structure is

pragma solidity ^0.4.18;

contract Exchange {
  mapping (address => uint256) public balances;
  string public helloworld;

  event LogDeposit(address sender, uint amount);
  event LogWithdraw(address receiver, uint amount);
  event LogTransfer(address sender, address receiver, uint amount);
  event HelloworldEvent(string helloworld);


  function Exchange() {
    helloworld = "helloworld!";
  }

  function helloWorld() returns (string) {
    return helloworld;
  }

  function deposit() payable returns(bool success) {
    balances[msg.sender] += msg.value;
    LogDeposit(msg.sender, msg.value);
    return true;
  }

  function withdraw(uint value) returns (bool success) {
    if (balances[msg.sender] < value) throw;
    balances[msg.sender] -= value;
    msg.sender.transfer(value);
    LogWithdraw(msg.sender, value);
    return true;
  }

  function transfer(address to, uint value) payable returns (bool success) {
    if (balances[msg.sender] < value) throw;
    balances[msg.sender] -= value;
    to.transfer(value);
    LogTransfer(msg.sender, to, value);
    return true;
  }

}

and, on the web3 javascript, I tried to call function "transfer(address to, uint value) like this :

  $("#button").click(function() {
      Exchange.transfer(receiver.toString(), 2);
      // $("#loader").show();
    });

when I added some gas, value parameters to this Exchange.transfer() method, the VM returns "base fee exceeds gas limit"

1
It looks like you're not sending any transaction options with gas/gasPrice in your client. Can you provide that? It looks like the contract works just fine in Remix (I used the default 3000000 gas limit)Adam Kipnis

1 Answers

1
votes

Each chain has a gas limit i.e. the maximum amount of gas you can offer for your action to be completed by the miners. So when you get an error "base fee exceeds gas limit" its saying that the amount of gas that is being supplied to execute your action is more than the limit I explained. You can alter this limit manually like so:

Exchange.transfer(receiver.toString(), 2,{gas:'amount here'});

which you probably already know but my guess would be that you are supplying far too much.

As for your error in remix, its hard to tell precisely whats going on but no doubt so playing around with the gas you supply and similar parameters will probably do the trick.