Deploying Contract
Last updated
Last updated
This tutorial is meant for developers who are new to Glide and Solidity. If you're already familiar with Solidity, consider reading the Glide Stack Differences guide to understand how Glide differs from Ethereum. Glide is designed to "just work" with existing Ethereum tooling, so you can use the tools you already know like Hardhat or Foundry just like you would on Ethereum.
This tutorial walks you through the process of deploying your first smart contract to Glide using the Remix in-browser Solidity IDE.
Firefox or any Chromium-based browser (Chrome, Brave, Edge, etc.)
You'll need access to an Ethereum wallet if you want to deploy a smart contract. This tutorial uses MetaMask, a popular browser extension wallet, just to get you started. MetaMask is also available as a mobile application, but it's typically easier to use the browser extension for development. If you already have MetaMask installed, you can skip this section.
Browser-based wallets like MetaMask are convenient for development, but they're not the most secure option. You should never store large amounts of GLDR or GRC-20 tokens in a browser-based wallet. If you're planning to store a significant amount of GLDR or GRC-20 tokens, consider using a hardware wallet instead.
Head over to metamask.io and click the "Download" button. You'll then be given an option to install the MetaMask extension for your browser. If using a Chromium-based browser, you may be prompted to install the MetaMask extension from the Chrome Web Store. An onboarding page will pop up once the extension is installed.
MetaMask will ask you to accept their terms of service. Read them carefully, then tick the box to accept them. Once you've accepted the terms of service, you can create a new wallet by clicking the "Create a new wallet" button.
After starting the wallet creation process you'll be asked if you'd like to share usage data with MetaMask. This is entirely up to you. Select "I agree" or "No thanks" depending on your preference.
You'll be asked to create a password for your wallet. This password will be used to encrypt your wallet, so make sure it's a strong one that you won't forget.
You'll be asked to confirm that you understand MetaMask cannot recover your password if you lose it. You may want to store this password in a password manager. Remember, browser-based wallets are great for development but are not the most secure option. Consider looking into a hardware wallet if you're planning to store a significant amount of ETH / GLDR or ERC-20 tokens.
Once you've written down your password, click "Create a new wallet" to continue.
MetaMask will now show you a short video about wallet security. If this is your first time using MetaMask or a browser-based wallet, it's recommended that you watch the video.
You'll be presented with the option to "Secure my wallet (recommended)" or "Remind me later (not recommended)". It's strongly recommended to continue with the "Secure my wallet (recommended)" option. This will prompt you to back up your wallet and might prevent you from losing access to your wallet down the line.
After continuing with "Secure my wallet (recommended)", you'll be asked to write down a 12 word secret recovery phrase. This phrase can be used to recover your wallet if you lose your password or the browser extension somehow becomes corrupted. Write these words down somewhere safe and keep them secret. For a development wallet, it's fine to keep the phrase in a password manager. Just don't place too much importance in this wallet.
After writing down your secret recovery phrase, you'll be asked to confirm it. This is to make sure you wrote it down correctly. MetaMask will ask you to input a few of the words you wrote down. Make sure to input them in the correct order.
You're all done! Read through the final page to get some more tips from MetaMask, then click "Got it!" when you're ready to continue.
Want to explore wallets other than MetaMask? There are many different kinds of wallets out there. You can use Ethereum.org's "Find a wallet" feature(opens in a new tab) to find one that works for you.
This tutorial will show you how to deploy a smart contract to Glide. In order to interact with Glide using MetaMask, you'll need to add it as a custom network.
Click Dropdown menu on the top left corner and Add Network.
And you will see a pop-up "Network Added Successfully!" Now it's time to switch to the Glide Protocol
You'll need some GLDR on Glide to pay for the gas fees associated with deploying a smart contract. You can use the Rollup Faucet to get some free GLDR on Glide.
After you get some GLDR on Glide, you can check your wallet balance in MetaMask. Make sure that your balance has updated before continuing. If you don't see any GLDR in your wallet, double check that your MetaMask is connected to the Glide network.
The most popular smart contract development language today is Solidity. In this tutorial, you'll be using a browser-based integrated development environment (IDE) called Remix. Remix is a great tool for learning Solidity because it requires minimal setup and runs in your browser.
Head over to remix.ethereum.org to open Remix. You'll be presented with a welcome screen and a popup asking if you'd like to share usage data with Remix. Accept or decline this request depending on your preferences.
This tutorial will show you how to deploy a simple contract that has a storage variable you can read and write. You'll be able to update this variable with a transaction and then retrieve the updated value. This is just a simple example to get you started. Solidity is a powerful language that can be used to write complex smart contracts.
Copy and paste the following code into the file you just created. Remix will detect copy/pasted code and give you a warning about it. This is meant to prevent you from accidentally running malicious code. Always be careful when copy/pasting code from the internet!
By default, Remix will automatically compile your contract when you save it. You can also manually compile your contract by clicking the "Solidity Compiler" icon in the left sidebar and then clicking the "Compile" button. It's usually easier to leave automatic compilation enabled. You shouldn't see any compilation errors for this contract.
Now that you've written your first contract, you can deploy it to Glide Network. Deploying contracts with Remix is pretty straightforward.
Click on the "Deploy & run transactions" icon in the left sidebar to open the Deploy tab (it looks like an Ethereum logo with an arrow pointing to the right). You'll see some deployment options and a list of contracts that are currently compiled. Since you only have one contract, you should see a single contract called "MyFirstContract" in the list.
By default, Remix will try to deploy your contract to a local, in-memory blockchain. This is useful for testing, but you'll need to change your environment to deploy to Glide for this tutorial. Click on the dropdown underneath the "Environment" heading and select "Injected Provider - MetaMask".
Once you've selected the "Injected Provider - MetaMask" option, MetaMask will show you a popup asking if you'd like to connect to Remix. Accept this request by clicking the "Connect" button.
You're now ready to deploy your contract! Click the orange "Deploy" button to deploy your contract to Glide. You'll be presented with another MetaMask popup asking you to confirm the transaction. Click the "Confirm" button to continue.
Glide is relatively fast, so transactions should confirm within just a few seconds. Remix will automatically detect when your transaction has confirmed and will show you your newly deployed contract under the "Deployed Contracts" heading within the Deploy tab.
Now that you've deployed your contract, you can interact with it. Remix makes it easy to interact with your contract by providing a built-in user interface. You can use this interface to call functions on your contract and read its state.
Click on the arrow next to the name of your contract under the "Deployed Contracts" heading to expand it. You should see a list of functions that you can call on your contract.
Now you'll update the message variable in your contract. Type a message into the input box next to the orange "setMessage" button and click on the "setMessage" button. Just like when you deployed your contract, you'll be presented with a MetaMask popup asking you to confirm the transaction. Click the "Confirm" button to continue.
Once again, Remix will automatically detect when your transaction has confirmed. You'll see a green checkmark appear in the console at the bottom of the screen.
Click on the "message" button to read the updated message variable. You should see the message you set in the previous step appear underneath the "message" button. Congrats, you've successfully deployed and interacted with your first smart contract on Glide!
How Your Contract Works
Now that you've deployed your contract, you might be wondering how it works. Let's take a closer look at the code you wrote.
The first line of most Solidity files is the license identifier. This line is used to specify the license under which the code is released. In this case, the code w
ritten is released under the MIT license.
The next line is a pragma directive. This line tells the Solidity compiler which version of the Solidity language to use. In this case, the code is written for Solidity version 0.8.0 or higher.
The next line defines a contract called MyFirstContract
. A contract is a collection of code and data that is stored at a specific address on the blockchain. You can think of a contract as a class in an object-oriented programming language. The contract definition is followed by a pair of curly braces that contain the contract's code.
The first thing you'll notice inside the contract definition is a variable called message
. This variable is declared as a string
, which is a Solidity type that represents a string of characters. The public
keyword means that this variable can be read from outside the contract.
The next thing you'll notice is a function called setMessage
. This function takes a single argument called _message
of type string
. The public
keyword means that this function can be called from outside the contract by anyone. Since this function doesn't have any access control, anyone can update the message
variable.
To learn more about Solidity, check out the Solidity documentation for more information about the language itself. If you learn best by reading source code, check out this annotated code for an ERC-20 token contract. Now that you know how to deploy a smart contract to Glide