1

I am trying to send Ethers to a contract deployed on Ganache but I am getting VM Exception while processing transaction: revert, the same logic is able to transfer Ethers to other account.

Following are error log and the code for sending Ether

Code:
Fallback method:

function() public payable {
    transfer(msg.sender, msg.value);
}

Transfer logic:

/**
* @dev Transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
    require(_value <= balances[msg.sender]);
    require(_to != address(0));

    balances[msg.sender] = balances[msg.sender].sub(_value);
    balances[_to] = balances[_to].add(_value);
    emit Transfer(msg.sender, _to, _value);
    return true;
}

Error:

Error: Returned error: VM Exception while processing transaction: revert
    at Object.ErrorResponse (errors.js:29)
    at index.js:140
    at XMLHttpRequest.request.onreadystatechange (index.js:79)
    at XMLHttpRequest.push../node_modules/xhr2-cookies/dist/xml-http-request-event-target.js.XMLHttpRequestEventTarget.dispatchEvent (xml-http-request-event-target.js:34)
    at XMLHttpRequest.push../node_modules/xhr2-cookies/dist/xml-http-request.js.XMLHttpRequest._setReadyState (xml-http-request.js:208)
    at XMLHttpRequest.push../node_modules/xhr2-cookies/dist/xml-http-request.js.XMLHttpRequest._onHttpResponseEnd (xml-http-request.js:318)
    at push../node_modules/stream-http/lib/response.js.exports.IncomingMessage.<anonymous> (xml-http-request.js:289)
    at push../node_modules/stream-http/lib/response.js.exports.IncomingMessage.push../node_modules/events/events.js.EventEmitter.emit (events.js:96)
    at endReadableNT (_stream_readable.js:1010)
    at afterTickTwo (index.js:27)
    at Object.ErrorResponse (errors.js:29)
    at index.js:140
    at XMLHttpRequest.request.onreadystatechange (index.js:79)
    at XMLHttpRequest.push../node_modules/xhr2-cookies/dist/xml-http-request-event-target.js.XMLHttpRequestEventTarget.dispatchEvent (xml-http-request-event-target.js:34)
    at XMLHttpRequest.push../node_modules/xhr2-cookies/dist/xml-http-request.js.XMLHttpRequest._setReadyState (xml-http-request.js:208)
    at XMLHttpRequest.push../node_modules/xhr2-cookies/dist/xml-http-request.js.XMLHttpRequest._onHttpResponseEnd (xml-http-request.js:318)
    at push../node_modules/stream-http/lib/response.js.exports.IncomingMessage.<anonymous> (xml-http-request.js:289)
    at push../node_modules/stream-http/lib/response.js.exports.IncomingMessage.push../node_modules/events/events.js.EventEmitter.emit (events.js:96)
    at endReadableNT (_stream_readable.js:1010)
    at afterTickTwo (index.js:27)
    at resolvePromise (zone.js:814)
    at zone.js:724
    at index.js:72
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:3815)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
    at push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask (zone.js:496)
    at ZoneTask.invoke (zone.js:485)
    at timer (zone.js:2054)
  • 1
    Does msg.sender have enough balance? – Henk Aug 16 '18 at 11:22
  • Yes, the accounts have the appropriate balance. – Paradox Aug 16 '18 at 11:26
  • @Paradox We're going to need more proof. :-) The transaction is being reverted, and there's only one relevant require, so my assumption is that msg.value > balances[msg.sender]. (To verify, remove that require statement and try again.) – user19510 Aug 16 '18 at 11:28
  • How are you sending the Ether? From another smart contract using address.transfer by any chance? Because in that case, the gas stipend that is sent along with the call is not going to be enough for all these computations and storage operations – Henk Aug 16 '18 at 11:28
  • @Paradox Sorry, just removing that require won't be enough, because it's already redundant. (I'm assuming .sub(...) is some sort of "safe math" routine that reverts when the result underflows.) Maybe just add balances[msg.sender] = 2**256-1 instead to verify the balance is the issue. – user19510 Aug 16 '18 at 11:29
0

I know its kinda funny but restarting the machine fixed the issue XD.

Your Answer

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

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