Examples

Sample ERC20 Implementation of Laïka Token

// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;

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

contract Laika is ERC20, ERC20Burnable, Ownable, ERC20Permit {
    constructor(address initialOwner)
        ERC20("Laika", "LAIKA")
        Ownable(initialOwner)
        ERC20Permit("Laika")
    {
        _mint(msg.sender, 2100000 * 10 ** decimals());
    }

    function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }
}

Interacting with a smart contract using Ethers.js to view balance and send token

const ethers = require('ethers');

// Replace with your provider URL 
const provider = new ethers.providers.JsonRpcProvider('https://testnet1.laikachain.dog');

// Replace with your contract address
const laikaContractAddress = '0xYOUR_LAIKA_CONTRACT_ADDRESS';

// Replace with your private key (**WARNING: Keep this secure!**)
const signer = new ethers.Wallet('YOUR_PRIVATE_KEY', provider);

// Define contract ABI (replace with your actual ABI)
const laikaAbi = [
  "function balanceOf(address owner) public view returns (uint256)",
  "function transfer(address recipient, uint256 amount) public returns (bool)",
];

async function main() {
  // Create a contract instance for Laika
  const laikaContract = new ethers.Contract(laikaContractAddress, laikaAbi, signer);

  // Fetch your Laika token balance (replace with your address)
  const yourAddress = '0xYOUR_ADDRESS';
  const balance = await laikaContract.balanceOf(yourAddress);
  const formattedBalance = ethers.utils.formatUnits(balance, 18); 
  console.log(`Your Laika token balance: ${formattedBalance}`);

  // Define recipient address
  const recipientAddress = '0xRECIPIENT_ADDRESS';

  // Define transfer amount (replace with desired amount)
  const transferAmount = ethers.utils.parseUnits('100', 18); // Send 100 Laika tokens 

  // Send Laika tokens to recipient
  const tx = await laikaContract.transfer(recipientAddress, transferAmount);
  console.log(`Transaction hash: ${tx.hash}`);

  // Wait for transaction confirmation (optional)
  const receipt = await tx.wait();
  console.log(`Transaction confirmed at block number: ${receipt.blockNumber}`);
}

main()
  .then(() => console.log('Laika interaction successful!'))
  .catch((error) => console.error('Error:', error));

Last updated