Botanix Labs
Try TestnetBuild dAppsVisit website
  • 🕷️Welcome!
  • 🕷️Get to know the Technology
    • Introduction to Botanix Labs
    • Risk warning
    • Terminology
    • Basic knowledge
      • Proof-of-Stake
      • Ethereum Virtual Machine (EVM)
      • UTXO vs Account Based Model
    • Introductory concepts
      • The Botanix EVM
      • The Spiderchain
      • Orchestrator node
      • Deposit & Withdraw
      • Transaction fees
    • Advanced concepts
      • Bitcoin security inheritance
      • Bridging
      • Consensus
      • Finality
        • Finality in a Proof-of-Work (PoW)
        • Finality in a Proof-of-Stake (PoS)
        • Finality on Botanix EVM
      • Forward security
        • Forward security in cryptography
        • The Spiderchain's Forward Security
        • Inventory management
      • FROST
      • Reth
      • Orchestrators
      • Staking
    • Roadmap to Spiderchain
      • Single Node (Testnet)
      • Botanix Federation
        • Consensus - CometBFT
          • Byzantine Fault Tolerance (BFT)
        • Node types
        • Multisig details - FROST
        • Peg-in / Peg-out
      • Botanix Federation with Staking
      • Slashing
      • Spiderchain DynaFed
      • Permissionless staking
      • Fully Decentralized Layer 2
    • Deeper dive: Whitepaper
  • 🕷️How to use the Botanix EVM
    • Getting started with the Botanix EVM (testnet)
    • Risk warning
    • Step 1 - Set up your wallet
    • Step 2 - Get test funds
    • Step 3 - Send a transaction
    • Step 4 - Use dApps
    • Step 5 - Deploy your first contract / Launch your own token
    • Step 6 - Withdraw
    • FAQ - Testnet V1
  • 🚀Build dApps
    • Introduction
    • Risk warning
    • Tools
      • Useful links
      • Development Frameworks
      • Web3 libraries and tools
      • Oracle Tools
      • Block explorer
        • Routescan
      • Indexers
        • The Graph
        • SubQuery
      • WalletConnect
      • Account Abstraction with BTC Connect
      • Muticall3
    • Build on the Botanix EVM
      • Basic Botanix EVM Information
      • Gas fees
      • Develop a new dApp
      • Migrate existing dApps
      • Quickstart - Build a dApp with Botanix (Solidity, Hardhat)
  • 🕸️Run a node
    • Introduction
    • Run an RPC Node
  • 📔Glossary
Powered by GitBook
On this page
  • Set up MetaMask and get BTC on Botanix testnet
  • Implement contract
  • Get token in MetaMask
  1. How to use the Botanix EVM

Step 5 - Deploy your first contract / Launch your own token

PreviousStep 4 - Use dAppsNextStep 6 - Withdraw

Last updated 6 months ago

This tutorial is based on the description provided by QuickNode. You can find the original tutorial . The video is made by .

Set up MetaMask and get BTC on Botanix testnet

Implement contract

pragma solidity ^0.4.24;

//Safe Math Interface

contract SafeMath {

    function safeAdd(uint a, uint b) public pure returns (uint c) {
        c = a + b;
        require(c >= a);
    }

    function safeSub(uint a, uint b) public pure returns (uint c) {
        require(b <= a);
        c = a - b;
    }

    function safeMul(uint a, uint b) public pure returns (uint c) {
        c = a * b;
        require(a == 0 || c / a == b);
    }

    function safeDiv(uint a, uint b) public pure returns (uint c) {
        require(b > 0);
        c = a / b;
    }
}


//ERC Token Standard #20 Interface

contract ERC20Interface {
    function totalSupply() public constant returns (uint);
    function balanceOf(address tokenOwner) public constant returns (uint balance);
    function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
    function transfer(address to, uint tokens) public returns (bool success);
    function approve(address spender, uint tokens) public returns (bool success);
    function transferFrom(address from, address to, uint tokens) public returns (bool success);

    event Transfer(address indexed from, address indexed to, uint tokens);
    event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}


//Contract function to receive approval and execute function in one call

contract ApproveAndCallFallBack {
    function receiveApproval(address from, uint256 tokens, address token, bytes data) public;
}

//Actual token contract

contract QKCToken is ERC20Interface, SafeMath {
    string public symbol;
    string public  name;
    uint8 public decimals;
    uint public _totalSupply;

    mapping(address => uint) balances;
    mapping(address => mapping(address => uint)) allowed;

    constructor() public {
        symbol = "QKC";
        name = "QuikNode Coin";
        decimals = 2;
        _totalSupply = 100000;
        balances[YOUR_METAMASK_WALLET_ADDRESS] = _totalSupply;
        emit Transfer(address(0), YOUR_METAMASK_WALLET_ADDRESS, _totalSupply);
    }

    function totalSupply() public constant returns (uint) {
        return _totalSupply  - balances[address(0)];
    }

    function balanceOf(address tokenOwner) public constant returns (uint balance) {
        return balances[tokenOwner];
    }

    function transfer(address to, uint tokens) public returns (bool success) {
        balances[msg.sender] = safeSub(balances[msg.sender], tokens);
        balances[to] = safeAdd(balances[to], tokens);
        emit Transfer(msg.sender, to, tokens);
        return true;
    }

    function approve(address spender, uint tokens) public returns (bool success) {
        allowed[msg.sender][spender] = tokens;
        emit Approval(msg.sender, spender, tokens);
        return true;
    }

    function transferFrom(address from, address to, uint tokens) public returns (bool success) {
        balances[from] = safeSub(balances[from], tokens);
        allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
        balances[to] = safeAdd(balances[to], tokens);
        emit Transfer(from, to, tokens);
        return true;
    }

    function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
        return allowed[tokenOwner][spender];
    }

    function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
        allowed[msg.sender][spender] = tokens;
        emit Approval(msg.sender, spender, tokens);
        ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
        return true;
    }

    function () public payable {
        revert();
    }
}

Replace the following values:

  • Line 62: symbol = "QKC"; Choose your own symbol

  • Line 63: name = "QuikNode Coin"; Choose your own name

  • Line 64: decimals = 2; set the decimal (value in which tokens can be divided, 0 to 8 decimal units can be used) and establish a total supply value as you wish

  • Line 65 _totalSupply = 100000; Choose a total supply

  • Line 66: balances[YOUR_METAMASK_WALLET_ADDRESS] = _totalSupply; Please change YOUR_METAMASK_WALLET_ADDRESS to your own wallet address (This one can be found in your MetaMask interface)

  • Line 67: emit Transfer(address(0), YOUR_METAMASK_WALLET_ADDRESS, _totalSupply);

Note: The total supply value must have additional trailing zeros as specified by the decimals field. For example, the decimals value in this contract is 2 and we need a total supply of 1000 tokens, so we’ll have to set the total supply variable to 100000 (simply because it won’t allow a decimal point).

Compile the smart contract. Make sure you select the right compiler based on the chosen Solidity version.

Deploy it using injected Web3 (make sure to select Botanix testnet on MetaMask before compiling the contract) and select the right contract to be deployed. Approve the transaction from MetaMask.

Note: We need to deploy the main token contract, select the name of the contract appropriately under the contracts section before deploying the contract (BotanixTestToken here).

If you receive an error message before deployment “This contract may be abstract”, make sure to select the appropriate contract under the Contract tab. Confirm the transaction in Metamask.

That’s it! your token contract is now deployed on Bitcoin’s Botanix testnet!

Get token in MetaMask

To get the token in Metamask, go to the “Deployed Contracts” section in Remix and copy the deployed contract’s address using the copy button near the contract’s name.

Open Metamask, go to the Token tab and click on the Import Tokens button. Paste the contract’s address in the first field. Metamask will fetch the Token Symbol and decimals automatically.

To get started, you will need the browser extension to create an EVM wallet and some test Bitcoin, which you can get by following the steps laid out in Step 2 - Get test funds.

Head over to the IDE and make a new Solidity file, for example Botanix-token.sol . Paste the following code into your new Solidity script:

🕷️
Metamask
Ethereum Remix
here
Simple Crypto