C 351: Making a Solidity Contract (10 pts)

What you need:


We'll make a very simple contract: a faucet that distributes small amounts of Ether. We'll continue to use the Ropsten test network so the ETH is free.

Opening the Remix IDE

In Chrome, go to
A "Help us to improve..." box pops up. Click Sure.

In the left pane, right-click contracts and click "New File", as shown below.

Type the name Faucet.sol and press Enter.

A "Faucet.sol" tab appears on the right side. Paste in this code, as shown below.

// Version of Solidity compiler this program was written for
pragma solidity 0.6.4;

// Our first contract is a faucet!
contract Faucet {
    // Accept any incoming amount
    receive() external payable {}

    // Give out ether to anyone who asks
    function withdraw(uint withdraw_amount) public {
        // Limit withdrawal amount
        require(withdraw_amount <= 100000000000000000);

        // Send the amount to the address that requested it

On the left side, click the third icon, outlined in green in the image above. The "SOLIDITY COMPILER" appears. At the bottom, click the blue "Compile Faucet.sol" button.

On the left side, the third icon now has a green check-mark on it, and at the lower left, in the CONTRACT section, a button appears labeled "Faucet (Faucet.sol)", as shown below.

At the lower left, click the "Compilation Details" button.

Scroll down to see the ASSEMBLY code, as shown below.

This is the compiled code that will be published on the blockchain.

At the lower right, click Close to close the box showing the ASSEMBLY code.

On the left side, click the fourth icon from the top. The "DEPLOY & RUN TRANSACTIONS" pane opens.

Select an Environment of "Injected Web3".

A "Connect With MetaMask" box pops up. Click Next. Click Connect.

At the lower left, the Deploy button turns orange, as shown below.

Click the Deploy button.

A "MetaMask Notification" box pops up. Click Confirm. Click Connect.

After a few seconds, at the lower left, in the Deployed Contracts section, you see "FAUCET...". Click the > sign next to "FAUCET" to expand that section and you'll see an orange withdraw button, as shown below.

Viewing the Contract in Etherscan

In Chrome, open a new tab and go to
In the Remix page, on the left side, under the "Deployed Contracts" label, in the "FAUCET AT..." line, click the two-page icon, outlined in green in the image above. This copies the contract's address to the clipboard.

On the Etherscan tab, paste in the address and press Enter to search the blockchain for it.

There is only one transaction for the contract: "Contract Creation", and this contract has a balance of "0 Ether", as shown below.

Funding the Contract

The faucet won't work until it has some ETH to distribute.

In Chrome, click the MetaMask tab.

Click Send.

Paste in the contract's address and send your contract 0.3 ETH, as shown below.

Click Next. Click Confirm.

Refresh the Etherscan tab.

You see two transactions, and a balance of 0.3 Ether, as shown below.

Withdrawing from Your Faucet

On the Remix tab, at the lower left, enter a withdraw amount of
as shown below.

Click the orange withdraw button.

Click Confirm.

Refresh the Etherscan tab.

You see three transactions, and a balance of 0.2 Ether, as shown below.

Notice that the latest transaction value is 0 Ether, not 0.1 Ether.

C 351.1: Internal Txns (10 pts)

In Etherscan, in the lower pane, click the "Internal Txns" tab.

Now the 0.1 Ether transaction amount appears, as shown below.

The flag is covered by a green rectangle in the image below.


Ethereum Basics

Posted 5-10-2021
Renumbered from 331 to 351 5-16-2021
Reference to C 330 added 10-26-21