Logo
GlobalWebThree
Blockchain Picture

Please Read The Blockchain Section Before Continuing






What is a smart contract?

In our last section, we learned how a blockchain records transactions and puts them into blocks that are then added to the blockchain. From 2009 with the creation of Bitcoin until 2015 when Ethereum was created, the only transactions that could be recorded on alomost every blockchain where transferring cryptocurriencies. In 2015 however, Vitalik Buterin, the creater of Ethereum, decided to make a blockchain that would allow someone to send a computer program, called a smart contract, to it as a transaction. People could then interact with these computer programs (smart contracts), directly, without having to go through a centralized company as an intermediary.






Why put a computer program on a blockchain?

In todays world, every website is hosted on a server run by some centralized person or company. This has several disadvantages:
1) Malicious code: You can't trust the code on the centralized server because you don't know what it is doing. Unless they publish their code, you have no idea what it is really doing, and even if they did publish it, they could change their code at any time.
2) Hacking: Even if you trust whoever is running the servers, there is always a major risk that a hacker can get into thier server and steal your data, infect your computer, or worse.
3) Privacy: On a centralized server, it's very easy for companies to see exactly who you are, what you're doing on their site, and track you across different websites and then sell that data to whomever they want.
4) Middle men: Most centralized websites require some kind of fee in order for them to carry out a transaction between you and a third party, whether it be an online raffle, escrow company, or any other kind of sale/interaction.
Smart Contracts solve all of these problems.
1) Smart Contracts are stored on a blockchain, so anyone can see exactly what the code is, and know that no one will ever be able to change it.
2) The only way someone can "hack" a smart contract is if it isn't written well. If your smart contract is written correctly, no hacker can enter the blockchain and deleter or alter your code in any way.
3) Every interaction by a user with a smart contract is only visible as a collection of letters and numbers called an address.
4) Instead of having to go through a middleman, users can interact with smart contracts directly, drastically lowering costs, increasing efficiency, and eliminating the need for trust between and of the parties involved.






Does the Smart Contract have an address on the Ethereum blockchain?

Yes, just like individuals have accounts on Ethereum, that can send and receive Ether, the smart contract also has an address on Ethereum. Not only can it send and receive Ether, but it can be written to do just about anything that a computer program that isn't on a blockchain can do.






What Can A Smart Contract Do?

Here is an example: Imagine you want to buy some property from a stranger. You aren't certain that the property is as good they say it is, and you don't want to pay them right away just incase there are any defects. In these situations, people usually turn to third party escrow companies to hold onto the money until the sale goes through and both parties are satisfied. If the buyer is unsatisfied, the money is returned. Of course, the third party requires a fee for this, and you have nothing but trust that they won't run away with the money they are supposed to be holding. A smart contract solves both these problems. The money can be stored in a smart contract, and only be given to the seller if the buyer is satisfied with the property, otherwise the smart contract will automatically return the money to the buyer. Since the smart contract is simply an independent computer program whose code is completely visible to anyone and unable to be edited, you don't need to worry that the smart contract will run off with the money, request a fee for holding it, or make any mistakes or delays with which address the money will be sent.
Here is another example. Imagine you are entering a raffle where ther winner will be chosen based on a random winner. With normal raffles, you have to trust that the number chosen will truly be random, and pay the company that is putting on the raffle. With a smart contract, none of these are concerns. The number can be derived from a decentralized chainlink oracle (explained below), and the smart contract will take that number and choose a winner, without anyone needing to trust a company, or pay the smart contract a fee for doing this.





Can anyone interact with the smart contract?

By default anyone can interact with the smart contract, but you can write the contract in a way that only your account, or accounts that you choose can interact with part or all of the smart contract if you wish.






Can I Remove A Smart Contract From The Blockchain?

By default a smart contract cannot be removed from Ethereum, but you can code in a self destruct function that will delete all the bytecode and essentially remove the smart contract from Ethereum (although you can still see all previous transactions prior to the smart contracts self destruction).






What is Gas?

Every action that a smart contract can do requires some amount of complexity. Ethereum actually has a unit for complexity, and this unit is called gas. So for example, a function might be 500 units of complexity, so we say that the function costs 500 gas. In order to interact with these smart contracts, you need to pay a small amount of ether per complexity unit (per gas). The price of the gas varies on a lot of factors including how many users are on the network at a given time, and fluctuates constantly. We will talk about how to see how much gas a transaction has and the price for each unit of gas in the next section titled MetaMask.





What is MetaMask?

In order to interact with these smart contracts that are on the Ethereum blockchain, you need to have an address on the Ethereum blockchain as well. The easiest and most popular way to do this is through MetaMask, MetaMask is a cryptocurrency wallet but it's also a browser extension that allows you to run Ethereum dApps (decentralized applications) right in your browser without running a full Ethereum node. It's available as a browser extension for Chrome, Firefox, Opera, and Brave. Then click the blue button that says Add to Chrome






What is an NFT?

A Non Fungible Token, or NFT is just a fancy way of saying a unique asset. US dollars for example, is not unique because I can trade one dollar for another dollar and it won't make any difference. A famous painting or a house for example are unique assets. I can't just trade one house for another and not expect any difference.
NFTs are created inside smart contracts. In one section of the smart contract keeps track of a number, called a token. In another section of the token it links a users ethereum address to that number (token). This linked address is said to be the "owner" of the NFT. In the final section of the smart contract, the actual asset is put onto the smart contract, the deed to a house for example. If someone buys the NFT for a deed to the house, it means that the address in the second section linked to the token in the first section changes from the sellers address to the buyers address. This way you don't need to keep the deed to the house in a physical location, it can just be on the blockchain and you can see exactly who bought and sold the NFT and at what time all the way back to the original address owner.
NFTs for art are slightly different than NFTs for other assets because the gas cost to put art on the third section of the smart contract is so high that people often just put the art on a central server off of the blockchain and in the third section of the smart contract they just have a http link to that server.






What is an ERC20 token?

In the section titled Blockchain/Cryptocurrency we explained that a cryptocurrency is just the reward a miner is paid for adding a block of transactions to the blockchain. There is actually another way to make cryptocurrencies though, and it's called an ERC20 token. First you create a smart contract that creates a number. This number is the total amount of ERC20 tokens. You then have other sectins in the smart contract that allow for sending these ERC20 tokens and another section that keeps track of how has been sent these tokens (their balances). You can think of an ERC20 token as a cryptocurerncy inside of a smart contract. This is different from the cryptocurrency paid to miners for adding blocks of transactions to the blockchain (these are called native tokens as opposed to ERC20 tokens). With these ERC20 tokens, the person writing the smart contract can decide exactly how many tokens to begin with, whether there can be more added, exactly who can control how many more can be added, etc.






What is the difference between an NFT and an ERC20 token?

An NFT is a number (token) linked to a particular person (address). With an ERC20 token, each number (token) isn't linked to a name or differnt than any other token. If I have 10 ERC20 tokens and you have 10 ERC20 tokens and we trade them, there won't be any differnece. The tokens themselves are not unique, unlike NFTs.






What is a DAO?

What are these ERC20 Tokens mainly used for? To answer this we need to introduce a few new terms and ideas. The first idea is that users aren't the only ones on the blockchain that can interact with smart contracts, other smart contracts on the blockchain can also do this. The second idea is that you can program a smart contract to only interact with approved users (called contract owners). You can also have the owners of this contract vote on whether or not to have the smart contract do certain tasks. How does this voting work? By giving each user some amount of ERC20 tokens that they can use as a way to vote. One ERC20 token, one vote. So a DAO essentially is a smart contract where users that have an approved ERC20 tokens can use them to vote on what that smart contract should do (kind of like shareholders voting on what a company should do). These smart contracts don't need a board of directors or other centralized governing body, the token holders themselves are allowed to directly vote on all tasks a smart contract can do after. Certain users propose the smart contract (DAO) to do something, and then the ERC20 token holders can choose vote to pass or reject the proposal. Because there is no board of directors or other governing body, it is decentralized, hence the name Decentralized Autonomous Organization (DAO).






What is Web3?

To understand Web3, we need to understand what Web1 and Web2 are. Also, there seems to be some confusion between what the WorldWideWeb is and what the internet is, so I will explain that too. The internet is essentially a system of fiberoptic cables that connects every internet service provider all over the world. Think of it as analogous to all the roads and highways across the world that connect everyone and allow people to travel anywhere. The web is best thought of as having the actual content that you search with your web browser. Using our road analogy, the internet is the roads that allow people to travel to places, but the places they want to get to (websites) would be the web. Websites are stored in computers called webservers, while webbrowsers like Chrome, Safari, and Brave talk to these websites using http requests, and find out what they are supposed to look like and then show that information to the user. Web1, the first version of the web just displayed text and information to the user. Web2, the current iteration of the web allowed users to interact with these websites (Commenting, liking, posting lots of content, etc). These webservers however are owned mainly by centralized companies and organizations. You can't see the websites code, it can be changed at any moment, it's vulnerable to being exploited by hackers, and they are almost certainly tracking you and selling your data. Web3 is the next iteration of the web, where the content is stored on a blockchain like Ethereum instead of centralized webservers. This way, anyone can see the code, no one, not even the best hacker in the world, can change the smart contract once it's been deployed, and all your personal data isn't being tracked and sold (only your address on the blockchain and the transactions it makes can be tracked).