►
Description
During this workshop, we will demonstrate CasperLabs' Payments code Contract implementation.
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
B
A
My
job
is
to
write
smart
contracts
to
and
to
make
guidelines
to
their
team
on
where
to
change
things,
how
to
improve
it.
So
if
you
have
any
feedback
after
the
session
or
after
your
work,
I'm
more
than
happy
to
listen
and
to
work
together
on
your
use
cases.
A
A
Okay,
so
we
will
start
from
the
beginning
I'll
I'll
spend
like
a
few
minutes
to
describe
what
is
the
payment
model
and
how
it
works,
and
then
I'll
show
you
some
code
that
and
we're
gonna
maybe
do
some
cutting.
Today
I
have
a
prepared
repository
with
the
code.
C
A
Yeah
sure,
so,
if
you,
if
you
want
to
do
that,
let's
talk
about
ethereum,
first
and
bitcoin.
If
you
want
to
do
the
transaction,
you
create
a
transaction.
That's
going
to
have
some
byte
code,
either
that's
for
bitcoin,
virtual
machine
or
for
ethereum
virtual
machine.
This
will
be
some
operations
and
those
operations
could
be
add.
A
A
This
is
the
sum
of
the
costs
for
every
trans
every
operation
made.
So
you
can
imagine
that
let's
say
adding
two
numbers
is
gas.
Two
multiplying
two
numbers
is
just
ten.
So
if
you
have
like
five
additions
and
one
multiplication
is
like
5
times,
2
plus
10,
and
then
your
gas
cost
would
be
20.
A
And
you
pay
a
lot,
but
what
does
it
mean
to
pay
so
how
much
one
unit
of
gas
costs-
and
this
is
another
thing
that
it's
important
it's
it's
called
gas
cost
and
if
you
send
a
transaction
to
the
network
about
an
interim
and
blockchain
miners
actually
need
to
be
convinced
to
include
your
transaction
into
the
block.
A
So
if
I
put
the
gas
cost,
let's
say
really
really
high,
then
my
my
miners,
not
my
the
miners-
will
take
my
transaction
really
willingly
because
they
say
wow.
A
I'm
gonna
earn
a
lot
on
this
like
ten
dollars
on
these
transactions,
but
if
the
gas
cost
would
be
half
of
this
price,
they
still
would
take
it
because
they
would
be
like
oh
five
dollars
in
this
transaction
nice.
So
but
on
the
other
hand,
if
I
put
the
cost
of
the
one,
you
need
gas
really
really
low,
they
would
take
a
look
and
say:
oh,
I'm
gonna
earn
on
this
half
cent.
I'm
not
gonna.
Take
this
so
how
to
pick
the
rice
right,
gas,
ghost
and
I'll.
Tell
you
showing
you
this.
A
A
A
A
A
A
A
Buy
casper
labs
tokens
then
learn
all
the
this
things
with
the
wallets
and
do
a
lot
of
things,
probably
in
a
new
way
and
that's
like
a
huge
buyer.
So
it
is
in
our
system.
A
We
are
proposing
a
method
for
controlling
the
gas
and
who
who's
paying
for
the
gas
and
how
you
pay
for
the
gas
using
smart
contract.
What
it
means.
A
When
you
send
a
transaction
to
the
to
the
blockchain,
you
specify
two
smart
contracts.
Actually,
one
is
the
smart
contract,
the
standard,
smart
contract.
We
call
it
session
code
and
the
session
code
is
what
we
saw
last
time
when
we
built
ethereum.
All
of
this
code
was
the
session.
This
is
like
the
the
logic
of
the
execution,
the
smart
contract
itself,
but
there
is
also
another
piece:
it's
called
payment
code
and
the
payment
code
executes
after
the
session
code
was
executed.
So
in
the
first
place
the
the
decision
code
was
executed.
A
The
virtual
machine
knows:
okay,
this
session
code
cost
1
million
of
gas.
So
now
I
know
the
gas
price,
so
let's
say
the
gas
price
is
10.
So
I
need
to
take
10
millions
of
clx
tokens
from
this
user
and
if
that
would
be
ethereum,
then
the
system
would
take
a
look
at
the
amount
of
gas
amount
of
tokens
or
ethereum
that
the
customer
has
and
just
simply
take
it
from
the
account
in
caster
labs.
A
A
A
A
A
Okay,
so
so
I'm
gonna
show
you
this
scenario
where
the
account
doesn't
have
to
pay
for
its
own
execution,
and
this
is
scenario
like
let's
say
I
created
the
system.
C
C
C
A
As
you
know,
everything
starts
in
cold,
so
at
the
beginning
there
is
no
payment
code.
There's
nothing.
So
our
goal
is
to
execute
the
normal
session
code,
normal
smart
contract,
that's
gonna,
deploy
the
contract.
A
And
this
contract
will
pay
for
my
execution
for
will
pay
for
the
execution,
but
this
contract
will
be
there
living
somewhere
and
it
will
work
when
someone
when
it's
gonna
be
called
from
the
payment
code.
So
one
more
time
about
the
execution.
First,
the
session
code
executes
and
then
the
payment
control
executes.
It's
the
same
model
of
the
execution.
A
It's
also
gonna
call.
In
the
same,
if
I
call
the
hash,
it's
gonna
call
the
hash
as
a
normal
smart
contract.
Okay.
So
let's
I
have
a
short
description
of
the
scenario
here.
Maybe
that's
gonna
help
as
well.
C
A
A
Maybe
I
should
say
a
bit
what
is
poor's?
I
don't
think
I
mentioned
this
in
casper
labs.
If
you
have
a
if,
if
you
have
a
tokens,
our
clx
tokens
casper
labs
tokens.
A
These
are
not
associated
directly
to
the
account
like
in
bitcoin
or
ethereum,
but
they
are
stored
in
the
in
the
purse
and
what
is
the
first,
the
purses?
Actually
it's.
A
A
A
A
A
A
Actually,
I
told
you
wrong:
the
payment
code
is
executed
before
the
session
code
and
to
do
yeah.
That
would
be
stupid
to
execute
payment
code
after
session
code,
because
if
the
session
code
is
expensive,
computational
computations
and
there
is
no
payment
for
the
competition,
then
the
host
just
did
a
lot
of
computation
without
being
paid
for
it.
A
A
First,
you
need
to
be
paid,
but
the
question
is
how
much
so
we
don't
know
how
much
so
we
pay
some
amount
and
we
hope
that
it's
going
to
be
enough
for
the
execution
and
just
after
the
execution,
the
smart
con,
the
session
code
can
can
cost,
let's
say
more
or
less
so.
If,
if
it
got
less,
then
let's
say
the
smart
contract
cost
500
and
we
paid
up
front
1000.
A
The
refund
to
be
done
not
to
the
user
because
he
called
it-
that's
like
the
baked
in
behavior,
but
we
want
this
to
be
transferred
back
to
the
smart
contract.
A
A
A
A
Okay,
so
this
call
gonna
prepare
everything
for
us
and
later
users
can
use
the
smart
contract
deployed
inside
of
this
call.
A
A
Okay,
so
first
read
two
arguments:
get
arc
uses
runtime
get
arc
and
handles.
A
Handles
missing
arguments:
okay,
star
first
authorized
account
europe.
So
let's
we
need
to
save
this.
This
authorized
account
under
some
the
memory,
so
we
can
pass
it
to
the
smart
contract.
A
A
A
A
Now
we
want
to
prepare
named
keys
for
the
payment,
so
these
are
the
known
urls
that
gonna
and
that
the
the
account
will
not
know
at
the
beginning.
A
A
Also,
we
wrap
the
payment
contract
first
into
a
uf
again,
so
it's
possible
to
access
it
from
the
outside
to
as
a
testing
framework.
You
you'll
see
this
in
tests
because
normally,
when
you
do
this-
and
you
want
to
call
the
payment
contract
first
you're
going
to
get
the
key
and
the
smart
the
the
testing
contract,
what
actually
does
is
it
takes
what's
under
the
key,
so
it
takes
the
key
and
then
it
uses
the
memory
to
call
the
storage
to
actually
call
the
value
that's
saved
under
this
key.
A
A
A
Okay,
so
what
it
so
at
first,
it
already
has
three
two:
it
has
three
name
keys,
but
we're
gonna
talk
about
only
two,
so
it
can
get
the
key.
That's
that
it's
first.
So
this
is
the
first
that
the
been
created
and
has
some
positive
value
balance.
Then
it
can
read
the
authorized
account
key.
A
A
Okay
and
now,
the
the
the
main
part
of
the
contract
that
actually
gonna
pay
for
the
all
of
this
is
gonna
for
the
execution
up
front.
A
A
First,
we
take
the
payment
first,
so
we
called
the
the
proof
of
stake
contract
and
that
get
payment.
First,
that's
just
the
string
get
payment.
First,
we're
gonna
get
ba,
have
back
the
uf,
which
is
first
and
we're
gonna
call
con.
We're
gonna
call
this
contract
again
and
we're
gonna
set
a
refund
refund
first
as
our
ampersa.
A
And
now
it's
time
to
call
this
contract
somehow
so
how
you
call
the
contract?
Probably
you
remember
from
the
previous
session
that
if
you
call
the
contract
directly
as
an
user,
you
don't
execute
it
as
this
cont
as
its
own
contact,
but
you're
gonna
execute
it
as
the
the
account
context.
So
you
need
to
call
some
code.
That's
gonna
call
the
smart
contract
and.
A
A
And
also
this
is
another
smart
contract
here,
it's
a
set
main
purse
is
this
contract
is
made,
so
we
have
something
to
call.
It's
gonna
just
put
accounts
main
purse
under
a
key.
Actually
I'm
going
to
use
it
in
tests.
So
I
know
I
need
to
save
the
accounts
main
first
under
a
key,
so
I
can
query
it
through
testing
framework.
A
A
A
And
now
the
admin
account
needs
to
deploy
the
this
smart
contract.
So
after
the
compilation
he
can
use
it
as
a
contract
that
wasn't
so
execute
this
contract.
Using
these
arguments,
as
you
remember,
the
argument
was
approved
account
and
the
amount
initial
amount
for
the
contract
payment,
and
so
this
is
the
execution
here.
So
now
we
have
those
three
contracts.
A
Deployed
okay,
so,
first
check:
if
payment
code
has
authorized
account,
set,
we
use
contract
query,
we
use
admin,
account
space,
we
get
into
the
payment
contract,
key
smart
contract
and
we
expect
this
to
be
smart
contract
and
we
also
expect
that
there
is
a
key
authorized
account.
Either
we
unwrap
types
and
assert
if
it's
the
same
as
our
initial
approved.
A
A
A
First,
let's
start
the
approved
account
main
purse
under
named
key,
so
we
can
actually
query
the
check
the
balance
and
then
we
will
execute
it
with
our
new
payment
code
and
see
that
the
balance
hasn't
changed.
A
Okay,
so
so
first
approved
account.
Gonna
execute
this
set
main
first
hash.
So
what
it
did
is
is
check
if
the
runtime
already
has
account
made.
First
key,
do
nothing
but
it's
if
it's
none,
then
cre
wrap
main
purse
into
new
uref
and
put
this
under
under
this
string.
A
Okay
and
thanks
to
this
piece
of
code,
we
can
now
query
the
balance
the
balance
of
this
burst.
So
this
is
the
initial,
so
at
the
moment,
in
this
this
moment,
the
approved
account
has
this
balance
the
first
balance
before
and
now
now
the
magic
deploy
and,
let's
deploy
some
some
contract
for
this
I'll,
just
deploy
again.
This
set
main
purse,
but
that
could
be
any
other
contract
it.
It's
not
relevant,
actually
and
see,
and
let's
deploy
it
so
how
we
do
it.
A
First,
we
define
payment
code
and
later,
when
I
build
the
session
here,
I
specify
payment
code
this.
So
I
need
to
pass
payment
code
and
payment
arguments.
A
C
A
A
So
that's
it
are
there
any
questions.
A
A
Check
out,
because
this
is
work
in
progress,
I
haven't
merged
it
into
the
master,
so
you
need
to
change
the
branch
and,
if
you're
interested
you
can
you
have
a
make
file
here.
A
A
B
B
C
C
C
A
I
can
give
you
a
bit
like
small
task
to
to
tell
me,
maybe
in
the
next
week
what
was
the
most
problematic
with
it.
A
A
A
A
So
this
is
the
session
called
execution
after
that,
the
host
checks.
How
much
did
this
cost
calculated?
Let's
say
it
was
70
million
tokens
sees
that
it
was
paid,
1
million
100
million,
so
the
change
is
30
millions
and
it's
going
to
pay
back
the
30
millions
to
something
we
call
the
refund
purse
and
normally
it
would
be
accounts
refund
first.
So
the
guy
who,
who
created
the
guy
who
who
is
defined
here,
but
because
we
don't
want
this
account
to
do
anything
with
the
the
tokens
we
want
the
contract
to
have
it
back.
B
B
B
A
So
you
you
say
here
right
so
here's
the
admin
account
creates.
The
main
account
takes
his
own
account,
and
the
question
is
why
I
transfer
first
to
new
purse
rather
than
pass
my
own
purse.
A
C
C
C
C
A
A
A
As
many
times
as
there
is
a
amount,
there
are
tokens
in
the
purse
right
so
let's
say,
if
account
the
admin
account
would
like
to
somehow
lower
the
amount
of
times
or
lower
the
amount
of
gas
it
wants
to
spend.
A
A
B
A
You
so
this
example,
as
I
showed
you
is
this-
is
the
exam
like
the
complex
case
that
I
wanted
to
explore
and
see
if
it's
possible,
but
normally
when
you
do
the
transaction.
A
C
A
So
normally
when
you,
when
you
call
call
it
when
you
call
with
something
we
have
something
like
standard
payment
code
that
we
created
and
most
of
the
time
when
you
do
the
transaction,
you
use
something.
We
call
standard
payment
code
and
this
is
just
a
snippet
that
does
this
get
the
proof
of
stake
contract
and
this
is
executed
not
in
as
a
smart
contract.
But
this
is
executed
as
the
account.