Within the Ethereum blockchain we can record transactions and run smart contracts. These things allow us to run DApps (decentralized applications) and which can support the running of the infrastructure in return for some payment (Ether). A DApp can also create tokens for new currencies, shares in a company or to prove the ownership of an asset. ERC-20 allow for the sharing, transfer and storage of tokens.
ERC20 Token
ERC-20 tokens are supported by the whole of the Ethereum infrastructure and can be easily traded. They support a number of mandatory functions:
- totalSupply. This function is the total number of ERC-20 tokens that have been created.
- balanceOf. This function identifies the number of tokens that a given address has in its account.
- transfer. This function supports the transfer of tokens to a defined user address.
- transferFrom. This function supports a user to transfer tokens to another user.
- approve. This function checks that a transaction is valid, based on the supply of token.
- allowance. This function checks if a user has enough funds in their account for a transaction.
Optional parameters are:
- Token Name. This is the name that the token will be defined as.
- Symbol. This is the symbol that the token will use.
- Decimal. This is the number of decimal places to be used for any transactions.
Coding
const Web3 = require('web3'); const ERC20Contract = require('erc20-contract-js'); var args = process.argv; // Web3 instance const web3 = new Web3( new Web3.providers.HttpProvider('https://mainnet.infura.io/v3/XXXXXXXXXXXXXXXXX') ); var contractAddr = '0x86fa049857e0209aa7d9e616f7eb3b3b78ecfdb0'; // EOS contract address contractAddr = '0xde2f7766c8bf14ca67193128535e5c7454f8387c'; //Metadium META https://www.metadium.com/ contractAddr = '0xb5a5f22694352c15b00323844ad545abb2b11028'; //ICON ICX https://icon.foundation/ contractAddr = '0x5ca9a71b1d01849c0a95490cc00559717fcf0d1d'; //Aeternity AE https://www.aeternity.com/ contractAddr = '0x4CEdA7906a5Ed2179785Cd3A40A69ee8bc99C466'; //AION AION https://aion.network/ contractAddr = '0x3883f5e181fccaf8410fa61e12b59bad963fb645'; //Theta Token THETA https://www.thetatoken.org/ contractAddr = '0xcb97e65f07da24d46bcdd078ebebd7c6e6e3d750'; //Bytom BTM https://bytom.io/ contractAddr = '0x86fa049857e0209aa7d9e616f7eb3b3b78ecfdb0'; //EOS EOS https://eos.io/ contractAddr = '0xfa1a856cfa3409cfa145fa4e20eb270df3eb21ab'; //IOSToken IOST https://iost.io/ contractAddr = '0xd850942ef8811f2a866692a623011bde52a462c1'; //VeChain VEN https://www.vechain.org/ contractAddr = '0xf230b790e05390fc8295f4d3f60332c93bed42e2'; //Tronix TRX https://tron.network/ contractAddr = '0xf85feea2fdd81d51177f6b8f35f0e6734ce45f5f'; //CyberMiles CMT https://www.cybermiles.io/ contractAddr = '0x1cb3209d45b2a60b7fbca1ccdbf87f674237a4aa'; //ThoreCoin THR http://www.thorecoin.com/ contractAddr = '0xe25bcec5d3801ce3a794079bf94adf1b8ccd802d'; //MATRIX AI Network MAN https://www.matrix.io/ //contractAddr = '0xB8c77482e45F1F44dE1745F52C74426C631bDD52'; if (args.length>2) { contractAddr=args[2]; } console.log("Address:\t",contractAddr); // Create new instance of ERC20Contract const erc20Contract = new ERC20Contract(web3, contractAddr); // Get allowance erc20Contract.name().call() .then(name => console.log(`Name: ${name}`)); erc20Contract.symbol().call() .then(sy => console.log(`Symbol: ${sy}`)); erc20Contract.totalSupply().call() .then(su => console.log(`Total supply: ${su}`));