Setting up Ethereum Workflows with the Streamr Canvas
ETHCC 3 · March 2020 · 16:06
Jonathan Wolff discusses setting up Ethereum workflows with Streamr Canvas.
Speakers
Topics
From ETHCC 3, hosted by Ethereum France.
Transcript
with streamer and this talk is about setting up aetherium workflows with a streamer canvas which is sort of like a GUI for stream plumbing I'd say and it's useful for automating your aetherium jobs and also for interacting with theorem contracts and sort of managing all automated stream plumbing so streamer is I started as a marketplace to buy and sell data streams and and now it does that we've shifted focus to the two aetherium a few years ago and so all the buying and selling of data streams is handled by cerium contracts and we also have a system for people to pool
their data together for example to sell your location data it's called data unions and be paid an oft channel payment system but it's also a peer-to-peer network for this stream distribution so people can be incentivized to be a node in this network by being paid in data coin and so that ensures reliable stream distribution and it's also this sort of dual GUI toolkit called the streamer canvas and that's what I'll be talking about today so the GUI toolkit has all these different modules for stream plumbing and so for example we have Internet of Things sensors databases and also these modules for interacting with the etherium blockchain and I'm going to be talking about these modules for interacting specifically with the etherium blockchain but there's many
different widgets you can plug in so you can actually use you know you can pump your data into rest through the rest endpoints and also sense there's all different kinds of things and all all of our software is open source so everything that I'm describing right now you can download and run locally and that's an important point that I'll get to later so so the streamer canvas GUI is sort of like a programmatic tool kit I'll give you a little preview of what it looks like so you have these on the left of the screen you have a sort of menu of different widgets you can choose of modules you can choose and in this particular example there's a stream which is a streamer stream so these can
be used as sources and sinks in this case as the data gets pumped into the streamer stream it goes to this visualization this this great graph over here and also this table and so the canvas is you edit it in your web browser but then it lives on a server and then everything excuse on this on our server is and not in your web browser so you setup the plumbing in your web browser press Start and then everything's sort of event-driven and so within this sort of plumbing analogy there's this idea of driving input where the output for a previous module will trigger an action in a downstream module and I'll get more into that later because there's some subtleties about that and then as I said a wide variety
of modules for HTTP and database connectors and also Assyrian modules and everything is event-driven and goes in real-time so it can be used also like a cron it can be used to process streams data as it comes in and it can also be used to kind of schedule jobs with a a clock module that I'll get into later so specifically for etherium transactions we have these four aetherium modules and we have solidity compiled deploy so you can just copy and paste the solidity code press compile and and it'll deploy it on the network of your choice and that will output a contract object and the contract object is then fed into theorem the theorem call module and they
get events module so the etherium call module as the name implies can be used to launch aetherium transactions either view methods or real transactions and the get events module streams events in real time from your contract so you can make listeners for particular events and we also decode your event data which we'll get into a little more later and then there's also this fourth module called get contract at so if you're not deploying a new contract and there's an existing contract you can use this get contract at module two direct without existing contract and one cool thing about that is that it actually fetches
the API from ether scans so you can you can you can paste your own API but if the ABI is already registered neither scan it will just fetch it for you and auto populate and that'll be included in the output which is this contract object so an example of a canvas where we were using these ethereal modules is up here and so in this case I'm doing a simple it's sofa cast octa-core Oracle so that they a guy who publishes data and then then there's a listener and this is the publisher of the data so in this case the salinity compile deploy has some code for a publisher I'll show you the code in a minute but when you have published your contract the contract object becomes
visible and that becomes the input to the etherium call module and then the contract ad book the contract object contains the network address and ABI of this contract and and then once you've selected your functions so it's kind of hard to see in there can you see it on the screen huh the looks very light but the UM you select your aetherium account and your function is a drop down over there and once you've selected your function that all this stuff is actually Auto populated so that makes it very easy to interact with so in this case it looks very light on that screen but I'll show you the code and this is a function that's selected called update price and then these are inputs to the functions
so as soon as you selected your function the function inputs go on the left and then the things on the right are all the events that you've just that you've defined in your contract so in this case there's a stock ticker there's a time stamp and there's a price and in this case I'm using the button as a driving input so each time I would hit the button in a canvas it would it would publish a new stock price but you can also feed your canvas via via rest calls for example you can make your own streamer stream and make that be the input for your your contract - so each module has an options as options in the top right so for the get contract and solidity compiled deploy modules you select the network and the network is
passed down to downstream modules in the in the contract object and also you can select parameters that are relevant to the module so for example solidity compiled deploy you'll have a gas limit for your deploy and you also select a there's a drop down in the module itself to select the account that you and you register your accounts with the streamer GUI so if you want to execute transactions and deploy contracts things like that you have to actually give stream your private key but you can also run streamer locally via docker image and I'll talk about that more later and if you do that then of course you don't have to show you a private key with streamer but the way you would give your private key to streamer was being in
this config option you just copy and paste your your private key in there and then it saved along with your other options so so going back to this sort of demo over here I'll show you the code so when you click on edit code so in the solidity compiled deploy module the one on the top left you click Edit code and this is the code that we have over here so there's an owner and the owner is the only person who can publish data so there's this only home the only transaction you can execute really is the update price module the update price function that only the owner can execute and that will trigger the emission of a price updated event and if you notice
that once once you've deployed your code all these names are actually populated so the inputs on the left and price updated symbol press left at a timestamp all these are populated just from the the source code you've defined over here so um so that the names come from from the parameters to update price function and also the price updated event parameters so so here's what it looks like when you've actually made function calls so you and in this case the but would be triggering the the transactions and when you when you press the button you can go in either scan you'll see the transactions are triggered and then it
decodes the output over here so so these are these are the events that were triggered each time the price was updated you get these decoded events over here and one thing about events is that if you have a parameter that's a that's indexed and it's a variable length parameter like a string only the hash is saved there so the the actual string itself would not be present so in the case of like Press updated symbol I have I'm actually pushing it twice once it's an index event parameter and one is it not most of the non indict event parameter because if I looked at the index parameter I would only have the hash of this and not the actual string contents but this is what the output of the theorem call module looks like and this
this is a table output that just displays what you've just just displays the data so and then in addition to the publisher we can listen to events so as I said the plumbing works on our server you set it up in this GUI you press start and close your web browser and go away and then each time events are triggered you can it will process them in real time so in this case of course to receive events you don't need to private key and and the data is decoded and here's what the get events module looks like so I have get contract at oh well this doesn't look like my screen but it's very faint but on the address over there you you copy and paste your
address and either the ADI would be fetch from either scan or you can supply it yourself the output of that contract goes to get events over here and then this just gets pumped into this table over here so each time an event happens in this case I would I would create the events in another canvas and this canvas would automatically pipe the event data into into this table and so in addition to that you can do all kinds of other processing with the data so you might take some sort of automated action if if you wanted to for example in this sort of contrived toy example the stock ticker you might take anything taken take an action like if the moving average of the stock price drops below a certain level trigger some sort of buy
event and that's what I've Illustrated in the next slide so rather than just dumping the the output to a table you can use this moving average function I'm sorry about the I guess you can kind of see it yeah you see the the the data over here but in this case the the output goes to a moving average they're actually connectors between these it's not it's not being shown on this I see it on my screen but not on here it's kind of faint but they're connectors between these these different modules between all the different inputs and outputs and so the output from the gate events module goes to a moving average and in this case it's filtering to see if the stock ticker is strm are the fictitious streamer stock ticker and then it's seeing if the moving average
is less than some certain amount and then if it is then it would automate it would execute this aetherium transaction automatically so in this case the listener would be taking some sort of automated action and yeah so one so the shimmer canvas was initially created for the purpose of sort of making a GUI for stream creation but you can also use your streams as inputs and outputs for your own personal uses so for example if you wanted to push your data via a REST API you could create a stream and then you could use the stream as an input to your function to do your ethereal modules and then you just do a curl
command and then that would be sent to whatever ethereal modules you are and then that would trigger whatever automation you have there so the streams you can always buy and sell streams on this marketplace you can package your streams for selling and get paid and data coin but the streams are also useful as sort of in an input and output entry points for for your own canvases and the canvases need not be for stream creation on the streamer marketplace you might use them for your own purposes for example for processing event data from some sort of aetherium contract so it's sort of a general all-purpose canvas for foot for event based stream plumbing and then one other thing about driving inputs so on the
with the connectors when you hover over a connector there's a little button that says di driving input and and that determines whether the the output would trigger the the downstream module or not so for example in the in the in this in this example I have the clock module connected to generate a timestamp so in this case I'm using the clock module not on the driving input but just to give it to get the current time but you can also use the clock module sort of like a cron if if I hover over the timestamp connector and I connect driving input on then each time the clock ticks which in this case is like every five seconds the rate says five seconds but it's too faint to see here
but it this thing takes every every five seconds if you had that as a driving input that in that case the model book would be triggered every five seconds so you can use it to to set up jobs much like a cron and then yeah and then finally you could run the entire stream or platform and docker this is the address it's github streamer comm streamer docker dev and there's a docker compose file that launches all the streamer components so if you don't want to give your private key to stream or understandably you can run it locally and then use this whole canvas to automate your own jobs
the only maybe downside or you lose with that is that you can't buy a install you can't sell your stream then on the streamer marketplace so if you want to make streams that are being sold in the supermarket place you need to go to streamer Network but otherwise all the other functionality and all the automation works just in docker so and that's that's all I prepared for today so this is my contact info jonathan wolf it's streamer and i have five minutes left for Q&A if people have questions um I'm sorry the display didn't show the connectors properly it seemed very faint but it's different when isolating half of my laptop I can actually open my web browser and maybe show you a live
streamer canvas if you're interested other any questions no deafening silence okay yeah thank you thank you [Applause] you