►
Description
Dan Connolly, Software Engineer at Agoric, demonstrates how to write your first smart contract in hardened JavaScript using the Zoe framework. This clip was recorded during the ZCash Gardening Club.
Join Office Hours: https://agoric.com/office-hours
Join Agoric Community: https://agoric.com/discord
A
Okay,
so
this
is
a
hello
world,
smart
contract
following
the
framework
and
so
a
smart
contract
is
a
javascript
module
and
it
exports
a
start
function
and
we
have
not
just
any
javascript.
We
recommend
it's
hard
in
javascript
and
in
fact
we
enforce
it
in
various
ways,
because
ordinary
javascript
somebody
could
replace
the
array.push
method
and
then
you'd
have
this
very
confusing
world
to
live
in.
So
we.
B
A
Yes,
it
is,
in
fact
I
can.
I
can
have
the
tools
check
that
okay,
let's
see
if
I
violated
jesse
anywhere
here,
so
if
I
yeah
so
there's
a
lint
profile
for
jesse-
and
I
happen
to
be-
I
haven't
strayed
outside
of
jesse
here
excellent,
so.
A
A
A
You
start
with
the
whole
world
of
messy
javascript
right.
You
take
out
non-static
scoping
things
that
you
know
modern
programming
languages
don't
have
so
you're
in
strict
mode.
You
take
out
some
stuff,
that's
dangerous!
That
I
won't
mention.
Well,
I
mean
object
capability
security.
Is
you
know
what
you
work
on
in
this
sas
realm
here
or
box
if
you're
familiar
with
that?
Okay,
so
that
collar
and
collie
or
syntax,
and
things
like
that?
A
These
are
my
mostly
globals
that
you
just
don't
get
when
you're
in
jesse,
there's
var
and
this
they're
also
outside
jesse
and
class
and
super
and
then
proxy
and
realm
and
symbol,
and
things
like
that
and
then
jesse
is
this
subset
of
javascript
that
we
recommend
for
so
that
humans
can
write
smart
contracts.
You
know
with
a
chance
of
getting
it
right.
B
Know
javascript,
you
might
try
using
some
of
those
other
features
that
are
unavailable,
but
it
seems
you
could.
The
learning
curve
should
be
somewhat
fast
for
figuring
out.
Oh,
I
can't
do
it
that
way.
So,
okay.
A
Yeah
so
yeah,
you
know
if
you're
in
in
the
editor
here
and
you
write,
what's
some
syntax
that
you're
not
supposed
to
use.
I
can't
even
remember
any
because
my
brain
is
trained
this
way
anyway.
You'll
get
red
squigglies
underneath
it
stuff
like
that.
So
you
get
real-time
feedback,
one
of
the
nice
things
about
working
in
the
javascript
world.
A
What's
it
telling
me
here,
class
is
not
allowed
jesse
to
find
a
maker
function.
Yeah
thanks
for
the
clue.
Oh.
A
So
we
have
mutable
variables,
you
can
redefine
variables,
but
you
can't
do
things
like
if
I
try
to
object
assign
now
I
don't.
I
might
go
over
time.
If,
if
I
entertain
all
these
questions
in
in
line
I'm
happy
to
do
it.
A
Yeah
see
so
you
don't
want
that
nice.
But
if
I
do
here,
if
I
do
that,
nfi
oops.
A
It'll
blow
up
cool
can't
do
that,
but
if
I
take
this
out,
if
I
just
run
test.
A
So
I'm
winning
right,
so
we
have
javascript
with
this
fun
little
edges
around
it
and
to
do
it
jesse,
sorry
to
do
a
zoe,
smart
contract,
you
export
start
function
and
yours
yours,
it
gets
access
to
something,
but
we're
not
going
to
use
it
in
this
in
this
fun.
In
this
contract,
we're
going
to
have
a
value
that
we
can
change.
That
starts
with
hello
world
and
we're
going
to
have
a
public
facet
which
you
you
give
out
widely.
A
A
So
then
the
the
tests.
We
write
them
with
a
thing
called
ava,
which
is
a
reasonably
popular
testing
framework,
and
then
we
customize
it
a
little
bit
and
you
make
a
zoo.
It's
always
a
fake
zoe
service
for
testing
purposes.
And
then
you
know
you
get
the
value
and
you
test
it
works,
and
then
you
set
set
it
and
then
sure
enough.
That
worked
too.
Now
this
little
e
widget
here
it
might
be
a
little
strange.
A
A
This
call
here
goes
between
one
sort
of
event
loop
and
another,
and
what
happens
is
the
method
and
the
arguments
and
stuff
get
serialized
up
and
sent
over
to
zoe
and
come
back
and
it's
done
asynchronously.
So
you
get
a
promise
for
the
result,
so
we
avoid
re-interesting
hazards
there.
So
that's
how
the
way
the
distributed
computing
works.
A
Okay,
so
that's
hello
and
then
but
this
doesn't
have
any
electronic
rights
or
tokens
or
money
or
anything
like
that,
and
so
here's
a
slightly
more
involved
contract.
Oh
that's
testing
it!
Sorry!
A
Here
we
get
points
for
primes
and
the
way
this
works
is,
if
you
can
guess
the
next
prime
number
you
get.
If
you
guess
the
first
prime
number,
you
get
one
point:
if
you
guess
the
second
prime
number,
you
get
two
points
et
cetera,
and
so
I
actually
got
the
prime
generator
out
of
stack
overflow,
but
it
was
written
in
python
and
javascript
doesn't
have
set
default,
so
I
had
to
add
set
default.
This
just
takes
a
map
and
a
key,
and
if
the
map
has
that
key
value,
then
it
returns
it.
A
Otherwise
it
assigns
the
that
key
to
the
default
and
gives
you
back
the
default,
and
so
this
is
just
a
generator
for
prime.
So
actually,
if
I
put
jesse
check
on
top
of
that,
I
think
I
won't
be
able
to
use
generators.
A
Yeah,
so
this
is
rocket
science
a
little
bit
so
work,
you're
kind
of
advised
against
it
because
you
might,
it
might
be
difficult
to
read
the
smart
contract,
but
you
you
can
still
do
it
so
that
generates
primes.
Believe
me:
I've
tested
it
and
everything.
A
So
that's
just
ordinary
javascript
programming
up
there,
and
so
now
we
start
our
contract,
and
so
earlier
we
didn't
make
use
of
this
widget.
That
was
passed
in
and
this
is
our
connection
to
the
zoe
world.
This
is
called
the
zoe
contract
facet,
and
one
of
the
things
you
can
do
is
make
a
mint
so
we're
making
we're
just
making
up
a
new
token.
A
I
think
you
called
them
anyway
erc20
token
and
it's
pretty
similar
and
and
then
we're
going
to
get
a
thing
called
a
brand
whenever
you
make
a
mint
there's
a
mint
and
an
issue
or
a
brand
and
a
brand
is
sort
of
how
you
recognize
this.
It's
a
little
bit
like
the
contract
address
in
ethereum,
but
it's
just
a
javascript
object
all
right.
So
then
we
got
our
generator
and
when,
when
the
way
the
the
clients
interact
with
contracts
that
make
offers
and
stuff
like
that
is
an
offer.
A
They
call
make
invitations,
so
they
get
an
invitation
and
then
they
can
make
an
offer
and
when
an
offer
comes
in
with
a
guess,
if
they
got
the
guests
right,
then
we
meant
some
some
tokens
and
give
them
to
them,
and
and
and
we
tell
them
that
they
won.
A
Otherwise
we
say
guess
again
and
if
I
hit
save
it
will
run
the
tests
again,
and
so
we
can
see
that
when
the
guess
was
2
the
guy
won
and
he
got
one
token
and
the
guess
3
and
the
guy
won
and
he
got
two
tokens
and
then
they
guessed
four
and
nope
that
wasn't
right,
so
they
so
that
is
a
little
teeny.
It's
like
a
faucet
where
you
have
to
do
a
little
bit
of
computing
to
get
your
to
get
your
money.