How to Create CRC20 Token Faucet on Coinex Smart Chain


Crypto Faucet is an application, or website or smart contract, which allows users to get tokens or coins in small amounts, usually to get crypto tokens, users have to complete tasks listed on the faucet application, for example input ReChaptvha, download applications or watch advertisements. Faucets are usually used to promote certain projects or tokens to make them more familiar to users and more popular.

Faucets are free, this will attract public attention to get free tokens on the faucet platform. Actually, faucet developers lose because they have to spend money to share crypto for free, but it’s not always a loss, developers can get more attention from users and the project is better known

Faucets were once popular during the early days of cryptocurrency, and have now become a milestone in the cryptocurrency world. In this article we will provide a tutorial on how to make a crc20 coinex smart chain token faucet, the faucet we made is a smart contract type, which later you can add a web application (reactjs) to the frontend.

 

What is Needed?

1# Wallet

The wallet is used to store coin cet, crc20 tokens and for transactions on the coinex smart chain blockchain, you can use a metamask wallet. You can download the metamask extension on the official metask website. After you create a metamask wallet, immediately set the rpc wallet to rpc coinex smart chain mainnet or testnet

RPC URL : https://rpc.coinex.net
Network Name : Coinex Smart Chain
ChainID : 52
Symbol : CET
Block Explorer : https://www.coinex.net

 

2# CET Coin

Coin CET is the native coin of the coinex smart chain blockchain, the coin is used to pay for transactions, swaps or interact contracts on the network. You can get these coins on Coinex Exchange. After you get some coins, immediately send it to your metamask wallet.

 

3# CRC20 Smart Contract

Coin CET is the native coin of the coinex smart chain blockchain, the coin is used to pay for transactions, swaps or interact contracts on the network. You can get these coins on Coinex Exchange. After you get some coins, immediately send it to your metamask wallet

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

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

contract TokenFaucet1 is ERC20, ERC20Burnable {
constructor() ERC20("Token Faucet 1", "TF1") {
_mint(msg.sender, 1000000 * 10 ** decimals());
}
}

 

4# Faucet Smart Contract

This smart contract is used to create a faucet function on the coinex smart chain blockchain, which later users or anyone can get free tokens from the smart contract (with applicable conditions).

// SPDX-License-Identifier: MIT

pragma solidity ^0.6.1;

interface ERC20 {
    function transfer(address to, uint256 value) external returns (bool);
    event Transfer(address indexed from, address indexed to, uint256 value);
}

contract Faucet {
    uint256 constant public tokenAmount = 100000000000000000000;
    uint256 constant public waitTime = 3000 minutes;

    ERC20 public tokenInstance;
    
    mapping(address => uint256) lastAccessTime;

    constructor(address _tokenInstance) public {
        require(_tokenInstance != address(0));
        tokenInstance = ERC20(_tokenInstance);
    }

    function requestTokens() public {
        require(allowedToWithdraw(msg.sender));
        tokenInstance.transfer(msg.sender, tokenAmount);
        lastAccessTime[msg.sender] = block.timestamp + waitTime;
    }

    function allowedToWithdraw(address _address) public view returns (bool) {
        if(lastAccessTime[_address] == 0) {
            return true;
        } else if(block.timestamp >= lastAccessTime[_address]) {
            return true;
        }
        return false;
    }
}

 

How to Make a Coinex Smart Chain CRC20 Faucet

1# Deploy CRC20 Smart Contract

To create a token in the coinex smart chain, you need to deploy the above smart contract using the Remix IDE

  • Open Remix ide.coinex.net
  • Create a new file, and paste the crc20 smart contract (above)
  • Create a new file, and paste the crc20 smart contract (above)
  • Deploy the smart contract

 

2# Deploy Faucet Smart Contract
  • Create a file in the ide remix, and compile the smart contract to completion
  • Edit WaitTime & TokenAmount on smart contract
  • uint256 constant public tokenAmount = Is the number of tokens that we get when we request to the faucet smart contract
  • uint256 constant public waitTime = Is waiting time for re-request (token on faucet)
  • Enter the smart contract address (crc20 token)
  • Deploy smart contract Faucet

 

3# CRC20 & Faucet Smart Contract Verification

After the process of deploying the crc20 smart contract and faucet is complete, then you have to verify the smart contract in the coinex explorer. The verification function is to publish the smart contract code, and later anyone can see the code. Verification also serves to make it easier for users to interact with the smart contract.

  • Install the flattener plugin in the ide remix
  • Flat file smart contract & save the flat file
  • Flat file smart contract & save the flat file
  • Choose “Contract Info”
  • Choose “Verify & Publish”
  • Enter all the required details in the form
  • Smart contract verification

 

4# Send CRC20 Token to Smart Contract Faucet

Send crc20 tokens to the faucet smart contract with an amount that matches your plan. I suggest you send in stages to avoid spammers claiming using multiple accounts at once

Smart Contract Faucet Information

5# Smart Contract Faucet Information

Read Contract

  • allowedToWithdraw = to find out if your address is able to request tokens
  • tokenAmount = to find out the number of tokens you get for 1 time request
  • tokenInstance = address smart contract token crc20
  • waitTime = waiting time to re-request

Write Contract

  • requestTokens = waiting time to re-request

 

6# Test Faucet

After everything is ready, you can test the request token on the smart contract faucet using another wallet

  • Enter the faucet smart contract in the coinex explorer
  • Click “Write Contract”
  • Connect your wallet
  • Click “RequestToken” , Write and confirm in your wallet
  • Wait 3-5 seconds, you will get a token from the faucet smart contract

The faucet only allows token requests per 3000 minutes, when you make a request for the first time then you have to wait 3000 minutes to make a re-request.

good luck


Alif Fahmi

hi , I'm Alif, I'm a blockchain & cryptocurrency lover, I love writing & learning, my job is web developer & crypto trader