How to easily create your MEMCOIN for any EVM-based chain using Remix and Solidity? [Beginner]

By akohad Apr9,2024

[ad_1]

Hello! I’m glad to welcome you here. In this article, I will show you how to create a memcoin (or any other coin) without much difficulty and expense.

This is the first part of the article where we will create a basic ERC20 token using simple actions, allowing you to start your journey into the Solidity and EVM-based world.

Right away, I would like to say that here I will talk about the basic method, using RemixIDE and Solidity language. This will allow you to better understand how it works from the inside and not pay additional fees for commission on third-party “no code” platforms.

Let’s get acquainted, this is the Memcoin that we will make today:

So let’s get started! 🙂

Remix IDE is a powerful online integrated development environment (IDE) for Ethereum and other blockchain smart contracts. This tool allows developers to create, test, and deploy smart contracts directly in the browser.

After going to the Remix IDE website, you will see the main page and an already-created basic environment for work.

  1. Go to the contractsfolder (on the left side of the window) and click on create new file.

2. Name the file and add the extension .sol at the end (for example, SadHamster.sol).

3. In the newly opened file that you created, paste this code:

// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract SadHamster is ERC20Capped, Ownable {
constructor(uint256 cap) ERC20("SadHamster", "SAD") ERC20Capped(cap) Ownable(msg.sender) {
}

/**
* @dev Function to mint tokens by only owner.
* @param to The address that will receive the minted tokens
* @param value The amount of tokens to mint
*/
function mint(address to, uint256 value) public onlyOwner {
_mint(to, value);
}
}

Now let’s take a closer look at the code:

// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract SadHamster is ERC20Capped, Ownable {
constructor(uint256 cap) ERC20("SadHamster", "SAD") ERC20Capped(cap) Ownable(msg.sender) {
}

In this code snippet, we begin the definition of the SadHamster contract. The directive pragma solidity 0.8.25; specifies the version of Solidity that will be used to compile the contract.

Then we import the necessary libraries from OpenZeppelin, such as ERC20.sol, ERC20Capped.sol, and Ownable.sol, which provides standard implementations for ERC20 tokens, the ability to set a cap (maximum number of tokens to be issued), and control access rights to the contract.

The SadHamster (you can name it whatever you want) contract inherits functionality from the ERC20Capped and Ownable contracts. The constructor takes a parameter cap, which defines the maximum number of tokens that can be created, and initializes the ERC20 contract with the name SadHamster and the symbol SAD (here you should insert your name and symbol). Additionally, it makes the calling contract the owner of the contract using the Ownable function from OpenZeppelin.

/**
* @dev Function to mint tokens by only owner.
* @param to The address that will receive the minted tokens
* @param value The amount of tokens to mint
*/
function mint(address to, uint256 value) public onlyOwner {
_mint(to, value);
}
}

Here we define the mint function, which allows the contract owner to create new tokens and send them to the specified address. The onlyOwner modifier ensures that only the contract owner can call this function. The _mint function adds new tokens to circulation. Together, these lines of code provide a mechanism for issuing new tokens by the contract.

With this, we conclude Step 1 and move on to Step 2.

In this lesson, we will deploy the contract on Polygon. But in the future, you will be able to do this on any other network you need using the same logic.

  1. Go to the “Deploy & run transactions” tab.
  2. Choose the following parameters:
  • ENVIRONMENT — Injected Provider — MetaMask (the required network must be selected in MetaMask in advance, in our case Polygon).
  • ACCOUNT — your wallet for deployment.
  • GAS LIMIT — 3000000.
  • VALUE — 0.
  • CONTRACT — SadHumster.sol (or choose the name you gave it from the list).
  • Deploy: cap = 1000000000000000000000 (1000 * 10e18).

3. Click the Deploy button when all parameters are filled in.

4. Confirm the transaction in Metamask.

After that, below, you will see your deployed smart contract. You should save the address of its contract for the future. You can also start interacting with it right here by calling some methods (for example, mint).

Let’s now consider how we could interact with the deployed contract.

I will do this using the mint method as an example.

  1. Fill in the parameters for the method. In my case, these are 2 parameters: to and amount.
  2. Click the “transact” button.

3. Confirm the transaction in Metamask.

Great! 90% of the work is done!

Step 4: Etherscan (whateverscan)

I would also like to introduce you to Etherscan (or another scanner for a specific blockchain). In my example, I will use Polygonscan since I deployed my token on the Polygon network.

  1. Go to the website polygonscan.com.
  2. In the large search bar, enter the address of your contract.
  3. Then you will see all the transactions made on this contract.

You also have the opportunity to go through a Smart Contract Verify and Publish. This will help all users see the code of your smart contract and call its methods. I always advise you to Verify and Publish, as it makes your contract more transparent and understandable to users.

Well, let’s get started!

  1. Go back to Remix IDE.
  2. In the bottom right panel, select the Plugin Manager section.
  3. In the search bar, enter the word verification.
  4. After the search query returns a result, select CONTRACT VERIFICATION — ETHERSCAN.

We need an API KEY. You can get it after registering on Polygonscan (or any other scanner).

How to get an API KEY?

  1. Go to https://polygonscan.com/register.
  2. Fill in all the details.
  3. After successful registration, go to the API page.
  4. Create a new API KEY by clicking the +Add button.
  5. Save this key in Remix IDE.

Great! Now let’s Verify our contract:

In conclusion, by following the steps outlined in this article, you’ve embarked on a journey into the world of creating blockchain assets with ease and transparency. Building a basic ERC20 token using RemixIDE and Solidity not only provides you with a foundational understanding of smart contract development but also empowers you to customize and deploy your own tokens tailored to your specific needs.

Remember, this is just the beginning of your exploration into the vast possibilities of blockchain technology. Whether you’re delving into the realms of decentralized finance, creating digital collectibles, or revolutionizing supply chain management, the knowledge gained here serves as a solid foundation for your future endeavors in the blockchain space.

As you continue your journey, don’t hesitate to experiment, learn from mistakes, and collaborate with the vibrant community of blockchain enthusiasts. Together, we can unlock the full potential of this transformative technology and shape the future of decentralized innovation. Happy coding!

LinkedIn | X | BuyMeACoffe



[ad_2]

Source link

By akohad

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *