Tip:
Highlight text to annotate it
X
(clicking gears)
- Coming up we have part two in our
series on blockchain.
We're gonna show you how you can use the app
environment in Azure Blockchain Workbench
to generate an application that uses
your blockchain of choice to drive greater
accountability into just about any
multi-party process like a supply chain and more.
We're gonna explore how you can build
a Smart Contract and bring that into the Workbench,
how you can have IoT devices send data to your apps,
and how you can even query and visualize events
that are happening in the blockchain.
(upbeat music)
We're joined today by Marc Mercuri
from the Azure Blockchain Team, welcome.
- Great to be on the show.
- So in part one we took a step back really
and explained the core concepts of how
blockchain and Smart Contracts work.
Now, if you didn't catch that one,
or you're new to the blockchain topic,
you're gonna want to check out that show.
If you have watched our first show on blockchain
or are already familiar with the core concepts
and want to start building blockchain based apps
to drive more accountability into your business processes,
you're in the right place 'cause we're gonna go
deep on the topic.
Marc, on the last show we really provisioned out
a blockchain Workbench, we set up our infrastructure,
we chose Ethereum in that case
as the blockchain ledger.
Now we're at the point where we can start
building out our Smart Contract.
- Yes, that's right.
All the scaffolding infrastructure
to generate an application for us is set up
so we're free to focus on the Smart Contract
that defines the scenario we're gonna demo today.
- Right, and so we're picking up from our real world
ice cream example here where basically we had
a couple of parties that were involved
and they were building Smart Contracts
for them to make sure that we ensure
their process is happening the way we want it to.
We have the dairy farmer and the ice cream manufacturer,
the shipper, all these parties are interested
in ensuring that we have a robust system
of accountability to ensure that our ice cream
goes from the farm to the shipper to the
store at the agreed upon temperature.
And that we wanna make sure that also our blockchain
record is verifying the progress
against each milestone in our supply chain
along the way against the terms and conditions
that we're gonna set up in our Smart Contract.
- That's right, let's start by opening up Visual Studio
and take a look at our Smart Contract
that represents the scenario.
Right, so we're in Visual Studio
and whether you're writing Smart Contracts
in Solidity for the Ethereum blockchain,
Java for Corda or Go for Hyperledger Fabric,
Visual Studio code has plug-ins for all these languages.
Today I'm using the plug-in by Juan Blanco for
Solidity for the Ethereum network.
So I've already started to define my Smart Contract.
And you can see here we've got our roles.
So these are the initiating counterparty, the device
itself, as well as the owner, we'll see those
a little bit later.
We also have the properties.
These are the things that we care about,
like the minimum and maximum temperature and humidity,
and whether the contract is in and out of compliance.
And we also, if we scroll up here, we're gonna see
our states, and so the states represents the status
of the contract at any given time.
So we can see whether it's been created,
if it's in transit, if it's been completed,
or also if it's been out of compliance.
You'll notice as we look through this bottom piece here,
we're looking at the logic of the contract,
these different functions that are there,
it looks very much like C# or Java syntax.
Solidity is based on JavaScript.
I want to show you one piece of logic that's
executed within the contract.
This is called Ingest Telemetry.
So here we collect the humidity, the temperature,
and the timestamp, and then the logic will evaluate
if that's outside of the bounds of what we had set up
when we created an instance of the Smart Contracts.
When we create this, and we'll see this in just a minute,
we'll specify what those minimums and maximums are.
- Okay, so you have some things like the roles,
states, properties, some of the logic here,
but you haven't actually defined the business process
itself, how do we do that?
- That's right.
What we really looked at here is our properties
and functions and states, but we haven't talked about
how they all come together in a business process.
So here we've got another file called App.js,
which does that, and also gives some cues to the
app generator to define what the user experience
will look like, and so here, we can see we've got states.
And in the created state, which you saw just a moment ago
in the code, we can see that the role that's allowed
for this is the device, and we see a function called
Ingest Telemetry, that one we just looked at.
So you can see here that only that device can call it
within this state.
- Right, so this is really good in terms of being able to
codify the things that are going to happen during
our contract or in the flow with the ice cream
retail example, so what we've effectively done here
is set out what's important for us and what we want to
monitor and take control of in our Smart Contract,
and the processes and things that we care about.
- That's right.
And so let's go ahead and go back to our Workbench.
So we're here in the Workbench, which is empty.
But before we get started here, let's go ahead
and make sure our users are assigned
in Azure Active Directory.
So here I am in the Azure portal, looking at
Azure Active Directory, and it's one that I set up
specifically for the consortium, because blockchain
is inherently a multi-party scenario.
And you can see some of the participants we just
talked about, so I'm gonna have an observer,
later on we'll see that as Inspector Brad.
And we even have our device that's represented here.
The great things about Azure Active Directory
is because if we look at blockchain,
it's multi-party inherently, it allows us to invite
guest users, so I could invite you from your Microsoft
account or someone else from their Contoso account,
and that way the policies that were set up for things
like multifactor authentication will flow through
into the consortium, which is great for how
we're getting this set up.
Now the other thing that you also see a little bit later on
is that these identities we're setting up here
will also be mapped to the identities you create
for the blockchain.
And so there are a number of benefits here,
and one of the ones that I'm most happy about
is the fact that I don't need to remember my
21 character Ethereum address.
I can just look at you as Jeremy and me as Marc
inside the app.
We'll see that in just a couple of minutes.
- Okay, so we've covered now the directory services,
we've got our Smart Contract kind of ready to go.
Why don't we jump back to the Workbench
and get everything loaded?
- Sounds great, so the process by which you do that
is you come in here, and you would go ahead to
upload your contract.
And you go ahead and specify the two files that
we just mentioned.
If you've got more than one contract, you can use
a zip file to go ahead and send those up,
and that would go ahead and generate an app.
Now what we're going to go ahead and do today
is because we'd also have to assign all those
other users, is for the sake of time,
we're gonna go ahead and use an existing one
that we have, and I'll show you how
that user assignment works.
So here is the assignment for me.
And you can see here that I can go ahead and specify a user
that's assigned to the contract that we just talked about.
And then a role here.
And my role's gonna be the initiating counterparty.
So what we're gonna do now is, you see this icon
on the homepage?
I can go ahead and click here.
I see a list of all the contracts that I've been
engaged in so far.
I also have the ability to create a new contract,
so let's do that.
And by the way, just as in business, not everyone
has the right to create a new contract.
So this is based on the role that I'm in.
Remember we talked about roles in the app.js file.
And now we're gonna go ahead and select our device,
and that represents this device here.
We're gonna select an owner.
Let's go ahead and just say that's
someone called manufacturer.
Our friend Inspector Brad is gonna be an observer.
And then this is where we're gonna set those ranges
that'll be used by the logic we looked at earlier.
And we're looking at both humidity as well as temperature.
We're gonna go ahead and click submit.
And what that's going to do is call our contract,
and create a new instance and pass those values in,
and we should see it as soon as it comes back
from the blockchain in just a moment.
- So now our conditions to stipulate the temperature
on the ice cream truck and what it must be kept at
have been specified here.
Getting back to our Raspberry Pi device that we see here
on the desk, we saw that you provisioned the contract
effectively to ingest telemetry through the function
that we saw earlier.
But is there anything else I need to do to wire up
these different devices through IoT?
- There are, there are actually two other parts
where we've integrated with Workbench.
So the device in our case is running code that will
collect and transmit data to Azure's IoT hub service.
And we have set up a route here to filter those
temperature values which fall outside of
our acceptable ranges that we just specified.
And so what this does is, we call partitioning the signal.
And so that way we don't send all the sensor readings,
'cause there could be thousands of sensor readings
coming out, to the Smart Contract, only the ones
that fall outside of the range that we care about.
And so the great thing about routes is not only can I use
that to help route those to the blockchain,
but we can also make sure that if we want to do analytics
across all the sensor readings that come in,
we can go ahead and send all those to a secondary
off-chain data store.
What happens next is the route delivers the data
to Azure Service Bus, but because this is sending
the raw data from the device, we need to transfer
that raw data into something that the Workbench expects.
And here, we're using a great capability in the Azure
platform called Logic Apps.
And so what happens is the Logic Apps will listen
for this coming into the system.
It will go ahead and get a trigger, it's gonna parse
the .json that comes through, it's gonna go ahead
and find the appropriate contract instance that
that device has been associated with.
It's gonna translate that and parse the .json,
and then we'll send it on to the same service bus
that we used from the API, that was used
in the web application.
So whether it's web application or the device,
they're sending the messages in, ultimately
through the same approach.
- How do I go about in terms of outputting the information
and getting real-time notifications if maybe some
of the contract terms have been violated during the
journey of the product?
- Yeah, great question.
And the reality is not everyone's gonna be
sitting looking at the web app to see if something
goes out of compliance.
We want to make sure we can reach them wherever they are,
especially if it could introduce a food safety issue.
And so here we do a Logic App.
Again, it's listening.
And so we're listening to an event grid
that's gonna go ahead and emit these events
that are coming off of the blockchain.
And so we're gonna see if it's from an Ingest Telemetry
action that has identified that has gone out of compliance,
we're gonna go ahead and make sure that we trigger an alert.
So we have a Logic App that's checking different pieces
of information that comes in, and then within Logic Apps,
they have a number of different connectors that you
can go ahead and plug in here, so we've got Office 365
sending an email, we have a partner named Twilio
that has an SMS interface, and we also have another one
down here which is an Azure function that wraps
another type of modality which is voice, which is great,
and we'll see that in just a little bit.
- And one of the great things with Logic Apps is
a lot of those different providers are precoded
and you can also use custom code, as we saw here
in Marc's example.
But now we've got all the systems in place,
the Smart Contract are active, can we see all
of this in action?
- You bet, so we have our Raspberry Pi here.
We also have our thunderboard, which is collecting
our temperature information, and will be reporting that up
to our IoT hub.
- So what do you need to do to actually get this
working and test it out?
- So let's shift over here.
You can see that I have both the web app that you
saw earlier, as well as the Xamarin application,
it's one of the examples that the Xamarin folks have
put together for us, running on an Android device.
On the right hand side, I'm logged in as a company
called Shady Shippers, and on the left hand side,
I'm logged in as me.
And so you can see that there's this contract
that's been created, but it isn't reflected over here.
And the reason why is because I haven't associated
Shady Shippers with that.
So what I'm going to do is go ahead and transfer
responsibility, one of the actions that we saw
in the Smart Contract earlier.
And now I'm gonna go ahead and assign that to
this company called Shady Shipping.
I'm gonna click submit.
Now these are both on the blockchain.
That is just submitting a transaction to the blockchain,
but because both parties are connected to that,
we'll see in just a moment, that we can see just now,
it's showing in transit on the right hand side,
in transit over here.
So now we've got this one blockchain, a common source
of truth running on the blockchain across both
the organizations in real time.
- Very cool.
So another benefit of blockchain, they're both in sync.
Everything's ready to go.
I want to simulate the actual truck losing power
or the refrigeration unit losing power.
And here we actually have our temperature sensor,
our IoT device.
It's actually sending bluetooth signals
onto our Raspberry Pi.
And I've got the perfect device here to raise
its temperature, so we're gonna go ahead and
hit that with some heat.
(dryer revs)
There we go, that should do it.
I'll put this down, let's see if that...
(alert beeps)
Wow, that was quick.
- That was pretty darned quick.
(phone rings)
Let's go ahead and answer that call.
On speaker.
- [Computerized Voice] Potential food safety issue that
needs your attention.
You are receiving this message to alert you to an issue
with a shipment being handled by Shady Shippers.
Your shipment of ice cream is likely melting
and no longer in a sellable condition.
- Okay, so it sounds like they've detected
something is afoul here in terms of our shipping.
- [Computerized Voice] To have the shipper return the
product, please press one.
To have the shipper destroy the product, please press two.
(button beeps)
To override...
We have recorded your response of two and will communicate
it to the shipper.
Thank you and have a nice day.
- Very cool, even the touch tone phone in that case
working to be able to respond directly with the phone.
And that could be a mobile phone or even
a land line doing that.
- That's right, and you also saw that a text alert
just came through on here as well, so we really
had three different modalities.
I got a text, a message and an email.
And both parties are notified of the update
at the same time.
And so that is gonna allow me to be able to respond
and have insight to take the appropriate action.
So that phone call may have seemed a little bit
over the top, but it delivers benefits in a number
of places, from accessibility or to places like
emerging markets where smart phones really don't have
a large penetration right now to be able to make
calls over feature phones as well.
So now the ice cream company can see this
and all the parties have been notified,
including the next party in the chain,
so they can take action.
And there it's committed to the chain,
immutable evidence that the Smart Contract terms
were violated by the shipper, and I can take action
before it even gets delivered.
- So you mentioned earlier
that the data's actually flowing in,
can be pushed into an off-chain database,
making it easier to query and visualize the events that
are actually happening inside the blockchain
and actually outside the blockchain.
Can we see how that would work?
- Sure, the Workbench captures all the transactional data
and places it in a SQL DB.
You don't need deep blockchain expertise to query
what's going on on your blockchain.
You're now querying a standard SQL database using
the people and the skills you already have in-house,
and you can now quickly visualize what's happening
if you want to in Power BI.
I hear we've connected the database to Power BI,
and if I'd looked at this before I decided to sign up
Shady Shippers to pick up my package, I would have
noticed a disturbing trend that the majority of
their deliveries are out of compliance.
They really are shady shippers.
- Yes, perfect name for that company.
So, Marc, how else can people get started with their
own blockchain apps?
- Well, the best way to learn more is to try
Azure Blockchain Workbench for yourself.
So start small and see how you go.
We have hands-on labs that give you controlled
sandbox environment to experiment with,
and this is a broad topic, and we've only
just scratched the surface, but you can engage
with us further with specific questions
in the Microsoft Tech Community.
- So great recommendations.
Of course, keep watching Microsoft Mechanics
to learn more about how to harness blockchain
with future updates.
That's all the time we have for today's show.
We'll see you next time and thanks for watching.
(upbeat music)