Berlin Ethereum meetup March 2016 recap

I went to the Berlin meetup yesterday and even though I missed the talk by Afri Schoedon about the Ethereum Stackexchange, it was really worthwhile. The second talk was by a represantative of Nexus Development about their tool Dapple which is designed to help build contract networks comprised of many interacting contracts. In particular it is a package mangager and deployment tool for Solidity contracts.

In the last segment of the evening ethereum C++ team lead Christian Reitwiessner was answering questions about the Solidity contract language. For this purpose he showcased the online tool Browser Solidity, which simulates an ethereum blockchain. It is well suited to test out contracts and provides an easy to use interface to interact with contracts.

He explained the Solidity contract language using the royalty contract for Tiny Human, which I have taken an interest in lately, as an example. In the next paragraphs  follow my notes regarding this part of the talk.

The general layout of this contract is as follows: It starts with the definition of several Structs. Structs are custom groups of variables. Here is an example from the contract code. Owner is a structure that has two variables, the address and the name of a person that owns a share in this song (i.e. one of the creators).

struct Owner {
address addr; // Can be linked off-chain to a persona (like "Imogen Heap" or "Guitar Guy Bob")
bytes32 name;
}

After the structs come state variables, that are permanently stored in contract storage. An example is the price of the download.

uint public constant USDDOWNLOADPRICE = 60; //0.6 usd.

After this there are two events defined. As I understand it, events are the hooks that allow other applications to interact with the contract. For instance javascript applications can listen for these events and trigger other actions when they occur. I assume that this is the way the Tiny Human web application notices that a payment has occured and starts the download of the mp3.

event purchasedRight(address indexed payee, bytes32 right);

Then on line 72 of the contract begins the constructor. The constructor is only once executed when the contract is submitted to the ethereum blockchain. In it a bunch of properties are setup, which will be used later. This concludes the constructor.

Directly after the constructor starting on line 142 are the definition of two modifiers. These are used to amend functions, in our case to restrict access to certain functions. Here are the lines from the contract code:

modifier isAdmin() {
if (msg.sender == admin) {
_
}
}

After that follow function definitions. First off the purchase-function is public and thus can be called by everyone. Here and in it`s sub-functions is where the meat of the matter is. “purchase” compares the amount of money that was sent in (denoted with msg.value) with the price of the download. If the money is greater or equal the “addTransaction” (line 167) function will be called. Here the contract will iterate over the owners of the song and issue a payment to each of them. See here:

for (uint i = 0; i < ownersCount; i += 1) {
if (shares[owners[i].name][_right] > 0) {
(owners[i].addr).send(msg.value * shares[owners[i].name][_right] / TOTALSHARES);
}
}

After this step the “purchasedRight” event is triggered, which makes the download start in the accompaning web-application. The last part of the contract contains administrative functions. You will see that they use the modifer isAdmin() or isOracle() in the function definiton, which make sure that they can only called by persons with the correct private key. These functions are used to set the current exchange rate, etc.

After explaining these features of the contract, Christian Reitwiessner also said, that it is possible to inherit from a contract. So it is possible to create another mp3-download-contract by setting up the contract like so:

contract AnotherSong is TinyHuman {..

This makes it possible to reuse much of the code.

Thanks to the ethereum foundation for setting up these meetups! They are a great opportunity to learn and get in touch with the ETH community.

3 Comments

  1. Hi David, thanks for joining the meetup and blogging about your experience. If you don’t mind, you could link the Ethereum Stack Exchange here: http://ethereum.stackexchange.com/ – and on a personal note, my Family name is spelled ‘Schoedon’ 🙂 — Best, Afri

    • david

      March 23, 2016 at 9:14 am

      Hi Afri, sorry for the spelling mistake. I fixed it and added the link to the stackexchange as well. Best, David

  2. Tokyomonogatari

    March 23, 2016 at 9:36 am

    Vielen Dank für die Zusammenfassung!
    Marius

Comments are closed.

© 2018 Propellah

Theme by Anders NorénUp ↑