The EOS ERC-20 contract explainedsteemCreated with Sketch.

in #eos7 years ago (edited)

This is a continuation of my previous post The EOS Crowdsale contract explained, please read that before reading here

What's an ERC-20?

ERC-20 is a standard which defines a custom token (like those sold in an ICO). At it's heart it is just a database which keeps a list of addresses and their balance.

In addition to just keeping the balances, to be ERC-20 compatible the contract must provide certain functions.

The main functions needed to be an ERC-20 contract are totalSupply, balanceOf and transfer. There are a few other functions but they are related to allowing another account to spend tokens on your behalf which most people do not use.

Because all ERC-20 functions have a standard format for functions we can write things like distributed exchanges which can exchange any contract token as long as it conforms to ERC-20.

The EOS ERC-20 token is just like any other ERC-20 token except that it has a few extra functions.

transfer

function transfer(address dst, uint wad) returns (bool) {
        assert(_balances[msg.sender] >= wad);
        
        _balances[msg.sender] = sub(_balances[msg.sender], wad);
        _balances[dst] = add(_balances[dst], wad);
}

After checking that the sender has enough balance, this function just adds the transferred amount to the destination address and removes it from your address. Any time you send tokens to another address or buy and sell them on an exchange this function is used.

stop

This is a function which will stop all transfers (it breaks the transfer functions). All it does is sets a variable called stopped, then adds a stoppable modifier which throws an error if the function is called when the contract is stopped.

Any request to any of the following functions will fail after the contract is stopped (please read my post about the crowdsale contract to see when this happens).

transfer, transferFrom, approve, mint, burn

This means that once the contract is stopped, no more transfers of ERC-20 EOS tokens will be possible. They will stay in your Ethereum account forever, after the token sale ends these will just be a momento of 2017/2018.

burn

function burn(uint128 wad) auth stoppable note {
    _balances[msg.sender] = sub(_balances[msg.sender], wad);
    _supply = sub(_supply, wad);
}

The auth modifier means you need to be the owner of the contract (or authorised by them) to call this function. It will burn the number of tokens that you supply as a parameter from your account. It will also remove them from the total supply.

Not sure what the purpose of this function is because it can only be used to burn the owner's tokens. I really doubt they would want to do that but queue the conspiracy theories!

totalSupply

function totalSupply() constant returns (uint256) {
    return _supply;
}

This function just returns the _supply variable. We saw that before in the burn function. It was set to 1 billion when the contract was created and initialised by the crowdsale contract. It could be changed by the burn function, but it is unlikely. Total supply is 1 billion tokens.

balanceOf

function balanceOf(address src) constant returns (uint256) {
    return _balances[src];
}

All ERC-20 tokens provide this function and it is used by apps like MEW to see what your balance is for a particular token. You can call this function with your address to verify that you actually own EOS tokens. The _balances variable contains all of the addresses and token balances.

Try it yourself

You can view the EOS ERC-20 token contract here.

EOS ERC-20 Contract

On the ERC-20 contract page you can click the "Read Smart Contract" tab and you will see the balanceOf function. Enter your address here and click query.

Also on this page are various other variables such as stopped (should say false), the owner account, total supply etc.

View more information about EOS ERC-20 token here

Screen Shot 2017-10-04 at 01.07.27.png

The ERC-20 contract is just a very basic database of addresses and total tokens each one owns, it allows standards-based transfer between accounts. It will be stopped after the token sale has ended so make sure you have done all your trades by then

Sort:  

The @OriginalWorks bot has determined this post by @m-i-k-e to be original material and upvoted it!

ezgif.com-resize.gif

To call @OriginalWorks, simply reply to any post with @originalworks or !originalworks in your message!

To enter this post into the daily RESTEEM contest, upvote this comment! The user with the most upvotes on their @OriginalWorks comment will win!

For more information, Click Here! || Click here to participate in the @OriginalWorks writing contest!
Special thanks to @reggaemuffin for being a supporter! Vote him as a witness to help make Steemit a better place!

Thanks for your work @m-i-k-e Followed...