1.4 Hello World Contract

Let’s deploy a simple “Hello Avilom” smart contract to verify setup.

Contract Code

Create contracts/HelloAvilom.sol:

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

contract HelloAvilom {
    string public greeting = "Hello, Avilom!";

    function setGreeting(string calldata _greeting) external {
        greeting = _greeting;
    }
}

Deployment Script

Add to scripts/deploy.js:

async function main() {
  const [deployer] = await ethers.getSigners();
  console.log("Deploying with:", deployer.address);

  const Hello = await ethers.getContractFactory("HelloAvilom");
  const hello = await Hello.deploy();
  await hello.deployed();

  console.log("Deployed to:", hello.address);
}

main().then(() => process.exit(0)).catch(error => {
  console.error(error);
  process.exit(1);
});

Deploy to Testnet

npx hardhat run scripts/deploy.js --network avilomTestnet

🧠 Note the printed contract address.

Interact via Console

npx hardhat console --network avilomTestnet
const Hello = await ethers.getContractAt("HelloAvilom", "YOUR_CONTRACT_ADDRESS");
await Hello.greeting(); // "Hello, Avilom!"
await Hello.setGreeting("Hi, AI Blockchain!");
await Hello.greeting(); // "Hi, AI Blockchain!"

🎉 Congratulations—you’ve deployed and interacted with your first Avilom smart contract!

Last updated