Transferring ERC20 contract to BEP20

509 Views Asked by At

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

1

There are 1 best solutions below

2
On

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).