Crypto of the Week — Ethereum!

Zach Lindsey
9 min readMay 17, 2021

This is a series of posts about cryptocurrencies. To get the most out of this post, you should know a little bit about how Bitcoin works, which was the topic of the last post.

Despite its importance, once major drawback of Bitcoin is that it’s fairly limited in what it can do. Essentially, the Bitcoin network is a global, distributed ledger for tracking account values of Bitcoin. However, can the trustless, open, decentralized technology on which the Bitcoin network rests be implemented for other things? For instance, you might imagine a system of voting in political elections using the technology to be more resistant to fraud, miscounting votes, and providing a way for everyone to ensure their vote was correctly counted. Or you could have financial assets like options automatically pay out the parties when the conditions in the asset are met. Ownership of real property could be tied into the blockchain. Totally digital organizations could have membership, voting, and governance proposals take place on a blockchain.

The obstacle to making all these possible is that each one would, if set up on its own, require a tremendous amount of work. A new system of transactions and rules governing valid transactions would have to be created. A totally new network of miners would have to be running to secure the transactions. Rather than setting up a separate network for each application, wouldn’t it be better if one very flexible network allowed all of these possibilities to exist within it? It would be! And that is the idea behind Ethereum. Instead of just a ledger that everyone agrees on, Ethereum runs a virtual computer whose contents everyone agrees on! This means that all the above applications, which can be implemented on a computer, can be implemented on the Ethereum blockchain!

Account Types

Ethereum is basically a collection of accounts. Each account has a balance of ether, and some have additional storage space. You might imagine each account has a wallet with some cash in it (the ether balance) and a possibly notebook to write things down in (the storage).

There are two kinds of accounts: externally owned accounts and contract accounts. Think of externally owned accounts as being controlled by actual people (you, your friend, a malicious stranger), and contract accounts are controlled by computer code (robots!). These accounts are allowed to communicate in two ways.

The first way is a transaction, which an externally owned account (that is, one controlled by a person) sends to some other account. The transaction contains the recipient of the message, a signature to prove who the sender is, and some ether to transfer. So far, this just seems like Bitcoin! But that’s not all a transaction can contain. In addition, transactions contain an optional data field, a STARTGAS value, and a GASPRICE value. We’ll get to these in a moment, but for now just know that these extra bits of info in a transaction are what let all the computer code run.

If a transaction goes to another externally owned account (a person’s account), all that happens is the ether specified in the transaction is moved from the sender to the receiver, with some extra amount sent to Ethereum’s miners. The amount sent to miners has to do with the GASPRICE value, which is explained in more detail below.

However, if a transaction goes to a contract account (a robot’s account), the money transfer happens, and then the fun starts: The robot account’s code begins executing! That is, every contract account comes set up with some code that runs when it receives a transaction. This code is designed to be Turing complete, which is a fancy way of saying that it can do basically anything a “normal computer” could. It could pay a prize to someone in a game. Or store information from the data field, making a distributed database. Or look up a stock price and perform some action depending on what it finds. Or record a vote in an electronic election. Or send a message to another contract account to fire off even more complicated stuff! There are a ton of exciting things a contract’s code could do in a secure, decentralized way.

Now, we must don our pessimist’s hat and ask ourselves, “This is all fine, but what do we do if someone just sends out a bunch of infinite loops that do nothing but waste time? Why would a miner or node waste time running this code?” The answer is that each step in a computation costs ether, and hence you have to pay for each step of the code you want to run. This brings us to those “GAS” entries in the transaction.

Gas

In order to prevent wasteful code from running and reward the computers securing the networking and processing transactions, each transaction requires a fee to be processed. The fee is determined by how complex the transaction is and a rate set by the transaction itself. To explain the idea, imagine you’d like to get an ride across town and you use the new (completely made up) ride-sharing app “CryptoRides”.

CryptoRides makes you select the maximum mileage for your ride and the rate per mile you’re willing to pay. You figure that your destination is about 10 miles away. To account for possible detours or errors in your estimation, you set the max miles at 15 miles. This is analogous to the STARTGAS value in the transaction. If you want to execute a long, complicated computer program on Ethereum (that is, travel a far distance), this value must be large. A simple transaction will only need a little bit of gas.

CyptoRides also makes you pick how much you’ll spend per mile travelled. It seems that the drivers can choose between different people based on how much they offer! The app suggests you pick $3 per mile, but also says offering $3.50 per mile will get a driver ASAP. Since you’re not in a rush, you just go with $3. This bid for mileage fee is analogous to the GASPRICE field in the transaction. Each transaction posted to the Ethereum network bids against other transactions to be included by the miners in the next batch. This lets you have some control over how fast your transaction is included. Paying a large amount will send it to the front of the line, while paying less works for transactions that aren’t time sensitive.

You can probably imagine two terrible outcomes if you mess up your CryptoRides settings. If you set your total miles too low, your CryptoRides driver will kick you out before you arrive! It’s even worse on the Ethereum network. A transaction without enough STARTGAS to run all code to completion will be completely reverted, but the money spent on the transaction is not reverted. CryptoRides offers no refunds! A second issue arises if you set your rate per mile too low: no drivers will pick you up!

EtherScan and Viewing Transactions

ow you know enough to make sense of some real transactions! Since the security of the network is obtained through openness and transparency, we can go look at all transactions ever run on the network. Various tools exist to display this data for you, one of which is etherscan.io. I’ve picked a random transaction to use as an example, and you can find it here. Click the link and follow along! (Note — I have no idea who owns these addresses! The double-edged sword of Ethereum is that your transactions are safe because they are public. Nobody knows who controls what address, but if you interact with enough apps with the same address, it’s entirely possible for someone to piece together which accounts you control. At that point, all assets tied to those accounts are known to the world!)

If you visit that page, you’ll be overwhelmed with numbers and stats, but we actually know what most of them are! Click “see more” at the bottom to view all the fields. Let’s go through them one by one, connecting them to some concepts discussed here and the last post.

  1. transaction hash — If you recall from the last post, to be included into the blockchain, we must compute the hash of the transaction. This hash is referenced by other transactions to be included, as well as future transactions.
  2. status — Since the transactions are running computer code and cost gas to run, various things can go wrong. You can run out of gas, hit a bug in the computer code, or other problems. Hence, it’s helpful to know the status of the transaction.
  3. block — Since solving the hash puzzle is so difficult, it would be very inefficient if only one transaction was added to the blockchain at a time. So transactions are actually added in batches called blocks, a point I swept under the run in the last post. This number just indicates which block the transaction belongs to.
  4. timestamp — This just indicates when the miner found the solution to the hash puzzle that lets the transaction’s block get added to the chain.
  5. from/to — Since this is a transfer of ether, these fields are self explanatory! They represent the Ethereum addresses of the accounts involved.
  6. value — The quantity of ether moved in the transaction.
  7. transaction fee — The amount paid to the miners to process the transaction.
  8. gas price — This is the amount that the transaction sender decided to reward the miners for each unit of computation in processing the transaction. That is, it’s the mileage fee you set in your CryptoRides app!
  9. gas limit — Recall that CryptoRides made you pick a price per mile as well as a maximum mileage. This is that number, representing the maximum amount of computation the miner is allowed to do before terminating.
  10. gas used by transaction — Since the number above is a maximum, it may well be that not all the gas is actually utilized. This number represents what’s actually used, and any leftovers are refunded to the sender.
  11. nonce — This is not the nonce used in the hash puzzle discussed in the last post. In this context, the nonce is just a transaction counter that helps prevent transactions from being run twice!
  12. input data — Since Ethereum transactions can run computer code, this is where you would place the inputs to the computer code you want to run! Since this transaction is just a simple currency transfer, no extra information is needed.

It might also be helpful to examine a transaction from a human-controlled account to a robot account! Here is the hash of such a transaction, and I’ll let you figure out how to use etherscan.io to find it!

0x7f6bd30f4c901379fcdd4d8a4026d5a9d5429fb800adbf61fad7ca37a933c523

In this example, we see that the “to” field is replaced with an “interacted with” field, since this transaction is actually a request to run some computer code! The robot account whose code this person wanted to run belongs to address

0x7a250d5630b4cf539739df2c5dacb4c659f2488d

which has the name “Uniswap V2: Router” to help us humans identify it. Notice that there is no “value”, because this “transaction” is not one that is sending money. Rather, scroll down to “input data”. Here, we see the computer code that the transaction sender wanted the Uniswap V2: Router to execute.

As one final step, let’s go look at what code the Uniswap V2: Router has. It’s all public! To do that, visit the address for the Uniswap V2: Router using etherscan with the account number

0x7a250d5630b4cf539739df2c5dacb4c659f2488d

Then, click the “Contract” button to view the information about this account’s contract code. From there, you will find a box called “Contract Source Code”. This is the code stored in this contract! You can look through the various things that the contract can do. If you send a correctly formatted message to this contract that explains which part of this code to run, it will do it for you! Provided you have enough gas, of course.

Conclusion

So we’ve seen how Ethereum builds on some concepts of Bitcoin to enable users to do much, much more than just send money. Using this globally shared computer system, we can run alternative financial systems, manage ownership of digital goods (NFTs!), set up digital organizations, and more! In the coming weeks, we will take a look at many examples of such applications of Ethereum, since many of the cryptocurrencies you might have heard of other than of Ethereum and Bitcoin are actually built using Ethereum’s blockchain.

Next week: NFTs

--

--