Deploy Your First Smart Contract

Learn how to deploy a simple smart contract on the SNFT testnet.

Prerequisites

Before deploying a smart contract, make sure you have:

  • Connected your wallet to SNFT testnet (see previous tutorial)
  • Obtained test SNFT tokens from the faucet
  • Basic understanding of Solidity (Ethereum's smart contract language)

Creating a Simple Smart Contract

Let's create a simple "Hello World" smart contract that stores a greeting message.

Step 1: Open Remix IDE

Go to Remix IDE in your browser.

Step 2: Create a New File

Click on the "File explorers" icon, then click the "+" icon to create a new file. Name it "HelloWorld.sol".

Step 3: Write Your Smart Contract

Copy and paste the following code into your file:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract HelloWorld {
    string private greeting;
    
    constructor(string memory _greeting) {
        greeting = _greeting;
    }
    
    function setGreeting(string memory _greeting) public {
        greeting = _greeting;
    }
    
    function getGreeting() public view returns (string memory) {
        return greeting;
    }
}

Step 4: Compile the Contract

Click on the "Solidity compiler" icon in the left sidebar, then click "Compile HelloWorld.sol".

Step 5: Deploy the Contract

Click on the "Deploy & run transactions" icon in the left sidebar. In the "ENVIRONMENT" dropdown, select "Injected Provider - MetaMask". This will connect Remix to your MetaMask wallet.

Make sure your MetaMask is connected to SNFT testnet. In the "CONTRACT" dropdown, select "HelloWorld". In the "DEPLOY" section, enter an initial greeting (e.g., "Hello, SNFT!"), then click "Deploy".

MetaMask will prompt you to confirm the transaction. Click "Confirm" to deploy your contract.

Verifying Your Contract

After deployment, you'll get a contract address. You can verify your contract on the SNFT testnet block explorer:

  1. Go to https://texplorer.snft.in
  2. Search for your contract address
  3. Click on the "Contract" tab
  4. Click "Verify & Publish" and follow the instructions

Interacting with Your Contract

Once deployed, you can interact with your contract through:

  • Remix IDE (if you used Remix for deployment)
  • The block explorer's "Write Contract" and "Read Contract" sections
  • A custom frontend application
  • Hardhat scripts