Skip to content

Instantly share code, notes, and snippets.

@brh55
Last active June 15, 2017 14:17
Show Gist options
  • Save brh55/be319187dfe3fccc3dbe0149d7653b4c to your computer and use it in GitHub Desktop.
Save brh55/be319187dfe3fccc3dbe0149d7653b4c to your computer and use it in GitHub Desktop.
Solidity Notes

Solidity Notes

Notes I've assembled for myself during my journey of learning Solidity, some notes maybe incorrect as they are my own interpretation

Event Listeners

Allow clients to keep track of things. IE: Sent transactions, End of transactions, etc.

Declaring Event

event EventName(...args)

Declare an event within a contract to be used.

{
  ...
  event Sent(address from, address to, uint amount);
  ...
}

Emitting Event

EventName(...parameters)

Emit the event to notify observers.

{
  ...
  function send() {
    Sent(msg.sender, reciever, amount);
  }
}

Watching Event

Register listeners to the event.

Constructor.EventName().Watch(param, param2, callback)

IE: Coin.Sent().watch({}, '', function(err, result)

Watch(param1, param2, callback)

Callback(err, result). Result contains property args which is a object containing the keys defined as the parameters in the declaration.

Hash Maps

A complex data type that can map values to a datatype

Type: mapping

  • Virtually initialized
  • Every possible key exists, but not possible to obtain a list of all keys of a map, or list it's values
  • Mapped to a explicit null value?

Usage

mapping(variable => type) [public] mapName

IE: mapping(addresses => uint) public balances

Blockchain Stuff

Accept it like a blackhole

Transactions

  • Globally shared, and readable by anyone participating in the network
  • Create "transactions" to change the database - not done or not completely aplied
  • Once performed, nothing else can alter it
  • Always cryptographally signed by creator

Blocks

  • Time is linear, and blocked together ('chained together') -- 17s in Ethereum
  • "Double-spend attack" - Transactions occuring in the network that both want to empty an account like a merge conflict.
    • ✨ Don't worry because transactions are bundled into a block, and the second one will be rejected and not part of the block.
  • order selection mechanism = Mining
  • blocks with greater / longer chains are less likely to be reverted, and removed from the blockchain.
    • ⏱ is your friend

Ethereum Virtual Machine

  • Completely ISOLATED access to network, filesystem, or other processes
  • Sandbox
  • Contracts are limited to one and another

Accounts

  • External accounts - public-private key pairs (human accounts)
  • Contract accounts - controlled by code stored together with account
    • Addresses are from creator address and # of transactions
  • All accounts have a key-value store mapping storage: 256-bit words to 256-bit words
  • All have Ether (in Wei) and are modified by sending transactions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment