ETHEREUM CLIENTS JSON-RPC INTERFACE clients offer an API and a set of Remote Procedure Call (RPC) commands Ethereum clients are applications implementing the open-source Ethereum which allows developers to write programs that use an Ethereum client as a gateway specification and communicating over the P2P network with other Ethereum clients. to an Ethereum network and (smart contracts included). The RPC commands are encoded as JavaScript Object Notation (JSON). The API is then There exists a variety of Ethereum-based networks which may or may not referred as the JSON-RPC API. interoperate with each other. Usually, the RPC interface is offered as an HTTP service on localhost port 8545, but it can be done though other communication protocols (IPC, WebSocket). There are many implementations HTTP and WebSocket are particularly handy if a remote node is used. of the Ethereum client protocol, the Native access to the JSON-RPC API can be made by means of a generic command-line most common clients are Geth and Parity. HTTP client (e.g. Curl) by sending the request message to the Ethereum client and receiving the response message from it. Running a client with full node features is not necessary for Ethereum development. Interacting with a remote client, which does not store a local copy of the blockchain nor validate transactions and blocks, but is able to // Request connect to full nodes of existing main, test or private Ethereum-based networks, is curl -X POST -H "Content-Type" : "application/json" --data a valid option for Ethereum development. '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":1}' \ http://localhost:8545 // Response {"id":1, "jsonrpc":"2.0", "result":"Mist/v0.9.3/darwin/go1.4.1"} GIOVANNI MAROTTA - UNIVERSITY OF CATANIA, DMI - AA 2020/21 GIOVANNI MAROTTA - UNIVERSITY OF CATANIA, DMI - AA 2020/21 1 2

WALLETS ETHEREUM NETWORKS Wallets are software applications for desktop, mobile or web-based systems (i.e MetaMask for web, Ethereum-based networks: Jaxx for mobile and desktop). ! mainnets (e.g. Ethereum, ) Wallets manage Externally Owned Accounts (EOAs): ! testnets (e.g. Ropsten, Kovan, Rinkeby) ▪ store private keys ! local private nets (e.g. Ganache, Remix JVM, Truffle Develop) ▪ access account balance ▪ create, sign and broadcast transactions value transactions contract creation transactions contract call transactions to be sent to other accounts ▪ receive value transactions from other EOAs Wallets having remote client features also act as an Ethereum gateway to different Ethereum (full) clients as well as a Web3 Provider with respect to development tools and DApps.

GIOVANNI MAROTTA - UNIVERSITY OF CATANIA, DMI - AA 2020/21 3 GIOVANNI MAROTTA - UNIVERSITY OF CATANIA, DMI - AA 2020/21 4 DECENTRALIZED APPS ECOSYSTEM SMART CONTRACTS

Selected network: mainnet, testnet, local private net Immutable EVM software modules: Access to blockchain and smart contracts: ✓ written in (or other high-level languages) ▪Web3 Provider: i.e Ethereum client (e.g. Geth or Parity node), remote client (e.g. ✓ compiled into EVM for transmission Metamask), cloud-based client (e.g. Infura) ✓ deployed over the network within the Data Payload of a contract creation transaction ▪Wallet applications ✓ translated into EVM low-level code Front-end application: HTML/JS webapp, Node.js webapp, Java ✓ stored in the EVM global state (Storage Trie of the relevant contract account) ▪optional Web3 specialized, high-level libraries ✓ executed by the EVM on call providing function calls corresponding to each available RPC command Decentralized P2P storage platform (e.g Swarm, IPFS) Decentralized P2P messaging protocol (e.g Whisper)

GIOVANNI MAROTTA - UNIVERSITY OF CATANIA, DMI - AA 2020/21 5 GIOVANNI MAROTTA - UNIVERSITY OF CATANIA, DMI - AA 2020/21 6

HTML/JS FRONT-END WEB3.JS Programmatically interfaces smart contracts: ▪stores the user’s front-end HTML/CSS/JS application pages in a web server • Web3.js is a convenience JavaScript library providing a Web3 object that can be used to interact with an Ethereum ▪interacts with a wallet software or includes wallet functionalities to get node via RPC communication transaction signed • ▪connects to any kind of Ethereum client (full, remote, cloud-based) which Web3.js works by exposing methods and objects that have been enabled over RPC thus allowing the exposes the Web3 JSON-RPC API development of user interfaces which hide the JSON- ▪reads from/writes to deployed contracts RPC API encoding via native JSON-RPC commands or by means of Web3.js (Ethers.js) object libraries • Web3.js is also used by development tools such as Truffle and Remix thus allowing contract interaction by means of their internal JavaScript Console

GIOVANNI MAROTTA - UNIVERSITY OF CATANIA, DMI - AA 2020/21 GIOVANNI MAROTTA - UNIVERSITY OF CATANIA, DMI - AA 2020/21 7 8 METAMASK REMIX

▪ MetaMask is a Wallet software which has remote client functionalities ▪ Remix is a Browser IDE which allows the following since it acts as a Web3 Provider with respect to development tools and operations on Ethereum Smart Contracts : apps and as an Ethereum gateway to different network types: ▪ development (either in Solidity or Vyper) • Live: Ethereum • Test: Ropsten, Kovan, Rinkeby ▪ compiling • Localhost 8545: connects to a local node (full or test node) ▪ debugging • Custom RPC: connects to an Ethereum node with a compatible RPC interface ▪ testing ▪ MetaMask works as a and, once installed, it will ask ▪ deployment for a password and show a 12-word phrase useful to retrieve the wallet ▪ calling access (e.g. lost password, account import from a different device) ▪ Remix can connect to deployed Smart Contracts in ▪ MetaMask injects a window.ethereum object into the developer console to let the website interact with the MetaMask functionalities different test or live environments: ▪ JavaScript VM (test environment internal to Remix) ▪ MetaMask additionally provides a window.web3 object as a convenience library (web3.js) for the website to optionallly use it (this library provision ▪ Injected Web3 (live or test environments through MetaMask) will be dropped soon – 1Q2021) ▪ Web3 Provider (live or test environments)

GIOVANNI MAROTTA - UNIVERSITY OF CATANIA, DMI - AA 2020/21 GIOVANNI MAROTTA - UNIVERSITY OF CATANIA, DMI - AA 2020/21 9 10

ENVIRONMENT SETTING #1: REMIX + METAMASK + ROPSTEN

▪ In this setting, Remix interacts with the Ropsten Ethereum test network via an automatic connection to the Injected Web3 environment provided, in our setting, by MetaMask ▪ Ropsten is the most used Ethereum Testnet Network (Net ID 3) and provides easy funding of Test Ethers by means of network-available faucet contracts ▪ Ropsten storage can be explored by means of a dedicated scanner tool (https://ropsten.etherscan.io/) which is able to show transactions, blocks and contracts

GIOVANNI MAROTTA - UNIVERSITY OF CATANIA, DMI - AA 2020/21 11