Skip to content

We Define the Basic Smart Contract

View the Full Course Now

This is the very basic smart contract. It can receive Ether and it's possible to withdraw Ether, but all in all, not very useful quite yet. Let's see if we can improve this a bit in the next step.

//SPDX-License-Identifier: MIT

pragma solidity 0.8.1;

contract SharedWallet {

    function withdrawMoney(address payable _to, uint _amount) public {
        _to.transfer(_amount);
    }

    receive() external payable {

    }
}

Solidity Updates

Prior Solidity 0.6 the fallback function was simply called "function() external payable" - a Function without a name. Since Solidity 0.6 there are two different functions: one called fallback and the other one called "receive". Only "receive" can receive ether. You can read more about this in my walkthrough!

Also, the code in this lab has been ported to Solidity 0.8.

The most prominent change is the removal of the SafeMath library, since Solidity 0.8 doesn't do automatic integer rollovers anymore. Read more about this in the topic about Overflow and Underflow. In the lab are notes where Solidity 0.8 changes come in.