Jul 17, 2018

4 min read

How does ERC20 Token Mining Work?

We are all familar with Bitcoin and most of us are even familiar with how it is mined: using Proof of Work mining. That means that the currency is created and controlled using Mathematics only, there is no central mint at all.

Without a central mint and without any human intervention, that removes the potential for human corruption. Even the inflation rate is controlled using code. Unfortunately, almost all ERC20 tokens on Ethereum do have a centralized owner and are not mined. They are dependant on humans who can cheat, lie, or disappear. Many people proposed ideas for allowing ERC20 tokens to be mined and ownerless in order to make them timeless, invulnerable, and incorruptable. Here is one example of a mined token:

Interestingly, a few projects tried this but every single one failed to succeed. Mostly because they forgot one key element: the difficulty target has to be able to adjust. Exhibit A: Bitcoinereum was a mineable token, but the Proof of Work never adjusts. Accounts are limited to X calls per unit of time, but this is easily cheated since anyone can make thousands of Ethereum accounts. Therefore, it is not a Pure Proof of Work mined token, it has a weird time and accounts component.

Every good technology evolves in small steps. In February of 2018, the 0xBitcoin contract was deployed which has an automatic difficulty adjustment mechanism built into the solidity code of the contract. That way, as the mining hashrate increases, the tokens become harder and harder to mint. Just like Bitcoin. So far this project has been a resounding success and over 1 TH of hashpower is trying to mine these tokens to use them as trustless currency on the Ethereum network. How does it work? Lets pull it apart.

The contract is here:

Inside, the first thing we notice is that no tokens are given to the deployer upon deployment. There is no initial reward or bonus to anyone. All tokens must be mined with this method:

Interesting !! The mint() method will only pay out tokens if a rare nonce is found, one which has a sha hash that starts with many zeroes, because it is smaller than the difficulty target. So what the heck does _startNewMiningEpoch() do ? It initializes the next block to be mined.

The reward era will increase if there are enough tokens minted. The max supply changes as well. The difficulty readjustment method is called every 1024 method calls, or every 1024 mints.

Okay, so how does the difficulty readjust?

Every 1024 mints, this method examines the number of Eth blocks that occured since the last time this method was called. If too few Eth blocks passed (less than 1024 * 60) then the difficulty will increase up to 150% of current. If too many Eth blocks passed, the difficulty will decrease down to 50% of current.

And that is about it! The rest of the contract is just a standard ERC20 token contract.

Now, a currency which is analogous to BTC operates -within- the Ethereum network. It is pure PoW mined, it is not managed by any human, it cannot be upgraded or deleted by anyone. The contract is locked. The 0xBTC tokens are compatible with all ERC20 services and Ethereum accounts and contracts. What can we do with this ?