Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gsaslis/ecf798e0d1d63b10a3344b9cbaca2ae1 to your computer and use it in GitHub Desktop.
Save gsaslis/ecf798e0d1d63b10a3344b9cbaca2ae1 to your computer and use it in GitHub Desktop.
Web3 Greece - Publishing our first smart contract on Ethereum

Workshop Walkthrough


Before you start: Join Zulip!

In order to deploy our smart contract, we’ll need some money to pay for that deployment.

As we’ll be deploying to Ethereum, we need some ETH on our wallets. Steps 1-4 below will help you create a wallet and add some balance to it.

If you already have a wallet, you know how to connect it to Rinkeby and already have some test ETH on it, please help others in a group!

1. Create a wallet

Choose between the Metamask browser extension or just use the built-in wallet in Brave - the first browser to offer a built-in wallet.

Metamask

The most popular wallet for web3 applications today is Metamask.

Head on over to https://metamask.io/download.html and follow the "Install MetaMask for your browser" instructions.

Brave

  • Ensure you have upgraded to the latest version of Brave.

  • Open a new tab and head on over to: brave://wallet/crypto/onboarding

  • Follow the on-screen instructions to create your wallet.

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/**
* @title MeetupRatings
* @dev Leave feedback for a meetup and retrieve all feedback comments
*/
contract MeetupRatings {
struct Feedback {
address commenter;
string message;
uint rating;
}
Feedback[] public all_feedback;
/**
* @dev Store Feedback
* @param feedback_rating a 1-5 rating for the meetup, where 1 is worse, 5 is best!
* @param feedback_message some free text message you want to leave for this meetup
*/
function rate(uint feedback_rating, string memory feedback_message) public {
all_feedback.push(
Feedback({
commenter: msg.sender,
message: feedback_message,
rating: feedback_rating
})
);
}
/**
* @dev Returns all the feedback recorded on chain so far
* @return value of 'all_feedback'
*/
function retrieve() public view returns (Feedback[] memory){
return all_feedback;
}
}

2. Switch to Rinkeby test network

You can think of test networks (testnets) as entirely different "deployments" or environments, much like you’d have a staging environment before you deploy to production.

We’ll not be working in production today.

Open Metamask or Brave and click the drop-down with "Ethereum" or "Ethereum Mainnet" text. Switch to Rinkeby test network.

3. Get test Ether

In test networks, getting money is FREE! (spoiler: that’s because it’s fake money)

Getting money on test nets happens through Faucets.

TODO:

  • Search (duckduckgo, preferrably) for the corresponding faucet of each test network

  • Try to get some funds on your wallet

  • Report to the group which faucets you found working (some faucets are known to stop working)

4. Send some ETH to a fellow participant

To get a little more acquainted with your wallet, let’s send some test ETH between us.

Try sending some test ETH between everyone in your group!

Be generous!!! 💰💰💰

5. Sample contract

Let’s go through a super-simple contract to get a feel of what they look like:

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

/**
 * @title Storage
 * @dev Store & retrieve value in a variable
 */
contract Storage {

    uint256 number;

    /**
     * @dev Store value in variable
     * @param num value to store
     */
    function store(uint256 num) public {
        number = num;
    }

    /**
     * @dev Return value
     * @return value of 'number'
     */
    function retrieve() public view returns (uint256){
        return number;
    }
}

6. Access Remix IDE and compile the contract

Remix is a web-based IDE that makes it really easy to deploy our first smart contract.

Go ahead and access it and follow the intro tutorial, so you can understand how to compile the contract!

Now try selecting the 1_Storage.sol file, compiling it !

7. Publish the contract

Once you have successfully compiled the contract with no issues, try deploying it!!

To deploy with your wallet, you will need to switch to the Deploy tab and select "Injected Web3" in the first dropdown. That should open a popup in your Brave or Metamask wallet and prompt you to connect your wallet with the Remix IDE.

After you have connected your wallet and ensured you are on the Rinkeby testnet, go ahead and Deploy!!! 🚀🚀🚀

8. Interact with the contract

After a few seconds, your contract will be deployed and the Remix IDE will allow you to invoke the functions in your smart contract!

Every time you try to invoke a function, you will need to authorise the payment for that transaction with your wallet, so you will get a popup (Note that you need to pay for the function code to be executed!!! 🙃 )

Try this out as much as you want and discuss within your group.

9. Leave your feedback about the meetup on-chain !

We’ll now work together to publish a single instance of the MeetupRatings.sol toy contract (shared below) to the Rinkeby test net, so that all participants can leave their feedback about this meetup.

Leave your groups and have a walk around the gather.town space until everyone else is finished and we can work on this together!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment