Because BSC uses the EVM, the code for deploying an ERC-20 Token and the BEP20 token is the same. What that enables us to do, is grab the
ERC-20 specification from OpenZepplin and use it in our smart contract.
The next thing to do is open up a new browser tab and go to the
Remix IDE and start a new Workspace.
Under the contracts folder, we will create a file called BEP20.sol
In this new file you can write the following code:
// contracts/BEP20.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract BEP20 is ERC20 {
constructor(uint256 initialSupply) ERC20("BEP20Test", "BPT") {
_mint(msg.sender, initialSupply);
}
}
// contracts/BEP20.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract BEP20 is ERC20 {
constructor(uint256 initialSupply) ERC20("BEP20Test", "BPT") {
_mint(msg.sender, initialSupply);
}
}
// contracts/BEP20.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract BEP20 is ERC20 {
constructor(uint256 initialSupply) ERC20("BEP20Test", "BPT") {
_mint(msg.sender, initialSupply);
}
}
Line 1/2: The license and where this file should be located.
Line 3: We set the solidity complier to version 0.8.0.
Line 5: This imports the ERC20 package from OpenZepplin. We can use the specification to implement the new token. It is this standard that allows other wallets and programs to easily interface with the new token.
Line 7: This is specifying a new contract. You could rename BEP20 to something else arbitrary. However the ERC20 portion is the part that lets solidity know we want to use the ERC20 package that we are importing on line 5.
Line 8: The constructor portion of the contract is going to be called whenever we deploy our contract onto the BSC Testnet. We are giving it a single parameter initialSupply of type uint256. Then we call use the ERC20 functionality that we imported from OpenZepplin. This has two parameters: the first of which is the name of your token, and the second is what the token's ticker will be. In our case I called the token BEP20Test and it will show up with the BPT ticker.
Line 9: The _mint call that is implemented in the ERC20 contract. _mint will create the token, and send all of the newly minted tokens to msg.sender which will be whoever deploys the contract onto the testnet. In this case, you! It will create however many tokens we pass to the initialSupply parameter.
Note: It will create InitialSupply amount of tokens in the WEI format. which is 1e-18. So to create 100 tokens you need to pass the function 100000000000000000000