Howdy, readers! After yet another crazy week of news in the crypto space, I’m back in your inboxes yet again preaching the gospel of decentralization! I’m kidding, of course. Partially.
A little recap of the week if you’ve missed it:
Discord alluded to developing a feature to allow users to connect their Ethereum wallets to their accounts but rolled it back after widespread blowback from non-crypto users. The CEO said “We have no current plans to ship this internal concept.” after tweeting this photo of the feature.
Follow up to that: there are lots of hate comments on those two tweets. Tread carefully.
Bitcoin, Ether, and Solana all passed their all-time highs again recently at $69,000, $4,867.81, and $260.06 respectively (via Coinbase).
And, of course, AMC Entertainment has started accepting cryptocurrency payments. The currencies accepted at the moment are Bitcoin, Ether, Litecoin, and Bitcoin Cash. Dogecoin will be added to the list soon as well. Obviously.
Oh, and we have a Discord server! Come join us over at discord.gg/Xs293sZAkW!
Now on to the newsletter.
Smarty-Pants Devs
Our society would probably crumble if it weren’t for legal contracts. Though they’re incredibly lengthy and kind of annoying to read, the function they serve is absolutely vital. They allow us to agree to deals in ways that are very hard to backtrack on.
But…they aren’t flawless. Skilled and well-paid lawyers can pick apart the wording of contracts to find loopholes that they or their clients can exploit to do as they please. That’s actually the main reason contracts are so wordy and written in an esoteric language known as legalese.
But what if a contract could be executed by software? What if there was no need for an expensive lawyer to write, read, or interpret a complex contract for something as simple as internet payments?
In 1996, a computer scientist named Nick Szabo had the same idea and wrote an academic paper on a concept he deemed “smart contracts”. If you want to read the original paper, you can find it here.
In essence, a smart contract is a contract written in code, not words. It’s similar to a paper contract in that it’s agreed upon by multiple parties and governs how certain transactions are made. How it differs is that instead of lengthy paragraphs and subsections, it’s all functions and algorithms. Not to mention it can’t be changed.
Smart Contracts on the Blockchain
In the past, we’ve talked about how blockchains are immutable. The only way to change them is by rolling back and getting the consensus of the network. Which is not easy to do. Otherwise, it won’t happen unless you branch off and create your own chain.
This fact lends itself very easily to legal matters. When you put up information on a blockchain, you literally can’t take it down. That was already kind of a thing on the regular internet, but it’s still possible to hide things from the majority of the world if you’re very dedicated. Blockchains don’t work like that. You can add and update data, but never remove it. They’re the best databases in the world.
In a pre-blockchain world, if you signed a contract with another person, you could both lose your respective copies in a disaster. Even if stored digitally, the only way to effectively protect something is to store it on a cloud server like Dropbox or Google Drive.
But in a world with blockchains, you can hire a programmer to write up a smart contract, deploy on-chain, connect your wallets, and you have a deal.
…in theory. Let’s take a look at some real-world examples of smart contracts to see how they can behave in the wild.
dApp Smart Contracts
First, ‘dApp’ is short for ‘decentralized application’ and generally refers to web apps stored and run on a blockchain. You can think of these as similar to Axie Infinity and CryptoKitties, both being Ethereum dApps.
dApp backend code is usually written with smart contracts. They govern the mechanisms of minting tokens, transferring to other users, battle mechanics if it’s a game, generative qualities of NFTs, and all the other necessary functions of a Web3 app.
For a real-world example, you can look at the actual source code for the CryptoKitties contract here on Etherscan. It’s pretty long and convoluted, but reading the comments is incredibly useful to know how it works if you’re not a Solidity developer.
Comments are marked by lines starting with two forward slashes (
//
) or forward slashes and asterisks (/*
stuff
*/
)
There are so many fantastic examples of things that are typically governed by paper contracts in the code. For example, the modifier onlyCEO()
on line 137 creates a modifier to be used in later functions that requires the person calling the function to be the “CEO” of CryptoKitties. If someone who isn’t the CEO tries to call a function with that modifier, they won’t have the ability to call that function ever unless they gained access to the CEO’s wallet.
There are other examples of functions that can be done on paper but are done far better by code. Scrolling very far down to line 1711 and looking at the function createSaleAuction()
, let’s look at some very important parts of the code that can only be enforced using a program.
A defining feature of CryptoKitties is that two kitties can breed and make kittens. Not only is it adorable, but can be dangerous if a kitty is being sold at auction. When a kitty gives birth, the new kitten is assigned to whatever address owns the mother.
When a kitty is put up for auction, the auction’s contract address owns the kitty until it’s sold. If the kitty being sold is pregnant, there’s a big risk that it can give birth before being sold and the kitten will be assigned to the auction contract. To prevent this, there needs to be a clause that prevents the kitty from being pregnant. That does exist in this contract! On line 1727:
require(!isPregnant(_kittyId));
All this says is that the kitty being put up for auction cannot be pregnant. If it is, it will fail and the transaction will be forced to stop.
Let’s pretend we live in a world where people sell real cats at auction and kittens are legally owned by whoever owns the mother at the time of birth. The same problems would be presented and contracts would be used to prevent pregnant cats from being sold. But if someone really wanted to, they could find a way to sell a pregnant cat without the auction house knowing, despite having signed a contract.
With a smart contract, the state of the kitty is always accessible by the code. It doesn’t matter if the cat became pregnant 5 minutes ago or 5 hours ago, it would be impossible to sell until it gives birth.
In Summary
That may have been a little technical, and for that I’m sorry. But I hope I made enough sense to explain the basics of smart contracts and how they can be used to perform real peer-to-peer transactions (whether financial or not) without the need to trust another party.
To summarize, smart contracts are used to replace the middlemen in a transaction, allowing for truly peer-to-peer markets. They can be used for payments, governance, and almost anything you can think of!