レッスン1

Setting Up & Understanding Gas in Remix

Welcome to the first lesson of our course, Gas Optimization Techniques with Remix!

Welcome to the first lesson of our course, Gas Optimization Techniques with Remix! If you’re reading this, you’ve probably had some experience with Ethereum smart contracts and might have noticed those pesky gas fees that come with every transaction and deployment. Gas ensures that the Ethereum network remains healthy and free from spam, but it also means that every line of code we write in our smart contracts can cost real money when executed.

If you are not an expert, here are some articles you can read before starting the course:

What is Ethereum?

What Are Smart Contracts?

What’s Gas Fee?

In this course, we’ll dive deep into understanding and minimizing these gas costs. Before we get into optimization techniques, it’s essential to get familiar with the foundational concepts and tools. This first lesson is dedicated to setting up our Remix development environment and introducing the core concept of gas in Ethereum. Let’s dive in!

Setting Up & Understanding Gas in Remix

Why Goerli Testnet?

Testnets in Ethereum resemble the main Ethereum network, sans the financial implications. These parallel networks allow developers to experiment without spending real Ether (ETH). We’re focusing on the Goerli Testnet due to its renowned stability and adoption in the Ethereum community.

Testnet Vs. Mainnet: What is the Difference?

Why Remix?

Remix, an open-source tool designed for Ethereum smart contract development, offers a user-friendly environment to craft, deploy, and test smart contracts. Its innate static analysis tools are paramount for our course, aiding in understanding the gas consumption of our functions.

Setting Up Goerli Testnet on Remix

  • Launch the Remix IDE in your browser.
  • Navigate to the Deploy & Run Transactions tab (it looks like a cube).
  • From the Environment dropdown, select Injected Provider. This option allows Remix to connect to any Web3 provider, like MetaMask.

  • Ensure MetaMask is connected to the Goerli Testnet. If you haven’t set it up, switch the network in MetaMask to Goerli Testnet.

  • Your Remix should now display the Goerli Testnet and your account address.

Deploying a Basic Contract on Goerli via Remix

Solidity
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.9;

contract SimpleStorage {
    uint256 public storedValue;

    function set(uint256 value) public {
        storedValue = value;
    }

    function get() public view returns (uint256) {
        return storedValue;
    }
}
  1. Copy the above contract.

  2. In Remix, under the Solidity tab, click on the + icon to create a new file. Name it SimpleStorage.sol.

  3. Paste the contract code.

  4. Navigate to the Deploy & Run Transactions tab.

  5. Click on the Deploy button. Confirm the MetaMask transaction. Your contract is now live on the Goerli Testnet! (before deploying the contact assure that you have enough GoerliETH in your Metamask Wallet, to request, please visit: https://goerlifaucet.com/ and follow the instructions)

Practical Task & Reflection

Experiment by interacting with the set and get functions of the deployed contract in Remix. Take note of the gas consumption. Reflect upon:

  • Which operations consume more gas?
  • How might the function’s complexity relate to its gas cost?

Your observations and reflections will set a solid foundation for the upcoming lessons centered around optimization.

免責事項
* 暗号資産投資には重大なリスクが伴います。注意して進めてください。このコースは投資アドバイスを目的としたものではありません。
※ このコースはGate Learnに参加しているメンバーが作成したものです。作成者が共有した意見はGate Learnを代表するものではありません。
カタログ
レッスン1

Setting Up & Understanding Gas in Remix

Welcome to the first lesson of our course, Gas Optimization Techniques with Remix!

Welcome to the first lesson of our course, Gas Optimization Techniques with Remix! If you’re reading this, you’ve probably had some experience with Ethereum smart contracts and might have noticed those pesky gas fees that come with every transaction and deployment. Gas ensures that the Ethereum network remains healthy and free from spam, but it also means that every line of code we write in our smart contracts can cost real money when executed.

If you are not an expert, here are some articles you can read before starting the course:

What is Ethereum?

What Are Smart Contracts?

What’s Gas Fee?

In this course, we’ll dive deep into understanding and minimizing these gas costs. Before we get into optimization techniques, it’s essential to get familiar with the foundational concepts and tools. This first lesson is dedicated to setting up our Remix development environment and introducing the core concept of gas in Ethereum. Let’s dive in!

Setting Up & Understanding Gas in Remix

Why Goerli Testnet?

Testnets in Ethereum resemble the main Ethereum network, sans the financial implications. These parallel networks allow developers to experiment without spending real Ether (ETH). We’re focusing on the Goerli Testnet due to its renowned stability and adoption in the Ethereum community.

Testnet Vs. Mainnet: What is the Difference?

Why Remix?

Remix, an open-source tool designed for Ethereum smart contract development, offers a user-friendly environment to craft, deploy, and test smart contracts. Its innate static analysis tools are paramount for our course, aiding in understanding the gas consumption of our functions.

Setting Up Goerli Testnet on Remix

  • Launch the Remix IDE in your browser.
  • Navigate to the Deploy & Run Transactions tab (it looks like a cube).
  • From the Environment dropdown, select Injected Provider. This option allows Remix to connect to any Web3 provider, like MetaMask.

  • Ensure MetaMask is connected to the Goerli Testnet. If you haven’t set it up, switch the network in MetaMask to Goerli Testnet.

  • Your Remix should now display the Goerli Testnet and your account address.

Deploying a Basic Contract on Goerli via Remix

Solidity
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.9;

contract SimpleStorage {
    uint256 public storedValue;

    function set(uint256 value) public {
        storedValue = value;
    }

    function get() public view returns (uint256) {
        return storedValue;
    }
}
  1. Copy the above contract.

  2. In Remix, under the Solidity tab, click on the + icon to create a new file. Name it SimpleStorage.sol.

  3. Paste the contract code.

  4. Navigate to the Deploy & Run Transactions tab.

  5. Click on the Deploy button. Confirm the MetaMask transaction. Your contract is now live on the Goerli Testnet! (before deploying the contact assure that you have enough GoerliETH in your Metamask Wallet, to request, please visit: https://goerlifaucet.com/ and follow the instructions)

Practical Task & Reflection

Experiment by interacting with the set and get functions of the deployed contract in Remix. Take note of the gas consumption. Reflect upon:

  • Which operations consume more gas?
  • How might the function’s complexity relate to its gas cost?

Your observations and reflections will set a solid foundation for the upcoming lessons centered around optimization.

免責事項
* 暗号資産投資には重大なリスクが伴います。注意して進めてください。このコースは投資アドバイスを目的としたものではありません。
※ このコースはGate Learnに参加しているメンバーが作成したものです。作成者が共有した意見はGate Learnを代表するものではありません。