Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

VM Exception while processing transaction: revert on Ether transfer #2068

Closed
2 tasks done
calvinlauyh opened this issue Jun 2, 2019 · 2 comments
Closed
2 tasks done

Comments

@calvinlauyh
Copy link

calvinlauyh commented Jun 2, 2019


Issue

Given a contract with a very simple payable function, when I try to sendTransaction from ganache account with more than sufficient gas to the Contract, I get the following error:

VM Exception while processing transaction: revert

I tried to send with a large gas as well as with the estimated one (around 21046), but the error still exists.

Steps to Reproduce

  1. truffle init
  2. Create the following contract under ./contracts
    Test.sol
pragma solidity 0.5.8;

contract Test {
    function deposit() public payable {}
}
  1. Create the following migration under ./migrations
    2_deploy_contract.js
const Test = artifacts.require("Test");

module.exports = function(deployer) {
    deployer.deploy(Test);
};
  1. $ truffle develop
  2. $ migrate
  3. Transfer Ether to it
$ await web3.eth.sendTransaction({
    from: accounts[0],
    to: bankInstance.address,
    value: oneEtherInWei,
    gas: "4712388"
})
  1. Error returns
Error: Returned error: VM Exception while processing transaction: revert

Expected Behavior

I expect the transaction should go through successfully and the Ether should be transferred to the contract.

Actual Results

Received the error

Error: Returned error: VM Exception while processing transaction: revert

Environment

  • Operating System: MacOS
  • Ethereum client: Web3.js v1.0.0-beta.37
  • Truffle v5.0.20 (core: 5.0.20)
  • Solidity v0.5.0 (solc-js)
  • Node v10.15.3
@gnidan
Copy link
Contributor

gnidan commented Jun 2, 2019

Hm. Looks like there's a mismatch between your contract and the way you're sending transactions.

If you just do a regular sendTransaction, it's going to invoke the "fallback function". If you change your deposit function to be this fallback function, you shouldn't see the revert:

pragma solidity 0.5.8;

contract Test {
    function () public payable {}
}

Alternatively, if you want to keep the name deposit, you can invoke this function in JS as follows (using truffle-contract syntax):

const bankInstance = await Test.deployed();
await bankInstance.deposit({
  from: accounts[0],
  value: oneEtherInWei,
  gas: "4712388"
})

Let me know if this helps!

@calvinlauyh
Copy link
Author

Thanks, this is exactly the problem. Sorry for the stupid question. Closing this issue now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants