Deploying Your First Smart Contract

This guide will walk you through the process of creating, compiling, and deploying your first smart contract on the Ettios blockchain.

Prerequisites

Before you begin, make sure you have:

  • Node.js (v14 or later) and npm installed
  • MetaMask configured with Ettios network
  • Some ETTIA tokens for transaction fees

Setting Up Your Project

First, let's create a new project directory and initialize it:

mkdir my-first-contract
cd my-first-contract
npm init -y
BASH

Next, install Hardhat, which we'll use for development and deployment:

npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox
BASH

Initialize a Hardhat project:

npx hardhat init
BASH

Choose "Create a TypeScript project" when prompted.

Creating a Simple Smart Contract

Replace the contents of contracts/Lock.sol with the following simple greeting contract:

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

contract Greeter {
    string private greeting;

    constructor(string memory _greeting) {
        greeting = _greeting;
    }

    function greet() public view returns (string memory) {
        return greeting;
    }

    function setGreeting(string memory _greeting) public {
        greeting = _greeting;
    }
}
SOLIDITY

Configuring Hardhat for Ettios

Update your hardhat.config.ts file to include the Ettios network:

import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import * as dotenv from "dotenv";

dotenv.config();

// Get private key from .env file
const PRIVATE_KEY = process.env.PRIVATE_KEY || "";

const config: HardhatUserConfig = {
  solidity: "0.8.19",
  networks: {
    ettiosTestnet: {
      url: "https://testnet-rpc.ettiosblockchain.io",
      accounts: [PRIVATE_KEY],
      chainId: 2238,
    },
    ettiosMainnet: {
      url: "https://rpc.ettiosblockchain.io",
      accounts: [PRIVATE_KEY],
      chainId: 2237,
    }
  }
};

export default config;
TYPESCRIPT

Create a .env file in your project root to store your private key (never commit this file to version control):

PRIVATE_KEY=your_metamask_private_key_here
PLAINTEXT

To get your private key from MetaMask:

  1. Open MetaMask
  2. Click on the three dots menu
  3. Select "Account details"
  4. Click "Export Private Key"
  5. Enter your password and copy the private key

Install dotenv:

npm install --save-dev dotenv
BASH

Also create a .gitignore file:

node_modules
.env
coverage
coverage.json
typechain
typechain-types

# Hardhat files
cache
artifacts
PLAINTEXT

Next Steps

Congratulations! You've deployed and interacted with your first smart contract on Ettios. Some next steps you might want to explore: