Custom implementation of basic ERC20 token using OpenZeppelin library
-
Check if Node.js and truffle are installed by typing in your terminal:
node -v
and thentruffle version
-
Initialize truffle
truffle init
-
Create package.json file
npm init
-
Install OpenZeppelin library
npm install openzeppelin-solidity
-
Create
MerxToken.sol
file in the contracts folder. -
Import from OpenZeppelin libraries using
import
keyword. Please note the importing format is using forward slashes. Ifimport
is highligted red in your editor, add following to your user settings(e.g. in VSC):
"solidity.packageDefaultDependenciesContractsDirectory": "",
"solidity.packageDefaultDependenciesDirectory": "node_modules",
-
Create a constructor to pass in arguments into DetailedERC20.Update a
truffle-config.js
file withsolc....
-
Run
truffle compile
. Please check the required version of the Solidity compiler (for all .sol files including imported libraries) by runningtruffle version
. If needed, runnpm uninstall -g truffle
and thenpm install -g truffle
-
Create 2_deploy_token.js in migrations folder.
-
Run the blockchain emulator. Install
npm install ganache-cli
and run itganache-cli
. -
Modify truffle-config.js (truffle.js for Mac).
-
Run
truffle migrate --reset
to migrate the contract. -
Run
truffle console
. Test the blockchain by typing:truffle(development)>MerxNetToken.deployed().then((instance) =>{merx = instance})
and thenmerx
-
To test, type
merx.name()
,merx.decimals()
-
Write
Merx.test.js
in the test folder. See file for detailed steps. -
Double check the correctness of the await test, run
truffle test
(Expected result : 3 passing). -
Install chai
npm install chai
,npm i chai-as-promised
andnpm i chai-bignumber
-
Run
npm install
-
** 03/28/2019 There is a conflict I could not resolve between chai-bignumer and chai-as-promised libraries that results in failed test.**