This Repo contains TestToken token smart contract based on ERC20.
ERC-20 is a standard interface for tokens.
The following standard allows for the implementation of a standard API for tokens within smart contracts.
More Information about Solidity Language and ERC-20 Standard:
The constructor
function set the name
, symbol
, decimals
and totalSupply
of the token.
The view function balanceOf
returns the account balance of account with address _owner
.
The method transfer
is called by an account and transfers _value
amount of tokens to other address _to
.
The method transferFrom
allow one third account transfers _value
amount of tokens from other address _from
to other address _to
.
Both methods fire the Transfer
event.
The method increaseApproval
allows other account _spender
to withdraw from one account multiple times, up to the _addedValue
amount.
The method decreaseApproval
reduces the value aprroveed to _spender
to withdraw from one account multiple times, substracting the _subtractedValue
to the approval amount.
If the _subtractedValue
is bigger than previously approved the value will reduce to 0.
The view function allowance
returns the amount which address _spender
is still allowed to withdraw from _owner
.
Those methods are not a ERC-20 standard but are commonly used to create and destroy tokens.
The mintTo
function creates _amount
tokens and assigns them to account _to
, increasing the total supply.
The burnFrom
function destroys _amount
tokens from account _from
, reducing the total supply.
Only owner can mint or burn tokens in this case.
The Ownable module provides a basic access control mechanism, where there is an account (an owner) that can be granted exclusive access to specific functions.
This module is used through inheritance.
It will make available the modifier onlyOwner
, which can be applied to your functions to restrict their use to the owner.
By default, the owner account will be the one that deploys the contract.
The owner address can be changed with method transferOwnership
.
Contract module which allows children to implement an emergency stop mechanism that can be triggered by an authorized account.
This module is used through inheritance.
It will make available the modifiers whenNotPaused
and whenPaused
, which can be applied to the functions of your contract.
In this example, only owner account can trigger call pause
and unpause
methods.
You can compile, run tests and deploy this smart contract with Truffe.
Clone or donwload this repositorie.
Go to path and run on terminal:
npm install
After running, all dependecies will be downloaded.
Maybe you need install truffle as global dependency to run next steps.
truffle compile
After running, contract information — including ABI — will be available at the build/contracts/
directory.
truffle develop
test
Or, You can run tests which can be found in the test directory /test
runing on terminal:
truffle test
Or run tests within a specific file:
truffle test <file_path>
Create .env file on root with:
PRIVATE_KEY = // Wallet private key
INFURA_PROJECT_ID = // Your Infura Project Id
TOKEN_NAME = "Token Name"
TOKEN_SYMBOL = "ERC"
TOKEN_DECIMALS = 18
TOKEN_TOTALSUPLY = 0
It is important that the chosen wallet has native tokens for the payment of gas.
Run migrate command:
truffle migrate --network <network_name> // mainnet, rinkeby, polygon, mumbai...
After migration, contract address and transaction ID will be shown on screen.