# NEAR and Far from _any_ Coding v.3.1 ## Course Outline --------- ## Welcome to the Course! Anyone with a computer and internet connection can take this course. If you are interested in making sense of Web3, but you don't know how to read or write code, then you are in the right place :wink: You might even be considering attending a NEAR certification course, but already feel lost. Don't worry. This course is a great first step for you. --- ## Learning Objectives ### a novice to Web3 will be able to: - confidently describe the idea of the open web - confidently describe broad blockchain concepts - describe the interface of a contract just by looking at a few lines of code :heart: - identify a view function, call function in any smart contract - confidently reason about a dApp - learn to ask good questions - reduce anxiety about taking a certification course - understand the difference between testnet and mainnet - identify and navigate to core primitives in the NEAR ecosystem - describe why NEAR is carbon neutral and Bitcoin is not - discuss identity, governance, and ownership in Web3 --- ## Course Overview :female-teacher: ---- 1. **You and your Computer** :computer: - _Today computers take many different forms beyond laptops, tablets, and phones. The microchip to track your pet if they get lost? That’s a computer. Your AirPods are actually two computers, but they behave as one. These tiny computers are inside so many things we touch, but what are they? How can we learn to see them clearly?_ --- 2. **You and the Internet** :computer: :telephone_receiver: :computer: - _We often use the internet and web interchangeably, but in fact these are different things. "The internet" refers to the infrastructure - **a network of networks** with rules for communicating, which keeps the web accessible at all times._ - _This may seem minor, but it's an important distinction we need to keep in mind. The **web**, the pages we browse when we're online, is built on top of the internet._ --- 3. **You and Web2.0** :spider_web: - _Once we start talking about browsers and web pages, we are in the domain of the modern web._ - _You've heard of servers, but when we talk about using those servers to access and share information, we can start to see the differences between infrastructure and how it's used - the highway vs. rush hour._ --- 4. **You and Web3.0** :question: :spider_web::question: - _Now that we understand that visiting a web site( Web2.0) is different than the WiFi(Internet) that brought it to your device(computer), we can start to imagine other ways to connect to each other. That's exactly what Web3.0, or Web3, is doing. It's re-imagining the web!_ - _When we talk about the “open web” we are talking about a system in which users have both freedom and transparency. As opposed to the "closed" systems used by certain governments to limit free access to information, the open web is designed to be a cooperative effort among a community of users and builders_ - _Why is Web3 so powerful and important? Because it has the ability to side-step centralized power structures that govern the internet. Web3 is all about open access to information with a level of privacy not attainable previously. Getting around Big Brother is a pretty big deal, isn’t it?_ - _Why is it called Web3? Today, Web3 generally refers to a type of network (of networks) that is still accessed through the existing internet, but with very different rules. Until Web3 fully breaks away from centralization, we can think of it as another type of highway; one where the toll roads pay YOU!_ --- 5. **You and NEAR Protocol** :rocket: - _If Web3 is a decentralized network, then what are the rules of engagement?_ - _It's an exciting time for Web3. By now you've seen dozens of ads that mention cryptocurrency. You may have scratched your head at whatever an NFT is, or perhaps gawked at the idea of pixel art selling for millions of dollars in “imaginary” money with silly names like Dogecoin, Ethereum, or even NEAR._ - _There’s a ton of activity in the Web3 space, but does one actually use it like you use the internet today?_ - _Decentralized networks can pretty much make up their own rules of engagement, so long as the outside world can access the information passing through them._ - _NEAR Protocol is exactly that - it's a system of distributed networks with its own rules, or **protocol**, for communicating._ --- # 1. You and Your Computer --- ## Your Computer is a Machine - It is organized through two types of **interfaces** - what is an interface? - it's how you and hardware and software interact with each other ---- #### _peripheral_ interfaces -- :desktop_computer: - motherboard - hard drive - keyboard - mouse - screen ---- #### _software_ interfaces -- :blue_book: - interface drivers - programs - set of instructions for the computer - operating system - software that enables other software to communicate with hardware - applications - programs desinged for an end user - scripts - set of instructions for another program to use ---- - It has **modularity** :building_construction: - hardware parts can be put together and taken apart - this ability to do that is called **modularity** ---- - It handles **data** in two basic ways :memo: - data in motion :runner: - from keyboard to machine - from mouse to machine - from monitor to your eyes - from speakers to your ears - data at rest :sleeping: - database - structure of how data is stored - hard drive - physical addresses where data is stored as 1s and 0s. --- ## Your Relationship with Your Computer ---- ## Identity :selfie: - Your _User Profile_ is your **identity** on your computer - _Guest Profile_ can't change your password. - but if I have your password, _then_ I have your identity as far as your computer is concerned. ---- ## Time :clock230: - You can set time to whatever you want on your machine, but when two machines with different times talk to each other, we need to agree on what time to use. - What if _your_ computer is set 6 hours ahead of _my_ computer? - How do our computers do things at the "same" time? ---- ## Ownership :key: - You can add / remove the programs you want - You can replace your mouse, your hard drive, and your monitor - You can even toss your computer in a pond (make sure to take it back out though, we don’t want to be polluting ponds). ---- ## Structure :classical_building: - What happens if you do throw your computer in a pond? - Is the data on it gone forever, because it was all **centralized** on your computer and your computer alone? - Or is all or much of the data **distributed** accross one or more _other_ machines, and you only lost a portion of your data? - Or, even better, is the data not only distributed accross multiple machines, but **decentralized** so that each machine has a copy of _all_ your data :crossed_fingers:? --- # 2. You and the Internet --- ## The Internet is a Network (of networks) of Computers :satellite_antenna: - Each computer connects using software called a network **interface** - These computers are meant to help information travel through the network - They are not designed to be used like your personal computer - These computers are referred to as **nodes** to help clarify the distinction ---- - Networks are divided into **modules** or clusters - Similar to how a city is divided into neighborhoods or communities :couple: - some communities are really dense :house_buildings::house_buildings::house_buildings: - other communities are sparsely populated :desert: ---- - Network health relies on how well these different modules communicate - each network has an access point (NAP) - routers are **nodes** that connect to NAPs - these connections need to agree on basic rules called _protocols_ that everyone must follow - network protocols ensure that a connection between any two **nodes** will be available, reliable, and consistent 24 / 7 ---- - The Internet has its own set of rules called Internet Protocols(IP) - Each node connected to the internet must have its own IP address so other nodes can find it. :::info :mailbox_with_mail: When you mail a letter, you must properly address it, add correct postage, and any other rules or protocols set up by your region's mail delivery system or it will be returned. Networking **nodes** isn't all that different ::: ---- - **data** travels through the internet from one node to another until it reaches it's destination IP address. - data in motion :runner: - data is broken down into packets - data reassembles when it reaches its destination - data at rest :sleeping: - service outages :skull_and_crossbones: - nodes go offline - routers fail - congestion :traffic_light: - data packets are cached in the nearest node - networks spin back up, and data packets resume travel - errors often occur when systems shutdown mid-execution --- ## Your Relationship with the Internet ---- ## Identity :selfie: - Your IP Address is your identity - I may not know who you are, but I know where you're calling from ---- ## Time :clock11: - Network Time Protocols (NTP) help networks sync time - one node is cast as the layer 1 source of truth - other nodes that sync with this node become layer 2 nodes - other nodes that sync to layer 2 nodes become layer 3 nodes, etc. - accuracy to 1ms - that's a long time for modern networks - Your internet relies on whatever the network _thinks_ is the correct time. - it assumes the time given it by the network is trustworthy - We need to adjust and re-adjust how our computers measure time - Y2K - Date formatted as YY instead of YYYY - '97...'98...'99...:fearful: - Y2038 - Unix time - counting the seconds since 1970 - Imagine if a system could only count to 2,147,483,648 seconds - and resets to zero each second after that... - we don't need to imagine it. Just wait until 2038 ---- ## Ownership :key: - Who owns the internet? Not you! - Businesses built their own networks and eventually agreed to connect those networks - Network owners can take a node or entire network offline - Your computer's access to the internet is entirely governed by centralized networks - You are at their mercy - You pay for a service, not a right - You have no say in how internet protocols are decided ---- ## Structure :classical_building: - The Internet is **distributed** - It doesn't go down when one node or network goes offline - _your_ internet going down isn't the same as _the_ internet going down - The Internet _used_ to be **decentralized** - One computer connected to another computer, and so on - The Internet quickly became **centralized** - each network has one access point (NAP) - one door to open or close - one point of failure for the entire network - network owners in control - access decided by a small group of people --- # 3. You and Web2.0 --- ## The Internet is _not_ the Web - infrastructure vs information - highway vs rush hour and billboards and bus rides... - network **interfaces** vs web **interfaces** ---- - applications have interfaces too - applications communicate with each other's programming through their interfaces - Application Programming Interface (**API**) - they're a set of rules of engagement - alexa listens to me say "turn off lights" - her microphone receives my sound vibrations - it transduces my command to bytecode her api can register - alexa converts the bytecode of my request to a signal that my smart bulb's API can register. - my smart bulb's server has been listening for any requests to its API all day - it receives a set of instructions and routes the request to a function that blocks current from passing through it, subsequently obeying my request and turning the light off - this networking of objects with tiny servers in our homes is called Internet of Things (IoT) ---- #### The Web is Servers and Clients - servers and clients are computers - servers are the _back_ end of the web - clients are the _front_ end of the web - clients make requests to servers - servers listen and respond to requests from clients - servers talk to other servers on behalf of clients ---- - servers are everywhere - your keyboard sends requests to the input server running on your computer that listens and responds to every key you press - your dog's smart collar is a server - servers just need a port so they can listen and respond to requests - web servers are servers that use a web protocol like http ---- - **organized** and _designed_ for user experience (U/X) - WordPress used to be the convention for web design - each page was a pre-designed template - limited control of layout - all pages looked / behaved the same - **modular** design breaks the page into the tiniest, customizable components or web resources - flexibility in deployment, arrangement, and customization - granular control - web pages grow / shrink responsively to screen size and device type ---- - **data** passes back and forth between your computer and multiple servers - data in motion :runner: - data broken into smaller web packets that travel between client and server(s) - if a packet says it's number 4 in a list of packets, and your computer hasn't seen number 3 yet then your data waits until the other packets arrive before it gets reassembled - data at rest :sleeping: - local storage - data stored in your browser with no expiration - session storage - data cached in your browser until you close the browser window --- ## Your Relationship with Web2.0 ---- ## Identity :selfie: - you are your activity on the web - your browser history - requests coming from your IP address - your activity in and accross other web apps (shared data) - your email is your _main_ source of identity - it relies on a web mail protocols to function - you can use it to log into numerous web apps - password _plus_ information from another device (2FA) required for identity verification - access to your identity is at the mercy of internet service providers and app owners - Twitter can lock you out of your account - your ISO can shut your internet access at any point - new internet plan? no problem - except now your router is no longer compatable, and you'll need to upgrade that before you service is restored :woman-shrugging: ---- ## Time :clock1: - "trusting" what a server somewhere tells us - UCT - time based on the Sun and Earth's rotation - needs mass adoption - impractical that noon UCT would mean noon all around the world - faster connections make syncing time more and more difficult - bad things can and do happen on the web in a blink of an eye ---- ## Ownership :key: - you don't own your data - it's being sold constantly - you don't make a dime from it - cloud admins can delete any data you store on it - your accounts can be taken offline with just a few strokes - Instagram can use any pics you posted any way they want - it only takes a handful of people to completely block your access to any digital assets you "own" ---- ## Structure :classical_building: - The modern web is distributed in a centralized way - distributed networks managed by handful of tech companies - very few points of failure can bring entire regions offline - The modern web is _very_ centralized - 4 big box stores to shop at - monopolies mean that fewer and fewer people hold the keys to the kingdom --- # 4. You and Web3.0 --- - Web3 is the "open" web :open_hands: - the decentralized web - network interfaces - no one node is in charge - no NAP - no one can "turn it off" - it's open to all - owned by the people using it - no middlemen - no brokers between you and the market - no bank fees for managing your money - no HR between you and payroll - network of computers accross the globe act as one computer sharing a single state - we are Borg :robot_face: - when one node registers a change in the network (state) it gossips about it to the other nodes - gossip spreads about the change in state to the entire network - web interfaces - user access points to Web3 - wallet - connect to blockchain through http connections - contract interfaces - interface with user and each other using call functions - contracts that take a lot of time to run can congest the network - transaction fees (GAS) help prevent this - you are incentivised to limit how much attention your contract requires to run ---- - Web3 needs Web2... for now :handshake: - infrastructure is different than Web2, but limited, and can't operate without Web2 yet - you still need the centralized web to access the decentralized web - it's not immediately apparent when you are on a Web3 app (dApp) ---- - Web3 is composed of interconnected layers - these **modules** can be broken apart and reconfigured to create new use cases - protocols - base layer - blockchain architecture - changes to data are stored as transaction recipts on a digital ledger - ledger is copied and distributed to all nodes in the network - infrastructure - interoperable building blocks - specific tasks - storage - naming service - smart contracts serve as the _back_ end of web3 - smart contracts make entries into the ledger - use case layer - where it all comes together - DeFi, Gaming - access points - top layer - users sign into their account and send / receive crypto-currency ---- - data in motion :runner: - state-as-data alerting each node in the network - data copied over and over to every node - updates to data (state changes) create a _new_ entry on the blockchain at a different height - you can see the entire history of the data - data at rest :sleeping: - data stored in a block on the blockchain remains in tact forever - you can view it, but you can't change it - updating date means creating a new copy in a new block - not all data in Web3 is stored on the blockchain - conventional data storage still in heavy use - browser storage - (centralized) database storage --- ## Your Relationship with Web3.0 ---- ## Identity :selfie: - your account that sends and receives funds from your wallet is your identity - no Oauth - your offline identity is yours to reveal or keep hidden - the account(s) you use to explore the space build reputation - reputation / street cred helps build trust in the platform - active engagement in the community is core to a community-run internet ---- ## Time :clock1030: #### the blockchain is a clock :exploding_head: - time is measured in block height - a new block is added to the chain - some protocols need proofs that the data in a new block is valid before adding it to the chain - some simply add new blocks at a certain cadence with many being empty - it contains snap-shots of data after it's state has changed - nodes sync with other nodes to get the current height - transactions (txs) happen constantly - transactions trigger state change - these txs queue and are added in the correct order based on their metadata - if a transaction says it's number 3 in a list and the chain hasn't seen number 2, the transaction stays in a memepool until it's predessor tx is added to the chain. - consensus among the nodes (ie >50%) sets the current block height (time) - sometimes two nodes with different block heights claim to have the most current (highest) chain - ( generally ) longest chain wins - sometimes nodes do not agree with the consensus and continue with their version of the blockchain - if other nodes join them, then a fork is created - two versions now exist - Ethereum vs Ethereum _classic_ - sometimes infrastructure updates require a fork - if a node with the old version of the chain exists, the old infrastructure is still accessible - You can think of it in terms of your computer - when your OS notifies you of an update, you can update your system or continue with your current OS version - eventually, you may experience limitations in what your OS can do - some apps may say they can't work with your old OS version - a computer from 1997 can't "dial into" today's internet like it did when Austin Powers was in the theaters. - trustless proofs provide integrity of the blockchain - proof that a transaction is valid can be achieved through cryptography (i.e. mining) - if anything changes in one block, all subsequent blocks are _immediately_ invalidated - mining or Proof of Work (PoW) has become very energy intensive as their corresponding blockchains grow - other proof concepts are being employed in new and existing blockchain networks to address these flaws ---- ## Ownership :key: - _you_ own your data and _you_ own the network - no. seriously! - everything is flipped on its head - you earn money from simply engaging the network - ad companies pay _you_ to see their ads rather than google - networks have their own economies based on their specific token or **crypto-currency** - Bitcoin, ether, doge, $NEAR - if it's not Bitcoin, then it's an altcoin - tokens in your wallet are yours to do as you wish - if your country freezes bank accounts, your crypto is still safe and accessible - digital assets are yours - whatever digital assets are associated with your account are yours for as long as you desire - there is no repo man - you are your own security ---- ## Structure :classical_building: - Web3 is decentralized - there is no single point of entry or failure - if one node goes offline, the data is preserved on all the other nodes - no _one_ controls the network - everyone controls the network - the wealth that is generated by the network is distributed among the people using it - Web3 relies on Web2 to exist - Web3's infrastructure is decentralized - Web3's access layer relies on Web2 servers - contracts compile to webassembly so they can run in Web2 browsers --- # 5. You and NEAR Protocol :fireworks: --- - Web3 is a network of blockchain networks - not all blockchains are alike - NEAR is a Layer 1 (L1) blockchain - layer 2(L2) blockchains use architecture of existing blockchains - Polygon is built on top of Ethereum, which is a layer 1 blockchain - NEAR is built from the ground up - NEAR is its own chain with its own rules and architecture - Instead of PoW to create trust, NEAR uses Proof of Stake(PoS) - PoS is humans staking a large amount of money that they will be honest about validating transactions - validators can earn historical returns on their staking - it's cheaper to tell the truth than to lie - its CARBON NEUTRAL :earth_americas: :heart: --- - NEAR has the same interfaces as other Web3 networks - protocols - base layer - L1 blockchain - blockchain architecture - nodes split into mini processors (sharding) to improve network availability - PoS validation - localnet for dApp development - testnet for testing dApps - mainnet for launching dApps - infrastructure - nodes are virtual computers you can download locally - when you download a node locally, you can refer to it as a client node since it will be interacting with the network in a similar way that your computer does. - indexer nodes - nodes anyone can run locally to listen to network updates - querying all blocks in the chain can be cumbersome - Indexer makes it easier to search the blockchain - Google indexes web pages so they are easier to find - block nodes - contain copy of the blockchain to increase network availability - validator nodes - nodes used by validators to review transactions - [Wallet](wallet.near.org) - account management - [Explorer](https://explorer.near.org/) - transaction history of any account - [JSON RPC](https://docs.near.org/docs/api/rpc) (Response-Procedure-Call) - API for interacting with the blockchain - use case layer - DeFi - [ref.finance](https://ref.finance) - Gaming - [berry.club](https://berryclub.io/) - Bussiness Development - DAO - [Sputnik](sputnik.fund) - access points - top layer - Wallet - Explorer - JSON RPC ---- - NEAR's infrastructure of **modules** can be broken down and reconfigured for new use cases - create new primitives like message protocols - [Machina](https://medium.com/nearprotocol/introducing-machina-the-worlds-first-proof-of-stake-storage-solution-built-on-near-fed2ed23dbfb) is a PoS decentralized storage solution built on NEAR - dApps can use any number of primitives for their use cases - how would you create AirBnB on NEAR? ---- - data in motion :runner: - data travels accross many different protocols within the network - data fetched from decentralized database like IPFS - transaction data retrieved from JSON RPC and broken down into http packets that are returned to client - data about chain state propagated to entire network like gossip - data at rest :sleeping: - data stored on chain is immutable - data stored in browser local storage - access keys - data stored on local machine - access keys - data temporalily stored in memory while dApp is running - access keys --- ## Your Relationship with NEAR ---- ## Identity :selfie: - your mainnet account (_yourname_.near) allows you to interface with any other account - subaccounts you create (_myname_.yourname.near) can build your reputation - you are paid in $NEAR for your engagement in the network - earn to play - earn to learn - contracts have accounts as well - accounts can have zero or one contract deployed to them - your account associated with your NEAR wallet does not have a contract deployed on it ---- ## Time :clock12: - current block height is accessible to anyone with a computer and an internet connection - new blocks are added every second - some blocks contain zero transactions - transactions _you_ make are queued using **nonces** (tally of transactions a key on _your_ account has made) - tx with nonce 4 isn't added until nonce 3 is added ---- ## Ownership :key: - you have complete control of your account - your wallet works like a keychain - you can create keys for your account - key pairs - private and public, actually - private key is stored on your machine - public key is used to sign transactions - when you sign a transaction the transaction verifies that your hidden private key and your public key are indeed a valid key pair - you can authorize dApps to add _their_ keys to your account - like when you give a valet a special "valet key" to park your car - the valet key has just enough functionality to get the task done - dApps basically do the same thing - they give you a **functional access** key - you can only call certain functions on the dApp's contract with it - you don't have **full access** - **full access** keys allow you complete control over an account - you can de-authorize a dApp on your account - this is like signing in with google - google confirms you are authorizing the app on your google account - you can de-authorize any web apps associated with you google account - you can delete all the keys from your account, and render it inaccessible by anyone (including you!) forever - #### you are your own security :lock_with_ink_pen: - no one can remove assets from your wallet without your permission - if someone gets your private key, however, they have full access to your account - your funds are theirs to control - :warning: **!!!NEVER SHARE YOUR PRIVATE KEYS!!!** :warning: - there are no middlemen in Web3 - no one at NEAR has the ability to "reset your password" - be vigilant! - store your seed phrase outside of any devices connected to the internet - rotate your keys every once in a while - transactions are irreversible - if you send / receive funds no one can reverse the transaction - your transaction history is available to anyone at anytime - hyper-transparency - no privacy on the blockchain - do not store anything you aren't ready to share with the rest of the world - contracts that list you as the owner of a digital asset (ie NFT) can not be edited - only when _you_ send that asset to another account, does the ledger update ---- ## Structure :classical_building: - NEAR is decentralized - NEAR is community based - NEAR doesn't own any nodes on its network - NEAR is part of Web3 and therefore relies on Web2, which is centralized --- ###### tags: `near-and-far-tutorial`