Creating your own ERC20 token in more than 2 hours

Mariano Conti
2 min readMay 25, 2021

--

How it started:

Lolololol… 1 or 2 hours… couple more with tests. I should know better by now.

Anyway, how’s it going:

I’m now at over 3 hours and 5 videos and I still don’t have code that I would 100% vouch for on Mainnet, let alone have it handle millions or billions of dollars in value.

That’s the Playlist with the first five videos. More may be added soon.

This experiment started as an ERC20 coding speedrun, but ended up more as a showcase for the dapptools suite of CLI tools for Ethereum development. Tools I’ve been using for years and that have gotten a lot of dev love lately but that sadly have always lacked documentation (even though it’s much, much better now).

Kudos to folks like https://twitter.com/MartinLundfall, https://twitter.com/xwvvvvwx, https://twitter.com/leonardoalt and others who keep making dapptools great!

Back to my main point:

ERC20 describes an interface not an implementation

The ERC-20 Token Standard is very succinct, I suggest you read it if you haven’t. name, symbol, decimals, they’re OPTIONAL. mint and burn aren’t even there (there’s a SHOULD trigger a Transfer event on token creating though). It’s tiny, but it leaves a lot of room for interpretation, and of course, implementation.

But there’s so much more that makes a token, and I’ve seen way too many now, and can probably come up with a decent list of things to consider when creating your own, or using an existing one.

  • Do you allow sending to address(0) or to the token itself?
  • If not, how do you prevent this?
  • Do you allow approve to address(0) as well or not?
  • “Infinite allowance” where setting it to type(uint256).max never decreases it, thus saving an SSTORE?
  • Can you mint and burn? Who can? Only the token owner?
  • WHO is the token owner? The creator? Are there roles in your token? Or is that abstracted elsewhere?
  • Do you care about increaseAllowance and decreaseAllowance? Even though it’s in every single audit I’ve read, I have NEVER EVER seen the “allowance attack vector” abused.
  • Do you have permit or not? Is it resistant to hard forks?
  • Snapshotting a thing? Do you want real, on-chain delegation or are you ok with Snapshot plus lightweight off-chain delegation?
  • How much gas will it add to your transfers? Isn’t that the main point of a token?
  • Can you get away with packing some variables together like COMP/UNI did? Did you know their balances are uint96?
  • And more, and more, and more…

Thanks for reading. I overthink things, I know.

And follow me on Twitter https://twitter.com/nanexcool my ego needs feeding. ❤

--

--

No responses yet