0

So I have a working contract code on Remix, but it's written for ERC20 and I need to somehow change it so that it works on BEP20. I'm like really-really new to all of this and can't understand much of Solidity. Sorry if the question is stupid by itself, but I couldn't find any info by myself, so here I am.

I've tried to simply connect some BEP20 files from GitHub, which seem to be essential, and started compiling the code, but obviously it just flooded me with a bunch of different errors. I'd really love if someone could explain what are the main differences between writing code for ERC20 and for BEP20

run4w4y
  • 1
  • 1

1 Answers1

1

Here's few definitions just so you can better orient in the context:

  • ERC-20 is a token standard on Ethereum
    • It's also sometimes called EIP-20, simply because ERC (Ethereum Request for Comment) is a subcategory of EIP (Ethereum Improvement Proposal)
  • BEP-20 is a port of ERC-20 to Binance Smart Chain

From the perspective of Solidity code, there is no difference between ERC-20 and BEP-20 token. So when you deploy the code on Ethereum, it becomes an ERC-20 token - and when you deploy the same code on Binance Smart Chain, it becomes a BEP-20 token.

Here's a sample code for ERC-20/BEP-20 token extending the OpenZeppelin open source library, that already implements all features required by the standard.

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

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

contract GLDToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("Gold", "GLD") {
        _mint(msg.sender, initialSupply);
    }
}

The import statement above imports the ERC20.sol file from @openzeppelin/contracts NPM package. Make sure that you included this dependency in your package.json - or that you're using an environment that has this dependency already included (for example Remix IDE).

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
  • Thank you so much for detailed explanation. It got way more clear to me. I've previously discovered some signs that nothing is to be change, but for example your code has contract declaration with ERC20 value. Shouldn't it be changed for BEP20 or I can simply deploy it on Binance Smart Chain and everything will be fine? – run4w4y Dec 21 '22 at 16:21
  • @run4w4y `ERC20` in this case is "just" a name of the imported class (a class is called `contract` in Solidity lang), but the class name is not defined by the ERC-20 standard so it can be pretty much anything. If OpenZeppelin called the class `FungibleToken` instead, then this name would work as well... So to answer your question - you don't need to change the class name, and it will still work on both Ethereum and Binance Smart Chain. – Petr Hejda Dec 22 '22 at 13:31