What are Blockchain Smart Contracts?
Key Takeaways
The video demonstrates the use of Ethereum blockchain and smart contracts to create a digital notary for proof of existence, using tools such as Solidity, Truffle, and GitHub. It covers the basics of smart contracts, blockchain technology, and the development of a simple proof of existence smart contract.
Full Transcript
hello world it's Suraj and I've really been digging smart contracts lately they're so powerful we're gonna build a smart contract that implements proof of existence it's an immutable digital notary that proves the ownership and existence of any document without needing to hire a lawyer the advent of Bitcoin proved that we could exchange value over the Internet in a way that didn't need to involve a third party namely a bank what made this possible was its use of a data structure that distributes trust across many nodes instead of a few called the blockchain I think I'm ready to jump on the path every node downloads a copy of it and stores every single transaction that's occurred in the network it can't be hacked or tampered with because it's secured by the proof-of-work algorithm only Jeff Dean has that much computing power since then several crypto currencies have popped up adding their own features to the Bitcoin blockchain to extend its functionality but the cryptocurrency with the second highest market cap in the world aetherium is by far the most interesting in terms of its potential to power a new wave of applications if their IAM is a digital currency just like Bitcoin but it's also got its own turing-complete programming language that lets you build what are called smart contracts let's rewind a bit in the Bitcoin network any coins that you buy are sent to a unique address no coins are actually held at this address it just acts as a unique identifier like a bank account number that allows the total of the transactions to and from this address to be calculated we can think of Bitcoin as a ledger that records the deposits and withdrawals from accounts when we send a transaction via the Bitcoin network the old balance is reduced by some amount and another accounts balance is increased by this amount but no physical value is ever moved aetherium works slightly differently it stores the number of coins you own at an address called a smart contract this is a piece of code which is stored on the blockchain network it defines the conditions to which all parties using the contract agree upon so if required conditions met certain actions are executed no need for a judge or AWS or really any third party to enforce the rules the ability to store info at these addresses is called the etherium state whereas Bitcoin only stores transactions that have been sent in the blockchain any type of data can be stored in the etherium state and thereby the etherium blockchain the information that is stored could range from the amount of either you have to the type of life insurance you own and since computation is scarce there must be a mechanism to limit the resources used by each contract every single operation that is executed inside the EVM is actually simultaneously executed by every node in the network this is why gas exists gas is internal it can't be purchased it's used to calculate the price of a transaction and ether and ultimately limit the EVM an etherium transaction contract code can trigger data reads and writes do expensive computations like using cryptographic primitives making calls to other contracts etc each of these operations have a cost measured in gas and each gas unit consumed by a transaction must be paid for an ether based on a gas to ether price which changes dynamically this price is deducted from the etherium account sending the transaction smart contracts enable aetherium to operate as a global server where you pay for each transaction instead of a monthly fee for some central server provider the gas as well motivates developers to write efficient code so that it would require less gas or the execution one interesting thing to note is that smart contracts can't execute API call directly if we wanted to build a weather app and wanted to connect to a weather API to retrieve data and show the info accordingly that code would need to be executed on each and every node so that call to the weather API could happen at different times as the nodes might start executing the code not at the same time in one second we could have rainy weather data returned and in another we could have sunny weather nodes wouldn't be able to reach consensus on the result of the smart contract in this case but we need data from the real world it's super useful so the solution is to use what's called an Oracle instead of the smart contract calling an external API the API itself pushes the data to the blockchain so that means that all the nodes now have the same data within the network so a contract triggers an event an external app can listen to that event retrieve the data from the API and add a transaction with the result to the contract we can ensure the integrity of the Oracle by using a smart contract as an insurance policy against it corrupting the integrity of the data but wait bitcoins got smart contract functionality too with Bitcoin smart contracts it's important to understand that each transaction exists as a data structure composed of inputs and outputs in order to send Bitcoin users must provide certain inputs meeting predetermined requirements that prove they own and therefore have the authority to send bitcoins they claim to own users can also create contract transactions that require a more complex set of inputs in order to trigger the release of bitcoins a simple example of more complex inputs is a multi signature transaction which requires more than one entity that sign off on the release of Bitcoin proving useful in escrow situations where two of three parties have to vouch for a transfer smart contracts in general are pretty computationally expensive to execute so not every conditional transaction is appropriate for execution via a blockchain we should only use them for features that demand the distributed and secure nature of a shared ledger think about an apartment complex and all the administrative work required to maintain it if we use smart contracts where a tenancy is registered on the blockchain they can be used to control access to the building when you pay the rent each tenants access to the building is renewed owners with registered keys are granted access to all the various types of utilities like mailboxes and washing machines we can also use biometrics to help authenticate users no need to maintain a server it's all completely automated this can be applied to grant ownership that is publicly verifiable over really anything physical objects as well making them smart property you could even incorporate a company on the blockchain and if we're really ambitious an entire nation could be defined not by geography but by the rules and benefits of citizenship on the blockchain let's get the building to start developing aetherium apps will need a client to connect to the network it will act as a window to the distributed network and provide a view of the blockchain where all the EVM states are represented there are various compatible clients for the protocol the most popular being def a go language implementation however it's not the most developer friendly the best option I've found is the test RPC node which we can install and run we can run test RPC in a new terminal and leave it running while we develop each time we run test RPC it will generate 10 new addresses with simulated test funds for us to use this is not real money and we're safe to try anything with no risk of losing funds the most popular language for writing smart contracts in aetherium is solidity so we'll be using that we're also using the truffle development framework which helps with smart contract creation compiling deployment and testing we should be able to compile the example contracts by running truffle compile then to deploy the contracts through the simulated network using the test RPC node we have running we need to run truffle migrate we'll be writing a simple proof of existence smart contract the idea is to create a digital notary that stores hashes of documents as proofs of their existence we can use truffle create contracts to get started then we'll open proof of existence that's Sol in a text editor contracts have States and functions it's important to distinguish two kinds of functions that can appear in a contract the first are read-only functions functions that don't perform any state changes the only read States perform computations and return values and the other kind are transactional functions functions that perform a state change in the contract or move funds our code only stores one proof at a time using the data type bytes 32 which is the size of a shoe 2:56 hash the transactional function notarize allows one to store the hash of a document in our smart contracts state variable proof the variable is public and is the only way a user of our contract has to verify if a document has been notarized let's deploy proof of existence to the network this time we'll have to edit the migration file to make truffle deploy our new contract now that our contract is deployed we can play with it as in we can send messages to it via function calls and read its public state using the truffle console so what have we learned a smart contract is code that is stored and run on a blockchain making it trustless and immutable we can use them to verify ownership automate financial instruments and create more autonomous software and etherium is currently the most developed platform to build smart contracts this week's coding challenge is to create a smart contract that an AI can interact with more details are in the readme github links go in the comments and I'll give the top two entries a shout out next Friday hope you liked the video please subscribe for more programming videos and for now I've got to fight the power so thanks for watching
Original Description
More and more apps will start using smart contract technology to enable never before possible features. We're going to build a smart contract called "proof of existence" that acts as a digital notary for any document using the Ethereum blockchain.
Code for this video:
https://github.com/llSourcell/proof_of_existence_demo
Please Subscribe! And like. And comment. Thats what keeps me going.
Follow me on:
Twitter: https://twitter.com/sirajraval
Facebook: https://www.facebook.com/sirajology/
More learning resources:
https://www.slideshare.net/intrins1k/ethereum-meetup-presentation-01042017-70716809
https://www.youtube.com/watch?v=R_CiemcFKis
https://auth0.com/blog/an-introduction-to-ethereum-and-smart-contracts-part-2/
https://ethereumdev.io/
https://ethereum.gitbooks.io/frontier-guide/content/writing_contract.html
http://hypernephelist.com/2016/06/01/deploying-my-first-smart-contract.html
https://blog.cloudboost.io/ethereum-smart-contracts-in-a-nutshell-for-hackers-64f357715791
http://www.techracers.com/smart-contract-solidity
http://ecomunsing.com/tutorial-controlling-ethereum-with-python
Join us in the Wizards Slack channel:
http://wizards.herokuapp.com/
And please support me on Patreon: https://www.patreon.com/user?u=3191693 Instagram: https://www.instagram.com/sirajraval/ Instagram: https://www.instagram.com/sirajraval/
Signup for my newsletter for exciting updates in the field of AI:
https://goo.gl/FZzJ5w
Hit the Join button above to sign up to become a member of my channel for access to exclusive content! Join my AI community: http://chatgptschool.io/ Sign up for my AI Sports betting Bot, WagerGPT! (500 spots available): https://www.wagergpt.xyz
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Siraj Raval · Siraj Raval · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
What is Bitcoin?
Siraj Raval
5 Ways to Use Bitcoin
Siraj Raval
BTC Fever - Siraj [Music Video]
Siraj Raval
5 Reasons to Build Decentralized Apps
Siraj Raval
The Interplanetary File System
Siraj Raval
How to Build a Dapp in 3 min
Siraj Raval
Life Before Smartphones
Siraj Raval
4 Ways to Use Smart Contracts
Siraj Raval
3 Dapps You HAVE to See
Siraj Raval
Char's Life as a BitTorrent Engineer
Siraj Raval
4 Reasons AlphaGo is a Huge Deal
Siraj Raval
Build a Neural Net in 4 Minutes
Siraj Raval
Sentiment Analysis in 4 Minutes
Siraj Raval
The Hackathon Life
Siraj Raval
Your First ML App - Machine Learning for Hackers #1
Siraj Raval
Build an AI Composer - Machine Learning for Hackers #2
Siraj Raval
Build a Game AI - Machine Learning for Hackers #3
Siraj Raval
Build a Movie Recommender - Machine Learning for Hackers #4
Siraj Raval
Build an AI Artist - Machine Learning for Hackers #5
Siraj Raval
Build a Chatbot - ML for Hackers #6
Siraj Raval
Build an AI Reader - Machine Learning for Hackers #7
Siraj Raval
Build an AI Writer - Machine Learning for Hackers #8
Siraj Raval
Build a Chatbot w/ an API - ML for Hackers #9
Siraj Raval
One-Shot Learning - Fresh Machine Learning #1
Siraj Raval
Generative Adversarial Nets - Fresh Machine Learning #2
Siraj Raval
Tone Analysis - Fresh Machine Learning #3
Siraj Raval
Generate Rap Lyrics - Fresh Machine Learning #4
Siraj Raval
Build an Autoencoder in 5 Min - Fresh Machine Learning #5
Siraj Raval
Build a Self Driving Car in 5 Min - Fresh Machine Learning #6
Siraj Raval
Build an Antivirus in 5 Min - Fresh Machine Learning #7
Siraj Raval
TensorFlow in 5 Minutes (tutorial)
Siraj Raval
Build a Recurrent Neural Net in 5 Min
Siraj Raval
Build a Simulation in 5 Min
Siraj Raval
Build a TensorFlow Image Classifier in 5 Min
Siraj Raval
Tensorboard Explained in 5 Min
Siraj Raval
Generate Music in TensorFlow
Siraj Raval
Build a Game Bot (LIVE)
Siraj Raval
Deep Learning Frameworks Compared
Siraj Raval
Introduction - Learn Python for Data Science #1
Siraj Raval
Build a Neural Network (LIVE)
Siraj Raval
Twitter Sentiment Analysis - Learn Python for Data Science #2
Siraj Raval
Recommendation Systems - Learn Python for Data Science #3
Siraj Raval
Predicting Stock Prices - Learn Python for Data Science #4
Siraj Raval
Pong Neural Network (LIVE)
Siraj Raval
Deep Dream in TensorFlow - Learn Python for Data Science #5
Siraj Raval
Visualizing Data with D3.js (LIVE)
Siraj Raval
Genetic Algorithms - Learn Python for Data Science #6
Siraj Raval
Enter Siraj [Music Video]
Siraj Raval
Build a Web Scraper (LIVE)
Siraj Raval
Why is P vs NP Important?
Siraj Raval
How to Make a Neural Network (LIVE)
Siraj Raval
How to Make an Amazing Tensorflow Chatbot Easily
Siraj Raval
How to Make an Amazing Video Game Bot Easily
Siraj Raval
How to Make a Tensorflow Neural Network (LIVE)
Siraj Raval
How to Make a Simple Tensorflow Speech Recognizer
Siraj Raval
Joel Shor - Really Quick Questions with an Awesome Google Engineer
Siraj Raval
How to Make a Path Planning Algorithm Easily (LIVE)
Siraj Raval
The Best Way to Prepare a Dataset Easily
Siraj Raval
Catherine Olsson - Really Quick Questions with an OpenAI Engineer
Siraj Raval
How to Make a Tic Tac Toe Neural Network Easily (LIVE)
Siraj Raval
More on: LLM Foundations
View skill →
🎓
Tutor Explanation
DeepCamp AI