How To Deploy a Faucet for Your Token on the Polygon Network

Source Node: 982179

Navigate to the Remix IDE. Create a new file called Faucet.sol and add the following contents to the file:

Note: I assume you already have a token deployed on the Mumbai testnet. If you haven’t deployed your token, please go through this article. It uses BSC, but the same method can be followed to deploy the token on the Mumbai testnet as well. Only the MetaMask should be configured to work with Mumbai testnet.

I have deployed a simple token called the “Sample Medium Token (SMT)” on the Mumbai testnet for testing purposes, and this faucet will drip 1 SMT token (that can be changed) at an interval of five minutes to the requesting wallet address.

So let’s compile the contract and deploy it to the Mumbai testnet.

For deployment, we need some testnet Matic tokens. The steps to compile and deploy a contract using Remix can also be found in the article mentioned above. During deployment, the tokenAddress and the ownerAddress should be passed for the contract initialisation.

The faucet has four methods:

  1. send() — This function sends 1 SMT (default) to the requesting wallet. It should be noted that a mapping (nextRequestAt) has been declared to implement a basic rate limit mechanism. There should be at least an interval of five minutes in between two subsequent calls made from a single wallet.
  2. setTokenAddress (address) — This method can be used by the faucet owner/admin to update the underlying token address. For example, if we are launching a new version of the token (e.g. SMTv2), we can pass the new token address to this method so that the faucet starts dripping the new token instead of the old one. This is somewhat similar to the “Adapter method” that is followed in the Upgradable contracts.
  3. setFaucetDripAmount (uint256) — Using this method, the owner can increase or decrease the number of tokens sent per request. The default value is 1 SMT.
  4. withdrawTokens (address,uint256)The faucet owner can use this to withdraw the tokens from the smart contract.

We need to manually deposit some tokens into the faucet contract as soon as the contract is deployed.

Sending tokens to the faucet

Aside from the send() method, the other three functions can only be called by the faucet owner. Therefore, the onlyOwner modifier is passed.

Source: https://betterprogramming.pub/how-to-deploy-a-faucet-for-your-token-on-the-polygon-network-363785e52d67?source=rss——-8—————–cryptocurrency

Time Stamp:

More from Medium