Skip to content

Instantly share code, notes, and snippets.

@victorevector
Last active September 6, 2017 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorevector/923d57df039160f4ff4d1eb7e17c5799 to your computer and use it in GitHub Desktop.
Save victorevector/923d57df039160f4ff4d1eb7e17c5799 to your computer and use it in GitHub Desktop.
Ethereum explanation for Julian

Hi Julian,

I hope this helps to elucidate the inner workings of Ethereum. I have chosen to focus on 2 concepts: accounts and contracts. This should provie a platform on which to converse and grow our understanding. There are many more terms associated with the blockchain, such as cryptographic economics, tokens, protocols, etc. I'd be happy to discuss with these you if you're keen.

Accounts

First let's cover the concept of accounts. There are 2 types of accounts in ethereum: Contract and Externally Owned (EO) accounts. Both account types have 2 important features:

  1. An address

    1. The means by which accounts are identified on the blockchain. This makes it possible for accounts to communicate with each other.
  2. Public/Private keypair

    1. The means by which account authentication occurs on the blockchain. It validates identity.

Both accounts can send and receive cryptographically signed data packages that store a message. The difference between the 2 is that Contract accounts contain some piece of executable code, the smart contract.

This brings us to the next topic: smart contracts.

Smart Contracts

Every Contract account contains some piece of code that gets executed whenever it receives a message from either another Contract account or Externally Owned account. Let's imagine a restaurant has a reservation system built on ethereum. The blockchain would contain record of table reservations; the Contract account would host the code necessary to "reserve" tables; and the EO would be the person trying to reserve a table. Below is an example of a smart contract defined in the Solidity language.


contract TableReservation {
  
  address[16] public diners;
  
  function reserve(uint tableId) public returns (uint) {
    //verify that tableId's value can be represented as an index in our fixed length array (16)
    require(tableId >= 0 && tableId <= 15);

    //if tableId is valid index position, then assign caller to occupy that position
    diners[tableId] = msg.sender;

    return tableId;
  }

  function getDiners() public returns (address[16]) {
    //getter function
    return diners;
  }
}

contract is a special data type defined in Solidity.

address[16] public diners is an array of ethereum addresses. It's a data type defined in Solidity. In our example, this is the immutable data stored on the blockchain. It holds 16 indices and each index represents a table. The value stored in each index represents a diner's EO account address. e.g. diners[0] = 0xdedc7ae544c3dde74ab5a0b07422c5a51b5240603d31074f5b75c0ebc786bf53 means table 0 is reserved for diner who is identified by the address 0xdedc7ae544c3dde74ab5a0b07422c5a51b5240603d31074f5b75c0ebc786bf53.

function reserve is a function tied to the contract. This one specifically reserves a table. Without getting into specifics, the EO would call this function to reserve a table. This is the essence of a transaction. The EO would send a message to the Contract account, specifying the function to execute and ether to pay for the computational resources. In turn, the function writes to the blockchain. Every transaction yields a transaction id, e.g. 0xdedc7ae544c3dde74ab5a0b07422c5a51b5240603d31074f5b75c0ebc786bf53, which is proof that it happened and you can refer back to this id at any time in the future.

So how does the user interface with the blockchain? Just like a web app! You can build a Dapp with HTML, CSS, and Javascript. There's a JS library called Web3.js that provides your front-end javascript an API with which to interact with the accounts on the network. You'll need to run your webpage/app on a browser that can support interaction with the blockchain (mist or chrome + extension). Specifically, these browsers give you an interface with which to login to your account and spend ether on transactions.

Relevant sources:

https://en.wikipedia.org/wiki/Public-key_cryptography https://en.wikipedia.org/wiki/Remote_procedure_call https://hackernoon.com/bitcoin-ethereum-blockchain-tokens-icos-why-should-anyone-care-890b868cec06 https://blog.0xproject.com/the-difference-between-app-coins-and-protocol-tokens-7281a428348c https://medium.com/@mvmurthy/full-stack-hello-world-voting-ethereum-dapp-tutorial-part-1-40d2d0d807c2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment