# BONUS - Launch your own token

{% hint style="warning" %}
**Important information**

This tutorial is based on the description provided by QuickNode which wrote the tutorial for testnet. You can find the original tutorial [here](https://www.quicknode.com/guides/ethereum-development/smart-contracts/how-to-create-and-deploy-an-erc20-token). The video is made by [Simple Crypto](https://www.youtube.com/@SimpleCryptoTV).&#x20;

When deploying your token on mainnet, you have to make sure you make the necessary changes as indicated throughout the text but not in the movie.
{% endhint %}

{% embed url="<https://www.youtube.com/watch?v=GY2d94FJWJI>" %}

## Set up MetaMask and get BTC on Botanix testnet

To get started, you will need the [Metamask](https://metamask.io/) browser extension to create an EVM wallet and some Bitcoin, which you can get by following the steps laid out on [this link](https://app.gitbook.com/s/TbKVxSyrQ5Fb5GJ2FDT1/getting-started/deposit).&#x20;

## Implement  contract

Head over to the [Ethereum Remix](https://remix.ethereum.org/) IDE and make a new Solidity file, for example `<YOUR_NAME>-token.sol` . Paste the following code into your new Solidity script:

{% code overflow="wrap" lineNumbers="true" %}

```solidity
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();
    }
}
```

{% endcode %}

Replace the following values:

* Line 52: Replace "**QKCToken"** with your own name (In the example it is BotanixTestToken)
* 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);

{% hint style="info" %}
**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).
{% endhint %}

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

<figure><img src="https://1545802676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGi5rTBkDfRkp6vDha0bT%2Fuploads%2Fv6BFk1RQfY0Swk0tu6z2%2F1.png?alt=media&#x26;token=767a32a0-f4a8-413d-8689-7d07193f5c66" alt=""><figcaption></figcaption></figure>

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

{% hint style="info" %}
**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).
{% endhint %}

<figure><img src="https://1545802676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGi5rTBkDfRkp6vDha0bT%2Fuploads%2FT7Nmhea5Vq5q1D08Pp2S%2F2.png?alt=media&#x26;token=9e8c5ab3-7884-45ca-8beb-b578880cdd21" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Gas fees**

If the gas fees appear to high to deploy the contract, try lowering them manually.&#x20;
{% endhint %}

<figure><img src="https://1545802676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGi5rTBkDfRkp6vDha0bT%2Fuploads%2Fe0VyLXH2dny5WgSMWS1C%2F3.png?alt=media&#x26;token=e0da5295-3ec4-4eae-8b77-d090d86a2b7c" alt="" width="356"><figcaption></figcaption></figure>

{% hint style="info" %}
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.
{% endhint %}

<figure><img src="https://1545802676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGi5rTBkDfRkp6vDha0bT%2Fuploads%2FeFBGsf21OB1LDnoeoMqH%2F4.png?alt=media&#x26;token=8b431389-6186-43ea-b554-22924917f7f5" alt="" width="356"><figcaption></figcaption></figure>

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

## 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.&#x20;

<figure><img src="https://1545802676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGi5rTBkDfRkp6vDha0bT%2Fuploads%2FLsV0VZTWAcAQreUHlNwh%2F5.png?alt=media&#x26;token=77c28efa-62e4-4d70-9db8-51e27b66625c" alt=""><figcaption></figcaption></figure>

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.

<figure><img src="https://1545802676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGi5rTBkDfRkp6vDha0bT%2Fuploads%2FQyZ38VwqlDybCYtNOByM%2F6.png?alt=media&#x26;token=7e8152c1-84fd-44fd-beff-dd86c36eadd1" alt="" width="355"><figcaption></figcaption></figure>
