My Current Understanding of Smart Contracts
Before diving in, a quick disclaimer: I have been looking into this topic for a short while. Some of the things written below may be inprecise or false. My focus is on the Ethereum (ETH) ecosystem, things can be different when it comes to other ones. Consider the below to be a work in progress.
Disclaimer: I’m pretty new to this topic, and might be mixing up words and concepts without realizing it! Consider this a work in progress :) I think it’s helpful already, but some parts might be technically wrong. If you spot a mistake - feel free to ping me @vsupalov
A quick overview:
- You can think of a blockchain as one big computer: being able to store data and perform computations. Made possible by the work of lots of actual computers.
- “Smart Contract” is a fancy word for a program residing on a blockchain.
- Environments differ! I have looked into Ethereum and Solana smart contracts. Both have major differences. There are more environments, Polygon for example.
- A token is a kind of smart contract, keeping track of values to addresses.
- Gas fees can add up.
Blockchain = Big Virtual Computer
I think this is a good place to get started. When it comes to the Ethereum blockchain, each block added contains transactions.
Each transaction can contain arbitrary data. Either transfering ETH from one adress to another, or deploying a Smart Contract. In that case, the data field contains code.
The code is in evaluated in an EVM environment.
What Does Smart Contract Mean?
Smart Contract is a fancy word for code, which is deployed to a blockchain.
That code is deployed through a transaction to an own, new address. In the case of Ethereum, the code is immutable, so once deployed, the code can’t be changed.
However, a Smart Contract on Ethereum can store state, and modify that state.
That contract’s public functions can be interacted with. Triggered by a fresh transaction - either directly or sometimes to another deployed Smart Contract.
Ethereum Is Just One Ecosystem
When writing Smart Contracts for the Ethereum blockchain, people usually use Solidity.
As described above, the contract code is immutable, and state is stored right at the contract’s address.
However, there are other blockchains and approaches! I don’t have an overview of most of them at the moment, but I’ve seen enough of Solana to be able to tell that it’s pretty different in many ways.
A Token Is a Kind of Smart Contract
Here’s something I found really interesting: when somebody created a “token” on the Ethereum blockchain, it basically just means that they deployed a Smart Contract, which keeps track of “how much of the token” addresses own.
Imagine a big hashmap, connecting addresses to numbers. That’s mostly it! And a few standardised functions to make sure the token behaves like people expect.
Two Noteworthy Smart Contract Standards
There are two standards (basically definitions of public interfaces) you should know about:
EIP-20 and EIP-721.
The Token Standard and the Non-Fungible Token Standard.
Go ahead, click the links above and look over the respective specification section! It’s really pretty straightforward.
EIP-20 defines a mapping from addresses to their balance. It’s great if you want to make it possible for people to own and transfer arbitrary “token” amounts.
EIP-721 is similar, but it stores information about ownership of single, distinct tokens. This is what NFTs are made of!
One more! EIP-1155 is the Multi Token Standard. It can keep track of multiple EIP-20 and/or EIP-721 tokens. That’s useful for something like a game, where you want to have multiple kinds of tokens and NFT collections, but would prefer to manage them all in one contract.
These standards, make it possible for other Smart Contracts and application to work with any other Smart Contracts which conforms to the standard they need - interchangeably. This is why Open Sea can list so many NFT collections. Each is a Smart Contract providing at least the minimal subset of necessary public functions.
These Computations Brought to You By: Gas
Computation and storage on the blockchain isn’t free! If you want to submit a transaction which interacts with a Smart Contract, executes code and stores data you have to pay for it: in gas.
Gas prices go up when lots of people want to interact with the Ethereum blockchain. They can get insanely high!
This is one of the reason, people consider using other Blockchains. Something like Polygon, which offers lower gas fees, but still notes data onto the Ethereum blockchain (only not that often to my understanding. Something-something L2 & sidechain).
Or Solana, which is engineered to provide fast and more affordable transactions, but is an own blockchain, which is sometimes criticized for being on the centralized end of the decentralization spectrum.
Right now, it’s not unusual to pay around 100 bucks or more to “mint” an NFT. The same interaction can be less expensive on Solana or Polygon (but also without some of the benefits Ethereum brings to the tabe. Tradeoffs!).