Lesson

Smart Contracts: Explained

The real strength of Ethereum lies in the creation of smart contracts. One way to think of smart contracts is that they’re like a special kind of a class. In this class, public functions can be called on externally. And data will be stored in the blockchain. One of the key differences between running this and another programming environment, however, is that when you call a write operations, it will cost gas, which is Ethereum. Keep in mind that some of these write operations will involve sending money as well.

Every contract will run in its own address, its own box that stored in account. This account will be similar to a wallet address that you might have starting with zero x and having some letters and numbers afterwards. The original idea for Ethereum was essentially to do some coding that enables you to put money in holding bin, and this holding bin would require certain parameters to be met. And once those parameters will be met, it could then release the money to someone else or to a number of different people or return the money to the original individual who sent it.

However, smart contracts have evolved considerably. They’ve evolved to encompass all kinds of code that’s executed on a blockchain node. This means they’re behaving much like a normal programming class or an executable service. So each smart contract is essentially a grouping of functions and state variables that reside on the blockchain and also can store data and interact with that blockchain opening unlimited possibilities to what we can do.

Not just in terms of financial applications, but also in terms of decentralized applications. When you create a smart contract, it will be uploaded as bytecode. This bytecode is then stored on the blockchain in the Ethereum network. Now keep in mind the blockchain is immutable, which means that anytime you would want to make a change to the contract, you will have to move that contract to a new address. You can’t edit what’s at the original address, because that is now in a block that’s already been processed.

One thing to remember also is because of this the code is actually stored live, which means you are exposing your actual code. Now, on one hand having that code available and sometimes people will upload not just the binary code, but they’ll upload the original solidity code that they wrote the smart contract in for full transparency. This enables anyone who interacts with that contract to understand that it’s not going to automatically take that ether and send it some mysterious Ethereum wallet.

But because of this public availability of your code, it also means that you code must be written very well. It must be well-tested or savvy hackers can actually exploit the code. This happened in 2016 in what’s now called the famous DAO Hack. Fifty million dollars worth of ether was drained from a contract and this caused a lot of turmoil in the community, whether or not they should write code to fix that hack. The debate still continues today.

The did actually write codes so anyone who’s using ETH, E-T-H, is running on the code base that had a fix for the DAO. However, there were a number of resistors and they’re the ones who created what’s called Ethereum Classic or ETC. So the bottom line is Ethereum represents a turing complete smart contract processing environment. And they talk about this a lot, really all that means is it’s a programming language where you can do the things you’d expect to in a modern programming language.

Everything is available, decentralized on the blockchain. It’s public and it’s unchangeable. Because it’s built into the blockchain, financial applications are extremely easy to write in integrating any type of financial processing comes quite naturally in the smart contract. And finally, keep in mind that you don’t just have to store ether inside of a smart contract. You can store all kinds of data. In fact, any public variable that you create is going to be stored in the state of the Ethereum network and in the blockchain.

Overall smart contracts are one of the key reasons that blockchain and distributed letter technology is advancing beyond the use case of simply storing value or handling financial transactions. Being able to write code that resides in a blockchain allows for distributed functionality that be used to automate contract execution and provide back-end power to decentralize apps or DApps.

Course Discussion