What are Blockchain Smart Contracts?

Siraj Raval · Beginner ·🛠️ AI Tools & Apps ·8y ago

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 What is Bitcoin?
What is Bitcoin?
Siraj Raval
2 5 Ways to Use Bitcoin
5 Ways to Use Bitcoin
Siraj Raval
3 BTC Fever - Siraj [Music Video]
BTC Fever - Siraj [Music Video]
Siraj Raval
4 5 Reasons to Build Decentralized Apps
5 Reasons to Build Decentralized Apps
Siraj Raval
5 The Interplanetary File System
The Interplanetary File System
Siraj Raval
6 How to Build a Dapp in 3 min
How to Build a Dapp in 3 min
Siraj Raval
7 Life Before Smartphones
Life Before Smartphones
Siraj Raval
8 4 Ways to Use Smart Contracts
4 Ways to Use Smart Contracts
Siraj Raval
9 3 Dapps You HAVE to See
3 Dapps You HAVE to See
Siraj Raval
10 Char's Life as a BitTorrent Engineer
Char's Life as a BitTorrent Engineer
Siraj Raval
11 4 Reasons AlphaGo is a Huge Deal
4 Reasons AlphaGo is a Huge Deal
Siraj Raval
12 Build a Neural Net in 4 Minutes
Build a Neural Net in 4 Minutes
Siraj Raval
13 Sentiment Analysis in 4 Minutes
Sentiment Analysis in 4 Minutes
Siraj Raval
14 The Hackathon Life
The Hackathon Life
Siraj Raval
15 Your First ML App - Machine Learning for Hackers #1
Your First ML App - Machine Learning for Hackers #1
Siraj Raval
16 Build an AI Composer - Machine Learning for Hackers #2
Build an AI Composer - Machine Learning for Hackers #2
Siraj Raval
17 Build a Game AI - Machine Learning for Hackers #3
Build a Game AI - Machine Learning for Hackers #3
Siraj Raval
18 Build a Movie Recommender - Machine Learning for Hackers #4
Build a Movie Recommender - Machine Learning for Hackers #4
Siraj Raval
19 Build an AI Artist - Machine Learning for Hackers #5
Build an AI Artist - Machine Learning for Hackers #5
Siraj Raval
20 Build a Chatbot - ML for Hackers #6
Build a Chatbot - ML for Hackers #6
Siraj Raval
21 Build an AI Reader - Machine Learning for Hackers #7
Build an AI Reader - Machine Learning for Hackers #7
Siraj Raval
22 Build an AI Writer - Machine Learning for Hackers #8
Build an AI Writer - Machine Learning for Hackers #8
Siraj Raval
23 Build a Chatbot w/ an API - ML for Hackers #9
Build a Chatbot w/ an API - ML for Hackers #9
Siraj Raval
24 One-Shot Learning - Fresh Machine Learning #1
One-Shot Learning - Fresh Machine Learning #1
Siraj Raval
25 Generative Adversarial Nets - Fresh Machine Learning #2
Generative Adversarial Nets - Fresh Machine Learning #2
Siraj Raval
26 Tone Analysis - Fresh Machine Learning #3
Tone Analysis - Fresh Machine Learning #3
Siraj Raval
27 Generate Rap Lyrics - Fresh Machine Learning #4
Generate Rap Lyrics - Fresh Machine Learning #4
Siraj Raval
28 Build an Autoencoder in 5 Min - Fresh Machine Learning #5
Build an Autoencoder in 5 Min - Fresh Machine Learning #5
Siraj Raval
29 Build a Self Driving Car in 5 Min - Fresh Machine Learning #6
Build a Self Driving Car in 5 Min - Fresh Machine Learning #6
Siraj Raval
30 Build an Antivirus in 5 Min - Fresh Machine Learning #7
Build an Antivirus in 5 Min - Fresh Machine Learning #7
Siraj Raval
31 TensorFlow in 5 Minutes (tutorial)
TensorFlow in 5 Minutes (tutorial)
Siraj Raval
32 Build a Recurrent Neural Net in 5 Min
Build a Recurrent Neural Net in 5 Min
Siraj Raval
33 Build a Simulation in 5 Min
Build a Simulation in 5 Min
Siraj Raval
34 Build a TensorFlow Image Classifier in 5 Min
Build a TensorFlow Image Classifier in 5 Min
Siraj Raval
35 Tensorboard Explained in 5 Min
Tensorboard Explained in 5 Min
Siraj Raval
36 Generate Music in TensorFlow
Generate Music in TensorFlow
Siraj Raval
37 Build a Game Bot (LIVE)
Build a Game Bot (LIVE)
Siraj Raval
38 Deep Learning Frameworks Compared
Deep Learning Frameworks Compared
Siraj Raval
39 Introduction - Learn Python for Data Science #1
Introduction - Learn Python for Data Science #1
Siraj Raval
40 Build a Neural Network (LIVE)
Build a Neural Network (LIVE)
Siraj Raval
41 Twitter Sentiment Analysis - Learn Python for Data Science #2
Twitter Sentiment Analysis - Learn Python for Data Science #2
Siraj Raval
42 Recommendation Systems - Learn Python for Data Science #3
Recommendation Systems - Learn Python for Data Science #3
Siraj Raval
43 Predicting Stock Prices - Learn Python for Data Science #4
Predicting Stock Prices - Learn Python for Data Science #4
Siraj Raval
44 Pong Neural Network (LIVE)
Pong Neural Network (LIVE)
Siraj Raval
45 Deep Dream in TensorFlow - Learn Python for Data Science #5
Deep Dream in TensorFlow - Learn Python for Data Science #5
Siraj Raval
46 Visualizing Data with D3.js (LIVE)
Visualizing Data with D3.js (LIVE)
Siraj Raval
47 Genetic Algorithms - Learn Python for Data Science #6
Genetic Algorithms - Learn Python for Data Science #6
Siraj Raval
48 Enter Siraj [Music Video]
Enter Siraj [Music Video]
Siraj Raval
49 Build a Web Scraper (LIVE)
Build a Web Scraper (LIVE)
Siraj Raval
50 Why is P vs NP Important?
Why is P vs NP Important?
Siraj Raval
51 How to Make a Neural Network (LIVE)
How to Make a Neural Network (LIVE)
Siraj Raval
52 How to Make an Amazing Tensorflow Chatbot Easily
How to Make an Amazing Tensorflow Chatbot Easily
Siraj Raval
53 How to Make an Amazing Video Game Bot Easily
How to Make an Amazing Video Game Bot Easily
Siraj Raval
54 How to Make a Tensorflow Neural Network (LIVE)
How to Make a Tensorflow Neural Network (LIVE)
Siraj Raval
55 How to Make a Simple Tensorflow Speech Recognizer
How to Make a Simple Tensorflow Speech Recognizer
Siraj Raval
56 Joel Shor - Really Quick Questions with an Awesome Google Engineer
Joel Shor - Really Quick Questions with an Awesome Google Engineer
Siraj Raval
57 How to Make a Path Planning Algorithm Easily (LIVE)
How to Make a Path Planning Algorithm Easily (LIVE)
Siraj Raval
58 The Best Way to Prepare a Dataset Easily
The Best Way to Prepare a Dataset Easily
Siraj Raval
59 Catherine Olsson - Really Quick Questions with an OpenAI Engineer
Catherine Olsson - Really Quick Questions with an OpenAI Engineer
Siraj Raval
60 How to Make a Tic Tac Toe Neural Network Easily (LIVE)
How to Make a Tic Tac Toe Neural Network Easily (LIVE)
Siraj Raval

This video teaches viewers how to create a digital notary using Ethereum blockchain and smart contracts, and how to develop and deploy a simple proof of existence smart contract. It covers the basics of smart contracts, blockchain technology, and the use of tools such as Solidity and Truffle. By the end of this video, viewers will be able to build and deploy their own smart contracts.

Key Takeaways
  1. Run truffle compile to compile example contracts
  2. Run truffle migrate to deploy contracts through simulated network
  3. Write a simple proof of existence smart contract using Truffle
  4. Create a digital notary that stores hashes of documents as proofs of their existence
  5. Notarize a document's hash in a smart contract's state variable using the notarize function
💡 Smart contracts can be used to automate administrative tasks and provide a secure and distributed ledger for various applications, but they are computationally expensive and should only be used for features that require a distributed and secure ledger.

Related Reads

Up next
Brisbane Catholic Education Frontier Transformation: Turning AI Ambition into Human Impact
Microsoft Cloud
Watch →