LogoLogo
HomeBased Labs ResearchWhitepaper
  • 1: Introduction
    • BasedAI Mainnet Q&A Guide
    • Is Your AI Based?
    • BasedAI Ecosystem
    • The Role of Based CLI
  • 2: Installation
    • Minimum Requirements and Prerequisites
    • Installation Instructions
    • Verification of Installation & Troubleshooting
  • 3: Interaction with [Brains] and [Brainstore]
    • Section Overview
  • Using [basedcli brains]
    • [stem]: Retrieving Brain Information
    • [pow_memorize]: Registering Wallets with PoW
    • [memorize]: Associating Wallets with Brains
    • [parameters]: Viewing and Setting Brain Parameters
    • [list]: Viewing All Brains
  • Using [basedcli brainstore]
    • [list]: Accessing Community-Approved Brains
  • 4: Interaction with [Core] Network Operations
    • Section Overview
  • Using [basedcli core]
    • [list]: Listing Core Network Components
    • [weights]: Adjusting Influence on the Network
    • [get_weights]: Reviewing Current Distribution
    • [vote]: Participating in Governance
    • [gigabrains]: Viewing Current GigaBrains
    • [memorize]: Ensuring Network Recognition
    • [proposals]: Insight into Network Proposals
    • [delegate] & [undelegate]: Managing Staked Influence
  • 5: [Wallet] Functionality and Transactions
    • Section Overview
  • Using {basedcli wallet]
    • [list]: Viewing All Wallets
    • [overview]: Comprehensive Wallet Summary
    • [transfer]: Executing Token Transfers
    • [create]: Setting Up a New Wallet
    • [new_computekey] & [new_personalkey]: Generating Additional Keys
    • [regen_personalkey], [regen_personalkeypub], & [regen_computekey]: Regenerating Keys
  • 6: [Stake] Mechanics and [BrainOwner] Tools
    • Section Overview
  • Using [basedcli stake]
    • [show]: Show Stakes in Wallets
    • [add] & [remove]: Add or Remove Stakes
  • Using [basedcli brainowner]
    • [get]: Retrieve Brain Rules and Parameters
    • [set]: Adjusting Brain Parameters
  • 7: Commands Reference
    • Reference Table
  • 8: Implementing Smart Contracts in BasedAI
    • Introduction to the Ethereum Virtual Machine (EVM)
    • Prerequisites
    • Write a Smart Contract
    • Test & Deploy a Smart Contract
    • Tools and Technologies
    • Advanced Example: $PUMP Memecoin Launchpad
    • Advanced Example: AI Marketplace
    • Advanced Example: Brain #88 Access Token
  • 9: Forms
    • $BASED Faucet
    • Test Brain Ownership
    • Test Brain Tokens
Powered by GitBook
On this page
  1. 8: Implementing Smart Contracts in BasedAI

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.

PreviousPrerequisitesNextTest & Deploy a Smart Contract

Last updated 11 months ago