►
Description
During this workshop, we will demonstrate how smart contracts work on the CasperLabs Blockchain.
To attend the next workshop, visit: https://bit.ly/2TQnXfM
Follow Us: https://twitter.com/meetCasperLabs
General Discussion: https://t.me/CasperLabs
Technical Discussion: https://discordapp.com/invite/Q38s3Vh
A
So,
and
so
what
do
you
want
to
build?
Is
a
web
assembly
file
with
that
gonna
make
specific
calls
to
the
host
environment?
So
when
you
execute
web
assembly
program
inside
the
web
web
assembly
environment,
you
have
this
host
functions
that
we
provided
so
every
time.
At
any
point,
for
example,
you
can
query,
save
to
the
memory
or
read
this
value
or
call
another
contract,
etc,
etc.
We
have
a
quite
a
few
few
functions
that
plays
together
really
nicely
and
that
creates
the
smart
contract
library.
A
A
A
A
A
A
Rusts,
a
crate
crate
is
in
in
Reverse,
terminology
is
a
package
and
it
has
a
defined
cargo
to
Tom.
That
is
the
main
specification
for
the
file
for
the
project
and,
let's
see
what
we
have
here,
it's
created
for
us,
it
put
me
as
an
author
and
it
added
the
dependencies
for
the
Casper
contract
and
Casper
labs
types.
These
are
two
packages
that
you
want
to
use
that
we
provide,
so
you
can
use
our
type
type
system
that
website
and
contracts
are
the
definitions
of
the
host
functions.
A
Build
comments
builds
with
the
package
and
release
tells
it
to
optimize
and
it's
actually
necessary
for
the
wise
man
producer.
So
we
have
this
in
the
car
go
to
chain,
we
have
target,
we
call
was
wasn't
target
and
if
you
want
to
work
with
this,
you
also
need
to
pass
a
release.
So
the
compiler
is
doing
a
lot
of
good
optimizations
for
you.
So
the
wesson
package
is
much
much
smaller.
A
First,
we're
going
to
compile
it
and
and
I'll
show
you
how
to
run
tests.
So
so
we
have
this
thing
that
this
is
like
simple
to
start
with,
and
after
that
I'll
go
into
the
code
and
explain
the
line
line
by
line
what's
happening
all
right,
so
this
is
compiled
and
to
prove
you
that
I
can't
show
you
target,
and
here
this
contract
awesome-
and
this
is
the
contract,
the
template
contract
that
is
defined
in
the
source.
A
The
function
can
be
annotated
in
Casper
labs
in
rust.
We
have
there
is
this
annotation,
that's
called
no
mangle
and
we
need
to.
We
need
to
put
it
here,
because
when
you
compile
a
rest,
Watson
package
rust
will
mom
mangle
or
rename
the
function
names
according
to
its
own
specification.
Sometimes
it's
better
to
the
name
things,
and
so,
if
we
put
no,
we
will
keep
the
call
function
named
call
and
thanks
to
that,
when
we
start
the
package,
there
is
running
this
program
inside
the
virtual
machine.
A
A
A
A
That's
the
purpose
of
this
smart
contract
so
good
to
check
it
before
the
next
thing
is.
We
were
telling
that
this
is
not
the
main
element,
because
rust
great
also
can
have
a
Mane
like
you
have
in
Java,
so
we're
telling
now.
This
is
not
the
main.
There
is
no
main
function
here.
You
cannot
call
it
like
this.
This
is
just
a
normal
file
and
we
start
importing
libraries.
A
A
The
storage
package
allows
you
to
interact
with
the
memory,
and
in
this
case
this
will
be
the
memory
of
the
account
and
also
we
have
this
nice
helper.
That's
called
unwrap
or
revert
so
wherever
we
have
an
option
or
result
that
can
have
a
for
example,
option
can
have
can
have
a
value
or
can
have
unknown
value,
and
if
this
is
and
Nani,
if
you
and
if
you
call
unwrap
or
revert
it's
gonna
output,
this
error
and
stop
the
execution
of
the
contract
and
result
it
with
with
an
error.
A
First,
you
unwrap
it
from
the
option,
that's
because
if
there
is
no
argument
at
at
zero,
so
this
is
like
give
me
a
like
a
pierced
argument:
if
there
is
no
you'll
get
em
none
and
if
it's
a
nun,
this
value
will
return
missing
argument
and
if
you
actually,
if
you
have
this
so
it's
gonna,
be
a
type
of
result
and
again
result
can
be
unwrapped
to
the
value
and
the
value
or
to
the
type,
and
the
type
here
is
a
string.
So
what
the
ref
will
do
for
you.
We
try
to
convert
the
value.
A
It's
passed
as
a
list
of
bytes
and
if
it's
valid
string,
then
it's
gonna
unwrap
it
as
a
string
and
if
it's
not
a
valid
string,
we're
gonna
throw
an
error
called
invalid
argument,
so
you
cannot
pass
your
something
like
an
int.
This
is
this
is
the
check
here?
Okay,
so
now
we
have
a
drink
like
value
and.
A
A
A
A
So
what
you're
going
to
do
is
because
this
is
a
this-
is
already
a
reference.
This
is
not
a
pointer
to
the
value.
The
actual
value
first
I
need
to
convert
it
into
the
type
we
call
it
key,
and
then
you
can
put
this
key
under
a
name-
and
this
is
the
this
third
line
here
and
it's
gonna
use
run
time
put
key
here.
We
have
name
then,
and
the
name
is
a
string.
A
That's
called
special
value
and
we
put
value
our
our
reference
as
a
value,
and
at
this
stage
this
function
ends
the
call
function
ends
and
the
host.
You
can
communicate
that
this
happened
successfully,
so
it
it's
going
to
apply
every
changes
to
the
global
state
of
the
blockchain,
and
this
way
the
account
will
have
a
new
entry
in
its
key
value:
storage.
A
So,
for
example,
when
you
run
a
release,
compilation
or
build
release
or
build
a
bug,
then
the
system
will
use
dependencies
and
when
you
run,
tests
system
will
add
also
dev
dependencies.
It's
a
good
practice,
and
so
you
don't
have
to
include
all
the
testing
requirements
dependencies
into
the
end
product.
A
How
the
tests
run
is
the
kradin
anyway,
so
when
you
run
the
tests,
you
have
this
ability
to
start
your
own
private
virtual
machine
that
we
call
execute
execution
engine,
and
this
virtual
machine
for
the
was
was
smart
contract
and
you
can
execute
your
smart
contract
against
this
machine
and
check
the
results,
see
how
global
state
of
the
blockchain
changed.
I
can
do
the
all
sorts
of
manipulation,
that's
gonna!
Let
you
test
it
okay,
and
so,
if
you
may
be
familiar
with
et
reom,
are
we
Tyrion?
Does
it
and
then
in
solidity?
A
You
have
to
spin
up
this
separate
virtual
machine.
That's
running
on
this
on
the
other
thread
and
it's
gonna
be
they're
behaving
a
lot
like
a
nodes,
real-time
node,
and
when
you
run
tests
you
actually
run
against
this.
So,
for
example,
you
cannot
run
concurrent
tests,
at
least
not
in
the
easy
way
you
would
have
to
design
it
really
well
to
be
able
to
test
concurrency,
but
that
shouldn't
be
done.
Even
so.
Here
we
have
a
nice
advantage.
I'd
also
think
is
that
it
runs
a
bit
faster
like
much
faster.
A
A
A
So
when
you
run
tests,
the
cargo
will
start
any
test
that
is
unnoted
as
a
test.
So
it's
here-
and
this
says-
include
this
module.
That's
called
test
only
when
you
run
tests,
so
here
we
are,
and
now
we
have
the
test
definition.
Of
course,
this
is
just
a
sample
in
your
large
project.
You
can
structure
it.
However,
you
want,
and
the
virtual
machine
that
I
told
you
about
is
very
modular,
think
you
can
even
include
it
in
the
already
created
large
applications.
If
you
just
want
to
test
integration
with
smart
contracts,.
A
A
U5
one
two
because
I'll
need
to
start
the
account
and
actually
I'll
need
to
create
some
account
and
give
a
number
of
tokens
of
clx
tokens
or
platform
tokens
for
the
gas,
and
we
have
a
few
elements
of
the
engine
test.
Part
that
are
explained
line
by
line.
We
start
with
creating
a
new
account
new
public
key
that
we're
gonna
use
as
a
deployer.
A
It's
another
nice
thing
in
our
software
is
that
the
verification
of
the
signatures
is
done
level
up.
So,
on
the
what
we
call
the
note
layer,
which
is
the
transport
layer,
the
communication
and
the
consensus
layer,
and
only
if
this
layer
allows
someone
to
execute
this
much
contract
it
will.
This
mark
on
track
will
execute
with
all
the
elements
like
who
actually
execute
this
contract,
and
so
this
layer
doesn't
have
to
manage
the
private
public
keeper,
but
I
can
only
just
specify
the
public
key
without
doing
any
cryptography.
A
So
that's
what
I
do-
and
this
is
a
constructor.
That's
gonna,
create
me
a
public
key
of
list,
32
bytes
and
each
byte
is
a
value
of
seven
and
then
I'm
gonna
check
the
key.
What
is
the
key,
I
will
read,
the
key
from
the
the
environment
and
I
will
assert
it
with
the
expected
value.
Okay.
So,
as
I
said,
when
I
run
the
test,
this
function
will
start,
because
this
is
an
actual
test
and
this
will
start
with
creating
a
context.
A
A
Later
I
need
to
prepare
the
derrick,
the
request
and
I
do
it
by
my
first
referring
to
the
contract
we
with
the
we
built
I
shall
have
to
build
previously
and
that's
in
the
target
contract.
It
wasn't
it's
going
to
be
copied
to
the
local
folder
inside
the
test
grade,
but
that
just
but
this
is
the
same
yeah.
We
call
it
session
code,
then
I,
specify
and
arguments.
The
arguments
has
to
be
a
topple
and,
in
the
rest,
to
define
a
couple
of
one
element.
A
You
have
to
add
comma
after
the
first
element,
so
it's
not
just
a
value
because
the
rest
would
strip
out
and
break
it.
So
I
have
the
arguments
and
now
I'm
building
the
call
color
object.
The
color
object
starts
with
the
code,
so
this
executes
contract
tourism.
With
those
arguments
now
we
have
to
say
who's
who's,
the
executor
and
which
is
my
account
and
who's
authorizing
this
execution.
A
And
after
that,
we
call
built
to
create
an
object
that
can
be
executed
against
the
context.
I'll
tell
a
bit
about
what
doesn't
mean
that
we
had
authorization
keys
in,
for
example,
in
aetherium
or
in
Bitcoin,
when
you
execute
your
execute,
always
in
the
context
of
the
account
that
the
private
keys
associated
to
in
Casper
labs,
if
you
set
it
up
correctly
previous
before
you
can
pass
your
you
can
pass
the
grant,
no
currency,
the
permission
to
execute
the
code
to
some
other
public
public
key
that
has
different
private
key.
A
So
if
I
would
pass
all
of
my
requirements,
all
of
my
permissions
to
another
I
could
earlier
I
could
put
another
account
here
or
maybe
to
two,
because
sometimes
we
have
this
multi
stock
built-in
feature.
So
you
can
pass
a
bit
of
permissions
to
one
account
and
to
other,
and
only
if
those
two
come
together
and
both
sign
it,
then
you
can
deploy
it.
A
So
that's
that's
why
we
have
those
two
two
lines
and
after
we
have
it,
we
use
context,
dot,
run
and
that's
going
to
execute
it,
and
it
will
return
the
context
back.
So
having
that
we
can
also
do
the
query
function
and
this
query
will.
This
is
the
search
that
we
we
have
to
actually
see
what's
happening
on
the
block
side.
First,
we
specify
the
space
of
where
we're
looking
at
so
I'm
I'm,
putting
here
my
account,
which
is
the
account
that
we
execute
as
a
account
as
we
executed
before
so
now.
A
A
The
result
so
here
I
have
the
value
because,
for
example,
if
the
contract,
if
something
would
go
wrong
with
the
contract
like
it
would
did
it
wouldn't
save
it
or
this
account
wouldn't
exist.
I
would
get
an
error,
but
I
expect
this
to
be
a
value
so
and
wrap
it
here
and
then
I
build
expected
value,
so
I'll
be
expecting.
A
A
value
type
actually
so
I
need
to
build
it
from
strings,
so
we
have
fur
this
value
from
T,
which
means
from
type
so
we
can
put
like
in
here
also
generate
function.
We
put
a
string
and
at
the
end
we
do
the
assertion
and
that
Y
that's
how
we
prove
it
and,
as
you
see
running
one
test,
that
was
okay,
so
maybe
let's,
let's
do
some
changes.
Let's.
A
Okay-
and
this
is
the
error
message
and
so
I
changed,
expected
value
to
be
a
string
AAA
and
actually
what
I
was
getting
his
hello
world
and
I'm
getting
the
error
that
these
are
not
the
same,
and
here
we
are
comparing
key
values.
So
that's
a
bit
interesting
how
we
actually,
how
our
type
system
works.