# Human Hour: Volume 3 - Introduction to Smart Contracts and Solidity ## Reading smart contracts using Etherscan Verified vs Unverified contracts: Verified: Humans Of NFT https://etherscan.io/address/0x8575B2Dbbd7608A1629aDAA952abA74Bcc53d22A#code Unverified: Opensea shared Contract https://etherscan.io/address/0x495f947276749ce646f68ac8c248420045cb7b5e#code Decompiler: https://ethervm.io/decompile ## The Ethereum Virtual Machine Runtime env for smart contracts (sandboxed / isolated). no access to network / filesystem etc. EVM - 2 kinds of accounts, external accounts (public-private key) and contract accounts. When a contract is deployed, it gets an account. ## The Ethereum Network A fun visualizer: https://txstreet.com/v/eth-btc ![](https://i.imgur.com/RdiXIW9.png) ## Understanding your seedphrase https://metamask.zendesk.com/hc/en-us/articles/4404722782107-User-guide-Secret-Recovery-Phrase-password-and-private-keys ## What is an RPC node? An RPC (Remote Procedure Call) Node is a type of server, which you communicate with through an API (application programming interface). When your dapp (or a wallet like metamask) wants to execute a transaction, you don't speak directly to the blockchain. Instead, you're communicating with an RPC node that's responsible for reading blockchain data or sending transactions to the network. ## What is Solidity? It's a language (which gets compiled down to bytecode). Inspired by c++ and python etc. Similar to OOP (Object Oriented Programming); ## What is a smart contract? Are digital contracts (programs), stored on the the blockchain. ## What is pragma? The `pragma` keyword tells the compiler what version of solidity you're using. As bugs are fixed, and new features are introduced, new versions of solidity are released. `pragma` allows you to tell the compiler exactly what version you want to use. eg. `pragma solidity 0.8.0` The `^` defines the minimum version the compiler accepts. ## Comments Comments allow you to make notes (comments) inside the code that aren't processed by the compiler (ie the program does not try and execute those lines). Eg. ``` // this is a single line comment /* This is a multi-line comment. It can be as long as you want. */ ``` ## Variables `uint256` - a whole number (256 bits) `string` - a string of characters (ie text) `mapping` - a data-structure that stores key-value pairs `array` - a "list" of variables `bool` - variable that can only be `true` or `false` `address` - an account/contract address ## function visibility `public` - available inside, outside, and in contracts that inherit from the contract its declared in. `external` - available outside the contract, ie it cannot be called inside the contract. `internal` - only available inside the contract and contracts that inherit from it. `private` - only available in the current contract, not to contracts that inherit from it. ## Using Remix Remix is an opensource IDE (integrated development environment) for developing and deploying smart contracts to EVM compatible (Ethereum Virtual Machine) Compatible blockchains (such as Ethereum). https://remix.ethereum.org/#optimize=false&runs=200&evmVersion=null&version=soljson-v0.8.7+commit.e28d00a7.js ## Gas `1 Ether = 1,000,000,000,000,000,000 Wei` `1 Ether = 1,000,000,000 Gwei` `1 Gwei = 1 Giga Gwei` Calculate gas price from Etherscan TX: `Gas Limit x Gas Fee` = Gas Usage (GWEI) Convert GWEI => Ether Unit Converter: https://eth-converter.com/ Op Codes cost gas, you can pull up a table of op code costs: https://github.com/crytic/evm-opcodes Contracts can run out of gas to prevent them from getting stuck in an infinite loop. ## Failed Transactions Examine the state to see the difference (before vs after) of what was actually lost in the transaction. ![](https://i.imgur.com/7EeKjS3.png) ## Gas Estimator https://www.blocknative.com/gas-estimator ## OpenZeppelin, ERC721, ERC1155 Openzeppelin contracts: https://docs.openzeppelin.com/contracts/4.x/ OpenZeppelin Wizard: https://wizard.openzeppelin.com/