Hi @ZixuZhao
For Ethernaut Fallback level it looks like you sent 1 wei to the Fallback contract with 21,000 gas limit
await sendTransaction({from: player, to: instance, value:1})
The transaction failed with out of gas. Etherscan
From https://solidity.readthedocs.io/en/latest/contracts.html#fallback-function
Like any function, the fallback function can execute complex operations as long as there is enough gas passed on to it.
You need to send the transaction to the fallback function with a higher gas limit. Try 100,000 as 21.000 is only enough to transfer Ether.
https://metamask.zendesk.com/hc/en-us/articles/360015488771-How-to-Adjust-Gas-Price-and-Gas-Limit-
If you send await sendTransaction({from: player, to: instance, value:1})
with 100,000 gas limit this will still fail, but because it was reverted rather than out of gas.
This reverts due to the require in the fallback function, it checks that you have sent more than 0 Ether and your contributions are greater than 0.
function() payable public {
require(msg.value > 0 && contributions[msg.sender] > 0);
owner = msg.sender;
}
Whilst you sent more than 0 Ether your contributions are 0.
You can check your contributions using fromWei(await contract.getContribution())
You can call the contribute function with 0.001 Ether await contract.contribute({value: toWei(0.001)})
Please note, this value of Ether will fail due to the require require(msg.value < 0.001 ether);
You only need to edit the gas limit for sendTransaction
.
To check your progress:
Get owner: await contract.owner()
Get balance of contract: await getBalance(instance)
I won't give the solution away but there are a number of community solutions if you get stuck on a level, or feel free to ask further questions in the forum.