# Deploying rewarder contract for communities on Mantle Testnet

DAOs and Rewards go hand in hand. In this tutorial, we will learn how to <mark>deploy a contract that will reward 100 tokens to users who hold an NFT on Mantle Testnet.</mark>  
This is a great way to get started in writing smart contracts.

Before we get started with development, let me explain what the Mantle network is.

Mantle Network is a layer 2 solution built on top of the Ethereum blockchain which aims to offer super scalability by implementing a modular approach. This also means Mantle will offer low gas fees and increased security.

Before we proceed, <mark>We must make sure to have Metamask with Mantle Network added to your wallet</mark>, to do so visit [Chainlist](https://chainlist.org/?search=mantle&testnets=true).

1\. Connect your wallet to Chainlist and click *Add to Metamask*

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685803099712/79ba7c15-9873-4097-9f55-1244822e1fc2.png align="center")

Now let's <mark>claim some testnet </mark> **<mark>$BIT</mark>** <mark>tokens</mark> which will be used to pay for gas fees.

1. Visit [https://faucet.testnet.mantle.xyz/](https://faucet.testnet.mantle.xyz/) and connect your metamask with Goerli Network where $BIT tokens will be minted and sent to your wallet.
    

Then head over to [https://bridge.testnet.mantle.xyz/](https://bridge.testnet.mantle.xyz/) and connect your wallet with Mantle test network. You can now bridge $BIT tokens from Goerli to Mantle Testnet.

Okay, so we have test $BIT, let's get started.

We will use Remix IDE for writing, compiling and deploying our contracts onto Mantle testnet. <mark>Remix IDE is the simplest and best IDE to get started</mark>.

Visit [https://remix.ethereum.org/](https://remix.ethereum.org/) to start writing your first contract.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685803733715/7905ed7a-ada5-4052-8719-2f276a365648.png align="center")

## **Game plan**

We will first create an <mark>ERC-20 token contract</mark> and then an <mark>ERC-721 NFT contract</mark> which will be used in our <mark>Rewarder contract.</mark>

<mark>If someone holds the NFT from our contract then the rewarder contract will give 100 ERC-20 tokens that we are creating.</mark>

**1\. ERC-20 Contract**

* Create a new file called `erc20.sol` under `contracts` folder in Remix IDE.
    
* Then copy-paste the code below, haha ik we all copy paste 😅
    
* Just press <mark>ctrl+s,</mark> Remix will compile the contract.
    
* Click the Ethereum-like icon and at the top, Click the dropdown that says <mark>REMIX VM (Shanghai), select Injected Provider to connect to our Metamask network.</mark>
    
* Then click **deploy** button.
    
    ```solidity
    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.9;
    
    import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
    import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
    import "@openzeppelin/contracts/access/Ownable.sol";
    
    contract MantleTutorialToken is ERC20, ERC20Burnable, Ownable {
        mapping(address => bool) private owners;
    
        constructor() ERC20("Mantle Tutorial", "MT") {
            _mint(msg.sender, 10 * 10 ** decimals());
            owners[msg.sender] = true; // Add the deployer as an owner
        }
    
        function mint(address to, uint256 amount) public ownerOnly {
            _mint(to, amount);
        }
    
        function addOwner(address newOwner) public ownerOnly {
            owners[newOwner] = true;
        }
    
        modifier ownerOnly() {
            require(owners[msg.sender], "Caller is not the owner");
            _;
        }
    }
    ```
    
    ### *<mark>Congrats we have deployed our first contract!</mark>*
    

1. **NFT Contract**
    

* Create a new file called `erc721.sol` under `contracts` folder in Remix IDE.
    
* Then copy-paste the code below again.
    
* Just like before press <mark>ctrl+s,</mark> Remix will compile the contract.
    
* Click the Ethereum-like icon, since we already selected injected provider, we can directly click **deploy** button
    

```solidity
pragma solidity ^0.8.9;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract MantleTutorialContract is ERC721, Ownable {
    using Counters for Counters.Counter;

    Counters.Counter private _tokenIdCounter;

    constructor() ERC721("Mantle Tutorial", "MT") {}
    // dummy metadata URI for placeholder, you can replace with your own IPFS hash
    function _baseURI() internal pure override returns (string memory) {
        return "https://bafyreihz6dpge5g7e6o7sjn6x7yyukbhygr5uttv5mnuppasqqhut222ny.ipfs.dweb.link/metadata.json";
    }

    function safeMint(address to) public onlyOwner {
        uint256 tokenId = _tokenIdCounter.current();
        _tokenIdCounter.increment();
        _safeMint(to, tokenId);
    }
}
```

*<mark>tada, we have deployed our NFT contract!</mark>*

**Main Rewarder Contract**

* Follow the steps you did previously to compile and deploy.
    

```solidity
pragma solidity ^0.8.0;


import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
interface ERC20 {
    function mint(address to, uint256 amount) external;
    function balanceOf(address account) external view returns (uint256);
}

contract MantleContract {
    ERC721 public nftContract;
    ERC20 public tokenContract;
    uint256 public tokenAmount = 100;

    constructor(address _nftContract, address _tokenContract) {
        nftContract = ERC721(_nftContract);
        tokenContract = ERC20(_tokenContract);
    }

    function claimTokens() external {
        require(nftContract.balanceOf(msg.sender) > 0, "Caller does not own the required NFT");
         tokenContract.mint(msg.sender, 100 *1e18);
    }
}
```

<mark>Now its time to get some rewardssss, Now lets first mint one NFT from our NFT contract by calling </mark> `safeMint` <mark> function within Remix IDE</mark>

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685805922663/783a3df6-6139-41e6-9f47-6282a38f13c0.png align="center")

After that tx is done, let's go to our <mark>tokenContract </mark> and call `addOwner` function with input address as the address of our rewarded contract to allow our Rewarded contract to mint erc-20 tokens that we created.

We are ready to claim our rewards, simply call `claimTokens` function in our rewarded contract to enjoy some free rewards!

Here is a tx that I did, [https://explorer.testnet.mantle.xyz/tx/0x96f45c58a17b60712d748f652c0db4aef51bd6d368f9273c283f0eac819f355f](https://explorer.testnet.mantle.xyz/tx/0x96f45c58a17b60712d748f652c0db4aef51bd6d368f9273c283f0eac819f355f)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1685806087180/23ec8b0e-af51-4418-94d4-ff2c1a2d00eb.png align="center")

*<mark>Congrats, you're now a smart contract developer!</mark>*

***Conclusion***  
Mantle network is an L2 chain with faster finalty and cheaper gas fees and is governed by $BIT DAO. To learn more about Mantle network, visit[https://www.mantle.xyz/](https://www.mantle.xyz/)
