3. Smart Contract Development

Sample Contract Structure

Your project should have this structure:

project-root/
├── contracts/
│   └── Lock.sol (or your contract)
├── scripts/
│   └── deploy.js
├── test/
│   └── Lock.js
├── ignition/
│   └── modules/
│       └── Lock.js
├── hardhat.config.js
└── package.json

Example Smart Contract (contracts/Lock.sol)

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

contract Lock {
    uint public unlockTime;
    address payable public owner;

    event Withdrawal(uint amount, uint when);

    constructor(uint _unlockTime) payable {
        require(
            block.timestamp < _unlockTime,
            "Unlock time should be in the future"
        );

        unlockTime = _unlockTime;
        owner = payable(msg.sender);
    }

    function withdraw() public {
        require(block.timestamp >= unlockTime, "You can't withdraw yet");
        require(msg.sender == owner, "You aren't the owner");

        emit Withdrawal(address(this).balance, block.timestamp);

        owner.transfer(address(this).balance);
    }
}

Last updated