The uhhh…. PNS token [NSFW]

Welcome to the Solidity WTF blog. We figured we’d start with some of the classics in the wide world of Ethereum smart contracts. So here we go, the (in)famous PNS token: https://etherscan.io/address/0xce853db3359326db6d03981c9fb42983bbcdd007#code

And yes, the name is what you think it is.

The PNS token is a standard ERC20 token implementation with a twist.

Here’s how it’s initialized:

Did you catch the value of _airdropAmount? Yeah, takes me back to middle school, too.

The comments have most of the immature comedy gold, I highly recommend reading through all of them on Etherscan. Here’s an example:

Although this contract is absurd, it’s actually a great example of a basic ERC20 token implementation and it’s a reminder of a few important things about Solidity development:

Your comments can be seen by everyone

Assuming you’re adding your Solidity code to Etherscan — which in most cases should be done (that’s kind of the point of smart contracts) — it’s important to remember that even your comments can be seen. Anyone coming from a non-so-transparent coding environment has surely written things in their comments like “TODO: Jerry will finish up this section”, “not sure how this works, but it does”, or even worse in this situation “there’s a bug here where if the user calls the function too many times it crashes”.

Because of how visible smart contracts can be, it’s always important to keep in mind that your comments are visible, as well. For those short-sighted souls who already write few to no comments, it’s a good time to start now that you’re working with Solidity. One of the main values of smart contracts is for everyone to potentially understand the code behind the thing they’re interacting with. Comments can go a long way to helping others understand what your code is doing.

Naming sticks

As we all know but maybe don’t always have front-of-mind, once you deploy an Ethereum smart contract, it’s out there forever. Maybe it wouldn’t hurt to put a few more seconds of thought into your variable names. Maybe you should think through the strings and abbreviations you’re typing into your contract to see if they perhaps have a second meaning you didn’t think about at first.

Obviously, in the case of PNS all these references are made to be funny, but in real situations doing things like naming a variable “theVariable” or using “i” as a counter instead of “variableNameCounter” could make your contract that much more difficult for others to understand.

Anyway, this is a funny one. Be sure to send it to any teenage coding nerds you know, they’ll be the funniest guy in high school by passing around the link.

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright Solidity WTF 2019
Tech Nerd theme designed by Siteturner