DEPLOYING YOUR FIRST SMART CONTRACT

In this tutorial, we will go through how to create, deploy and interact with a smart contract on Gather Testnet.

Here we will use metamask as our wallet and remix IDE to compile and deploy our smart contract. You can use a different wallet and other frameworks like Hardhat or Truffle as well.

PREREQUISITES

  • Metamask wallet configured with Gather testnet

  • Testnet GTHs. You can use Gather Faucet to get some testnet GTH.

Here we will create a very simple greeting smart contract to set a greeting message and get the greeting message.

STEP-1

Open Remix IDE on your web browser.

STEP -2

Create a file myFirstContract.sol, copy the code mentioned below and paste it there.

You can get the code from here as well - https://github.com/GatherNetwork/Greetings-Smart-Contract.git

// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0; 
contract Greetings { 
     string message;
     constructor() {
           message = "Hello";
      }

     function setGreetings(string memory _message) public {
           message = _message;
      }

      function getGreetings() public view returns (string memory) {
           return message;
      }
 }

STEP-3

Compile your smart contract and go to the deploy section of Remix.

STEP-4

In the environments section select inject web3 and connect your MetaMask account with enough GTHs.

STEP-5

Make sure you have switched to the Gather testnet network on your MetaMask.

Now you can deploy your smart contract by clicking on deploy. Here you will get a MetaMask popup for a contract creation transaction, you can approve the transaction for successful deployment of the contract.

STEP-6

It will take around 20 secs to successfully deploy the contract on Gather testnet.

Once the contract is deployed you can now interact with the contract in the deployed contracts section in Remix.

Here you can see the public functions getGreetings and setGreetings in our smart contract.

To set a greeting message, enter a message in the parameter value and click on setGreetings.

This will trigger a transaction and you will get a popup on MetaMask, approve the transaction on the MetaMask.

STEP-7

Now you have set a greeting message, to see the greeting message you can click on getGreetings and we can check the greeting message in the response body.

Here in the decoded output, you can see the greeting message ("Hello Gather Testnet!") as a string response.

Now you have successfully created a smart contract, deployed it on the Gather testnet, and interacted with the deployed smart contract on the Gather testnet.

You can follow the same guide for mainnet as well, you just need to configure your MetaMask to Gather mainnet and switch your MetaMask network to Gather mainnet.

Similarly, you can write, deploy and interact with complex smart contracts and dapps on Gather mainnet and testnet. You can also use different development frameworks for smart contract and dapp development like Hardhat and Truffle.

Last updated