I'm new to solidity development so maybe this isn't as difficult as it is right now for me. I created a smart contract that can receive and send ether to different accounts. If I connect ganache to metamask, I can see it changes the account balance when these functions are called. I use "send" method to send ether to an account and use a "depositToThisContract" function as payable to receive ether in the smart contract.

My question is ¿Is it possible for a smart contract to be written so it can receive ether directly from metamask platform? That is without calling these functions through metamask API or using web3. Directly from metamask, just like you would send ether to any other account ¿Is there a class or other type of contract that I can import so my contract recognize transactions coming from metamask platform and updates the balance? ¿Or maybe override an existing default function?


PS: This is my first question ever at a development forum. I would really appreciate if you could tell me how to make this better.

1 Answer 1


What you're looking for is the special receive function (docs). This function is executed when someone sends ETH to the contract without any data (i.e. they're not calling a function).

receive() external payable {
    // Do something here

This would trigger when someone sends ETH directly to the contract from Metamask without calling any functions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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