Write a Smart Contract

Developing a Smart Contract

Step 1: Set Up the Development Environment

  • Install MetaMask and configure it for the Cyan BasedAI Testnet.

  • Obtain test tokens from the BasedAI faucet to fund transactions.

Step 2: Writing the Smart Contract

Remix IDE will be used for writing and deploying smart contracts.

  • Open Remix IDE.

  • Create a new file with a .sol extension.

Writing a Sample ERC20 Contract

Here is a commented example of an ERC20 contract which would be named "AchievementToken.sol":

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

// AchievementToken contract is an ERC20 token that can be issued by the contract owner to reward users for completing specific tasks or challenges.
contract AchievementToken is ERC20, Ownable {  
    // Event to be emitted when a new achievement token is issued
    event TokenIssued(address indexed to, uint256 amount, string achievement);  
  
    // Constructor that initializes the ERC20 token with a name and symbol
    constructor() ERC20("AchievementToken", "ATK") Ownable(msg.sender) {
        // The Ownable constructor is called with msg.sender as the initial owner
    }
  
    // Function to issue tokens to a specific address. Can only be called by the owner of the contract.
    function issueToken(address to, uint256 amount, string memory achievement) external onlyOwner {
        _mint(to, amount);
        emit TokenIssued(to, amount, achievement);
    }
}

This is a very simple contract that anyone can issue. It is recommended that anyone who wants to test out deploying contracts on Cyan issue a version of this one, obviously swapping out AchievementToken and ATK for whatever you prefer, as your first smart contract.

Last updated