# Smart Contracts

## **Introduction**

ERC-20 tokens are fungible tokens commonly used for creating cryptocurrencies, governance tokens, and staking mechanisms. Taker Chain enables easy token deployment with Ethereum-compatible smart contracts via its EVM environment.

This tutorial covers deploying an ERC-20 contract on the Taker Chain TestNet using Remix IDE, a web-based development tool. OpenZeppelin's ERC-20 contracts are utilized for security and compliance.

***

#### **Prerequisites**

Before starting, ensure you have the following:

* **MetaMask installed** and connected to the Taker Chain TestNet. For detailed instructions, see the **Connect Your Wallet** section.
* **A funded account** with some test tokens (you can get them from the Taker Faucet). To learn how to get test tokens, check out the **Test Tokens** section.
* **Basic understanding of Solidity** and fungible token concepts.

***

#### **Create the ERC-20 Contract**

To create the ERC-20 contract, follow the steps below:

**1. Navigate to Remix IDE**

Visit the [Remix IDE](https://remix.ethereum.org) to start developing your smart contract.

**2. Create a New File**

Click the **Create new file** button under the `contracts` folder and name your contract `MyToken.sol`.

**3. Paste the ERC-20 Contract Code**

Copy and paste the following code into the editor:

```solidity
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.22;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

contract MyToken is ERC20, Ownable {
    constructor(address initialOwner)
        ERC20("MyToken", "MTK")
        Ownable(initialOwner)
    {}

    function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }
}
```

***

#### **Key Components of the Contract**

**Contract Imports**

* **ERC20.sol**: Implements core functionality for fungible tokens, including transfers, approvals, and balance tracking.
* **Ownable.sol**: Provides basic authorization control, ensuring only the contract owner can mint new tokens.

**Constructor Parameters**

* **initialOwner**: Sets the address that has administrative rights over the contract.
* **"MyToken"**: The full name of your token.
* **"MTK"**: The symbol representing your token in wallets and exchanges.

**Key Functions**

* **mint(address to, uint256 amount)**: Allows the contract owner to create new tokens for any address. The `amount` should include 18 decimals (e.g., 1 token = `1000000000000000000`).
* **Inherited Standard ERC-20 Functions**:
  * **transfer(address recipient, uint256 amount)**: Sends a specified amount of tokens to another address.
  * **approve(address spender, uint256 amount)**: Grants permission for another address to spend tokens on behalf of the token owner.
  * **transferFrom(address sender, address recipient, uint256 amount)**: Transfers tokens from one address to another, if previously approved.
  * **balanceOf(address account)**: Returns the token balance of a specific address.
  * **allowance(address owner, address spender)**: Checks how many tokens an address is allowed to spend on behalf of another address.

***

#### **Tip**

Use the **OpenZeppelin Contracts Wizard** to quickly generate customized smart contracts. Simply configure your contract, copy the generated code, and paste it into Remix IDE for deployment. Below is an example of an ERC-20 token contract created with it:

*(Insert screenshot of OpenZeppelin Contracts Wizard showing ERC-20 contract configuration.)*

***

#### **Compile the Contract**

Compiling transforms your Solidity source code into bytecode that can be deployed on the blockchain. Follow the instructions below:

**1. Select the Solidity Compiler Plugin**

From the left panel in Remix IDE, select the **Solidity Compiler** plugin.

**2. Click the Compile Button**

Click the **Compile MyToken.sol** button.

**3. Verify Compilation Success**

If the compilation succeeds, you’ll see a green checkmark in the Solidity Compiler icon.

***

#### **Deploy the Contract**

Deployment publishes your compiled smart contract to the blockchain, making it permanently available for interaction.

**1. Select the Deploy & Run Transactions Plugin**

From the left panel in Remix IDE, select the **Deploy & Run Transactions** plugin.

**2. Configure Deployment Settings**

* From the **ENVIRONMENT** dropdown, select **Injected Provider - MetaMask** (or your wallet provider).
* From the **ACCOUNT** dropdown, select the account you want to use for deployment.

**3. Set Contract Parameters**

Enter the address that will own the deployed token contract.

**4. Deploy the Contract**

Click the **Deploy** button to initiate the deployment. MetaMask will pop up—review the transaction details and click **Approve** to deploy your contract.

**5. Verify Deployment Success**

If the deployment succeeds, you’ll see the transaction details in the terminal, including the contract address and deployment transaction hash.

***

#### **Interact with Your ERC-20 Contract**

Once deployed, you can interact with your contract through Remix IDE:

**1. Locate Your Contract**

Find your contract under **Deployed/Unpinned Contracts**, and click it to expand the available methods.

**2. Mint New Tokens**

To mint tokens:

* Expand the **mint** function.
* Enter:
  * **Recipient address**: The address to which tokens will be sent.
  * **Amount**: Remember to add 18 zeros for 1 whole token (e.g., `1000000000000000000` for 1 token).
* Click **Transact**.
* Approve the transaction in MetaMask.

**3. Verify Minting Success**

If the transaction succeeds, you’ll see the output in the terminal.

***

#### **Other Common Functions**

* **balanceOf(address)**: Check the token balance of any address.
* **transfer(address to, uint256 amount)**: Send tokens to another address.
* **approve(address spender, uint256 amount)**: Allow another address to spend your tokens.

Feel free to explore and interact with other contract functions using the same process: select the method, provide the required parameters, and confirm transactions through MetaMask when prompted.

***

Start building and deploying ERC-20 tokens on Taker Chain today!&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.taker.xyz/taker/developers/evm-developers/smart-contracts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
