I’ve been learning Solidity lately, this is a note for noob.
While encountering
Error: Returned error: VM Exception while processing transaction: revert
We can debug the transaction using:
truffle debug --fetch-external 0xTxHash
Then, we can follow the code and look into the stacktrace. For me this time, I’m facing this:
msg.sender.transfer(wad);
Here msg.sender
is my contract, why my contract revert
when transfer ether
to it. After a few digging, I learn the reason.
A contract receiving Ether must have at least one of the functions below
receive() external payable
fallback() external payable
You can follow the Reference to check more detail about these 2 functions.
Reference: