Create Basic ERC20 token with Solidity, Brownie and Python
Demo
Check out Cornell Token on Rinnkeby network with Etherscan.
Installation
-
Install brownie with pipx
$ python3 -m pip install --user pipx $ python3 -m pipx ensurepath $ pipx install eth-brownie # test installation $ brownie
-
Install ganache-cli with npm
npm install -g ganache-cli
Create the Project
-
Initialize the project
$ mkdir cornell_token ; cd cornell_token $ brownie init
-
Create token contract in
./contracts/CornellToken.sol
- inherit ERC20 implementation from OpenZeppelin to avoid re-inventing the wheel.
-
Add
./brownie-config.yaml
- create mapping
@openzeppelin
to the github repo - add other config:
- dotenv
- private key of local dev
- create mapping
-
Add
.env
for the environment variables- dotenv -> for private key stuff, as a safer way
-
Change the name of the Token (e.g.
CornellToken
) -
Creat deploy script
deploy_cornell_token.py
- define initial supply, token name, token sybol
-
Creat deploy script
helper.py
- get account function
Deploy to local blockchain development environment
$ brownie run scripts/deploy_cornell_token.sol
Deploy to live network
-
in
brownie-config.yaml
, add:networks: rinkeby: active
-
in
.env
, add:export WEB3_INFURA_PROJECT_ID=<YOUR INFURA PROJECT ID> export PRIVATE_KEY=<YOUR PRIVATE KEY>
To have infura project id, you need to create an infura account and a new project. The id is the endpoint to the live network.
To access your private key, you can check out the metamask -> account details
-
run the same script with an extra
--network
option$ brownie run scripts/deploy_cornell_token.sol --network rinkeby
then wait for a moment to see the address being active on the live network.
-
add this token to metamask
- Metamask -> assets -> import tokens
- grab the token contract address and add it into metamask.