Closed medied closed 6 years ago
This is the Truffle-OpenZepplin tutorial, initial implementation is in the erc20-proof-of-concept
branch
ERC-20 defines six different functions for the benefit of other tokens within the Ethereum system. These are generally basic functionality issues, including how tokens are transferred and how users can access data about a token. ERC-20 also prescribes two different signals that each token takes on and which other tokens are attuned to.
Put together, this set of functions and signals ensures that Ethereum tokens of different types will typically work the same in any place within the Ethereum system.
It's hard to overstate how important that interface has been. By defining a common set of rules for ethereum-based tokens to adhere to, ERC-20 allows developers of wallets, exchanges and other smart contracts, to know in advance how any new token based on the standard will behave.
(...)
Before delving deeper, it's important to spell out what a token actually is and how it differs from ether, the native currency driving the ethereum blockchain.
As they relate to the ethereum network, tokens are digital assets that can represent anything from loyalty points to vouchers and IOUs to actual objects in the physical world. Tokens can also be tools, such as in-game items, for interacting with other smart contracts.
But put simply, a token is nothing more than a smart contract running on top of the ethereum blockchain. As such, it is a set of code (functions) with an associated database. The code describes the behavior of the token, and the database is basically a table with rows and columns tracking who owns how many tokens.
If a user or another smart contract within ethereum sends a message to that token's contract in the form of a 'transaction,' the code updates its database.
(...)
In contrast to tokens, ether is hard coded into the ethereum blockchain. It is sold and traded as a cryptocurrency, and it also powers the ethereum network by allowing users to pay for smart contract transaction fees. (All computations on the ethereum network have a 'gas' cost.)
(...)
Early on in ethereum's history, standards were part of the overall plan to create a user friendly and broadly accessible system. But like all standards, ERC-20 took time to evolve over a series of long discussions and careful considerations.
So, sometime before DevCon1, the first big ethereum conference in 2015, Vitalik Buterin, the founder of ethereum, introduced the initial standards token.
Later that year, Fabian Vogelsteller, one of the developers working on ethereum's Mist wallet, took that standard, changed a few things, and proposed it to the community as ERC-20 to initiate a formal conversation around how the standard should be implemented.
(...)
ERC-20 defines a set of six functions that other smart contracts within the ethereum ecosystem will understand and recognize.
These include, for instance, how to transfer a token (by the owner or on behalf of the owner) and how to access data (name, symbol, supply, balance) about the token. The standard also describes two events – signals that a smart contract can fire – that other smart contracts 'listen' for.
ERC stands for Ethereum Request for Comments, different than EIP (Improvement proposals), EIP changes actual Ethereum code and ERC are more for guidelines. It's still all new though.
Following is an interface contract declaring the required functions and events to meet the ERC20 standard:
1 // https://github.com/ethereum/EIPs/issues/20
2 contract ERC20 {
3 function totalSupply() constant returns (uint totalSupply);
4 function balanceOf(address _owner) constant returns (uint balance);
5 function transfer(address _to, uint _value) returns (bool success);
6 function transferFrom(address _from, address _to, uint _value) returns (bool success);
7 function approve(address _spender, uint _value) returns (bool success);
8 function allowance(address _owner, address _spender) constant returns (uint remaining);
9 event Transfer(address indexed _from, address indexed _to, uint _value);
10 event Approval(address indexed _owner, address indexed _spender, uint _value);
11 }
Debugging tutorial token 👇🏽
https://github.com/trufflesuite/trufflesuite.github.io/issues/190
A mapping means an associative array, where you associate addresses with balances.
(...)
To stop a contract execution mid execution you can either return or throw The former will cost less gas but it can be more headache as any changes you did to the contract so far will be kept. In the other hand, 'throw' will cancel all contract execution, revert any changes that transaction could have made and the sender will lose all ether he sent for gas.
(...)
...something called Events. These are special, empty functions that you call to help clients like the Ethereum Wallet keep track of activities happening in the contract. Events should start with a capital letter.
(source)
‘ERC20’ is actually a standard that tokens on the Ethereum network can meet, and tokens that check all the necessary boxes are deemed ‘ERC20 Tokens’. These tokens are blockchain assets that have value, and can be sent and received, like Bitcoin, Litecoin, Ethereum, or any other cryptocurrency.
The difference between these tokens and a standalone currency like Litecoin is that ERC20 tokens piggyback on the Ethereum network, hosted by Ethereum addresses and sent by Ethereum transactions.
(source)
Fees for sending Ethereum or ERC20 assets increase if you send them to a 'smart contract' address. Smart contracts are programs that automatically perform tasks, usually involving ERC20 assets or managing/moving Ethereum funds (some exchanges use smart contracts on their deposit addresses).
The fees are higher to give the smart contract enough 'gas' to process the transaction and execute the 'contract' program correctly. Sending a transaction with sub-optimal fees to a smart contract could cause a failed transaction, so Exodus automatically adjusts the fee to compensate when sending assets to a smart contract.
(source)
What are the main issues with the current ERC20? Many. The first glaring one is how to transfer tokens to contracts. Because you can send tokens to any ethereum address, you can easily also send them to contracts which do not support them, locking them forever. Worse than that: even if the tokens can be manually moved, it's very hard to tell which tokens came from who, and try sending them back.
To solve that, the ERC20 used to have a approve function that would allow you to approve the transfer to a contract and then you needed to create a second transaction, letting the contract know you had approved it. This required two transactions, had multiple security issues and was not widely implemented.
(source)
Read up on ERC20 dynamics, implement Truffle/Zeppelin tutorial, debug and learn