ENGLISH

Beginning Ethereum Smart Contracts Programming: With Examples in Python, Solidity, and JavaScript

Book information

Publisher
Apress
Year
2023
ISBN
1484292707, 9781484292709
Language
english
Format
PDF
Filesize
16 MB (16913590 bytes)
Edition
2
Pages
387\377
Time added
2023-04-16 03:59:34

Description

Use this book to write an Ethereum blockchain smart contract, test it, deploy it, and create a web application to interact with your smart contract. This new edition has been expanded and updated to cover web3.js APIs, additional Consensus Protocols, non-Fungible Tokens (NFTs), developing NFT tokens using ERC-721, and more! Beginning Ethereum Smart Contracts Programming, second edition is your fastest and most efficient means of getting started if you are unsure where to begin and how to connect to the Ethereum blockchain. The book begins with a foundational discussion of blockchain and the motivation behind it. From there, you will get up close and personal with the Ethereum blockchain, learning how to use an Ethereum client (geth) to create a private Ethereum blockchain to perform transactions such as sending Ethers to another account on another node.  You will learn about smart contracts without having to wade through tons of documentation. Author Lee’s “learn-by-doing” approach will allow you to be productive and feel confident in your ability in no time. The last part of this book covers tokens, a topic that has taken the cryptocurrency market by storm. Sample code in Python, Solidity, and JavaScript is provided in the book and online. What You'll LearnUnderstand the basic premise of blockchain and “record keeping” in a peer-to-peer network Experience blockchain in action by creating your own blockchain using Python Know the foundation of smart contracts programming and how to deploy and test smart contracts Work on a case study to illustrate the use of blockchain Be familiar with tokens, and how to create and launch your own ICO digital token Write smart contracts that transact using tokens Who This Book Is For Those who want to get started quickly with Ethereum smart contracts programming. Basic programming knowledge and an understanding of Python or JavaScript is recommended. Table of Contents About the Author About the Technical Reviewer Acknowledgments Introduction Chapter 1: Understanding the Science Behind Blockchain: Cryptography What Is Cryptography? Types of Cryptography Hash Functions Uses of Hashing Implementing Hashing in Python Symmetric Cryptography Generating the Shared Key in Python Performing Symmetric Encryption Performing Symmetric Decryption Asymmetric Cryptography Generating and Saving the Public/Private Key Pairs Encrypting Using the Public Key Decrypting Using the Private Key Digital Signature: Signing Using Private Key Verifying the Digital Signature Using a Public Key How Cryptography Is Used in Blockchain Hashing Symmetric and Asymmetric Cryptography Digital Signature Summary Chapter 2: Understanding Blockchain Motivations Behind Blockchain Placement of Trust Trust Issues Solving Trust Issues Using Decentralization Example of Decentralization Blockchain As a Distributed Ledger How a Blockchain Works Chaining the Blocks Immutability of Blockchains Consensus Protocols Proof of Work The Mining Process Proof of Stake (PoS) Comparing PoW with PoS Blockchain in More Detail Types of Nodes Merkle Tree and Merkle Root Uses of Merkle Tree and the Merkle Root Summary Chapter 3: Implementing Your Own Blockchain Using Python Your Conceptual Blockchain Implementation Obtaining the Nonce Installing Flask Importing the Various Modules and Libraries Declaring the Class in Python Finding the Nonce Appending the Block to the Blockchain Adding Transactions Exposing the Blockchain Class as a REST API Obtaining the Full Blockchain Performing Mining Adding Transactions Testing Your Blockchain Synchronizing Blockchains Testing the Blockchain with Multiple Nodes Full Listing for the Python Blockchain Implementation Summary Chapter 4: Creating Your Own Private Ethereum Test Network Downloading and Installing Geth, the Ethereum Client Installing Geth for macOS Installing Geth for Windows Installing Geth for Linux Creating the Private Ethereum Test Network Creating the Genesis Block Creating a Folder for Storing Node Data Initiating a Blockchain Node Starting Up the Nodes Creating Accounts Checking the Balance of an Account Stopping the Node Starting Another Node Getting Information About the Node Pairing the Nodes Performing Mining Examining a Block Mining on Both Nodes Transferring Ethers Between Nodes Managing Accounts Removing Accounts Setting the Coinbase Summary Chapter 5: Using the MetaMask Crypto-Wallet What Is MetaMask? How MetaMask Works Behind the Scenes Installing MetaMask Setting Up the Accounts Using the MetaMask Extension Selecting Ethereum Networks Getting Test Ethers Creating Additional Accounts Transferring Ethers Recovering Accounts Importing and Exporting Accounts Exporting Accounts Importing Accounts Summary Chapter 6: Getting Started with Smart Contracts What Is a Smart Contract? How Smart Contracts Are Executed Your First Smart Contract Using the Remix IDE Compiling the Contract Testing the Smart Contract Using the JavaScript VM Getting the ABI and Bytecode of the Contract Testing the Smart Contract Using the Goerli Testnet Summary Chapter 7: Storing Proofs Using Smart Contracts A Smart Contract as a Store of Proofs Creating the Smart Contract Compiling the Contract Deploying the Contract Testing the Contract Making Further Changes to the Smart Contract Restricting Access to Functions Accepting Payments in Smart Contracts Events in Smart Contracts Cashing Out Destroying a Contract Summary Chapter 8: Using the web3.js APIs What Is web3.js? Installing web3.js Testing the web3.js Using MetaMask Interacting with a Contract Using web3.js Summary Chapter 9: Developing Web3 dapps using Python Interacting with Ethereum Using Python Registering with Infura Connecting to Infura Fetching a Block Setting Up the Accounts Getting the Balance of an Account Transferring Ethers Between Accounts Creating a Dapp Using Python Loading the Contract Base64 Encoding Saving Credentials on the Blockchain Verifying the Result Summary Chapter 10: Project: Online Lottery How the Lottery Game Works Defining the Smart Contract Betting a Number Setting the Winning Number and Announcing the Winners Getting the Game Status and Winning Number Cashing Out from the Contract Testing the Contract Announcing the Winner Saving the ABI of the Contract Deploying the Contract to the Testnet Creating the Web Front End Announcing the Winning Number Cashing Out The Complete Contract Summary Chapter 11: Creating Your Tokens What Are Tokens? How Tokens Are Implemented? Minting New Tokens Burning Tokens Units Used Internally in Token Contracts ERC-20 Token Standard Creating Token Contracts Overriding the Number of Decimal Places of Precision Deploying the Token Contract Adding the Token to MetaMask What Can You Do with the Token? Using Tokens for Smart Contract Payments Selling Tokens Programmatically Calculating the Amount of Tokens Bought Deploying the Contract Summary Chapter 12: Creating Non-Fungible Tokens Using ERC-721 What Is an NFT? Ownership vs. Copyright Where Do You Buy or Sell NFTs? Creating NFTs Using Token Contracts Who Deploys the NFT Token Contract? Using ERC-721 for Creating NFTs Deploying the NFT Token Contract Testing the NFT Contract Getting the Owner of the Token Preparing the Digital Asset to be Sold as an NFT Minting the NFT Getting the Name and Symbol of the NFT Token Contract Finding the Balance of NFTs for an Address Getting the Owner of an NFT Getting the TokenURI of an NFT Transferring an NFT to Another Account Transferring Ownership of the Contract Summary Chapter 13: Introduction to Decentralized Finance Limitations of Traditional Finance Decentralized Finance Components in DeFi Stablecoins Fiat-Backed Stablecoins Crypto-Backed Stablecoins What Is a DAO Exactly? How DAI Works DAI Liquidation Non-Collateralized Stablecoins Crypto Exchanges Creating a Decentralized Exchange Creating the Token Contract Deploying the Token Contract Creating the DEX Contract Funding the DEX Swapping WML Tokens for LWM Tokens Summary Index Capture.PNG Capture.PNG Capture.PNG Capture.PNG

Similar books