BEP-20 Token Creation

HOW TO CREATE BEP20 TOKEN ON BINANCE BLOCKCHAIN (BSC)

Learn more about the binance smart chain

https://www.binance.com/en/blog/421499824684900933/Binance-Smart-Chain-Launches-Today
https://academy.binance.com/en/articles/connecting-metamask-to-binance-smart-chain
https://accounts.binance.com/en/register?ref=22521757
https://bscscan.com/

Get MetaMask Wallet

  • Install MetaMask extension
  • Setup MetaMask account
  • Follow instructions given to you

    Make sure to keep Private Keys and Passphrase safe!

Create new network in Metamask

Code ERC20 Token

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
pragma solidity ^0.5.0;

// ----------------------------------------------------------------------------
// ERC Token Standard #20 Interface
//
// ----------------------------------------------------------------------------
contract ERC20Interface {
function totalSupply() public view returns (uint);
function balanceOf(address tokenOwner) public view returns (uint balance);
function allowance(address tokenOwner, address spender) public view returns (uint remaining);
function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns (bool success);
function transferFrom(address from, address to, uint tokens) public returns (bool success);

event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}

// ----------------------------------------------------------------------------
// Safe Math Library
// ----------------------------------------------------------------------------
contract SafeMath {
function safeAdd(uint a, uint b) public pure returns (uint c) {
c = a + b;
require(c >= a);
}
function safeSub(uint a, uint b) public pure returns (uint c) {
require(b <= a); c = a - b; } function safeMul(uint a, uint b) public pure returns (uint c) { c = a * b; require(a == 0 || c / a == b); } function safeDiv(uint a, uint b) public pure returns (uint c) { require(b > 0);
c = a / b;
}
}


contract CodeWithJoe is ERC20Interface, SafeMath {
string public name;
string public symbol;
uint8 public decimals; // 18 decimals is the strongly suggested default, avoid changing it

uint256 public _totalSupply;

mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;

/**
* Constrctor function
*
* Initializes contract with initial supply tokens to the creator of the contract
*/
constructor() public {
name = "CodeWithJoe";
symbol = "CWJ";
decimals = 18;
_totalSupply = 100000000000000000000000000;

balances[msg.sender] = _totalSupply;
emit Transfer(address(0), msg.sender, _totalSupply);
}

function totalSupply() public view returns (uint) {
return _totalSupply - balances[address(0)];
}

function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}

function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}

function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}

function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}

function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = safeSub(balances[from], tokens);
allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
balances[to] = safeAdd(balances[to], tokens);
emit Transfer(from, to, tokens);
return true;
}
}

  • Make code adjustments

    • Change contract name ‘CodeWithJoe’
    • Set name of token ‘CodeWithJoe’
    • Set symbol of token ‘CWJ’
    • Set decimals of token ‘18’
    • Set _totalSupply of token ‘100000000000000000000000000’
  • Compile the file name

    • Make sure the compiler version matches
    • Make sure MetaMask account is connected to remix

Deploy Token

Confirm Transaction in MetaMask

Verify the smart contract

  • Verify the Smart Contract
    • Enter the contract address you would like to verify
    • Select the Compiler Type ‘Solidity (Single file)’
    • Select the Compiler Version
    • Select the Open Source License Type
    • Click ‘Continue’
  • Paste Solidity Contract Code below
    • Click ‘Verify and Publish’
  • Contract should now be verified on the Ethereum Blockchain

Check if Smart Contract was deployed to the Binance Smart Chain

  • Search for Smart Contract on Binance Smart Chain
  • Instead of interacting with the smart contract with Ethereum, we need to interact with it with the Binance Token

Reference: https://www.youtube.com/watch?v=BOTXBO6UOY0