►
Description
In this video, we introduce a simple smart contract that we install on the Casper Testnet.
To follow along, you can clone the repository of this simple contract that maintains a counter variable.
o Sample contract code: https://github.com/casper-ecosystem/counter
o Reference documentation: https://docs.casperlabs.io/dapp-dev-guide/writing-contracts/rust/
A
In
this
video
we'll
introduce
a
simple
smart
contract
that
will
install
on
the
Chain.
This
is
a
very
simple
contract
that
only
maintains
a
counter
variable
to
follow
along.
You
can
clone
this
repository.
A
smart
contract
is
a
self-contained
program
installed
on
chain
in
the
context
of
a
Casper
Network.
A
smart
contract
consists
of
contract
code
installed,
using
a
deploy
before
writing
contracts
for
the
network
developers
should
be
familiar
with
the
difference
between
contract
code
and
session
code
session
code
always
executes
in
the
context
of
the
account
that
signed
the
deploy
containing
the
session
code.
A
On
the
other
hand,
a
smart
contract
which
is
stored
on
chain
logic
executes
within
its
own
context,
session
code
has
only
one
entry
point
call
which
can
be
used
to
interact
with
the
session
code.
A
smart
contract
can
have
multiple
entry
points
that
will
help
you
interact
with
the
contract
code.
Any
action
taken
by
the
session
code
is
initiated
by
the
call
entry
point
within
the
session
code.
A
Any
action
undertaken
by
a
contract
must
initiate,
through
an
outside
call,
usually
via
session
code,
when
a
put
key
call
is
made
with
the
body
of
the
session
code.
The
key
is
added
to
the
accounts
name
Keys,
when
a
put
keycall
is
made
within
the
smart
contract
context,
the
contract's
record
is
modified
to
have
that
named
key
for
more
information
on
how
to
write
session
code
or
contract
code.
Please
consult
the
documentation.
A
So
when
should
we
use
a
Smart
contract?
Smart
contracts
exist
as
stored
on
chain
logic,
allowing
different
users
to
call
the
included
entry
points.
These
contracts
can
in
turn,
call
one
another
to
perform
interconnected
operations
and
create
more
complex
programs
on
the
Casper
platform
developers.
May
write
smart
contracts
in
any
language
that
compiles
to
awesome.
In
this
tutorial,
we
will
focus
specifically
on
writing
a
smart
contract
in
Rust.
The
rust
compiler
will
compile
the
contract
into
wasm
binary.
A
A
Now,
let's
look
at
the
structure
of
the
contract
in
the
main
RS
file.
No
main
is
an
attribute
that
tells
the
program
not
to
use
the
standard
main
function
as
the
entry
point.
No
STD
is
the
attribute
that
tells
the
program
not
to
import.
The
standard.
Libraries
here
are
some
of
the
required
dependencies
for
this
contract.
Casper
contract
is
a
library
for
developing
Casper
Smart
contracts.
This
crate
contains
the
API
required
to
author
smart
contracts.
A
Casper
types
are
the
types
shared
by
many
Casper
crates
for
use
on
a
Casper
Network.
We
also
have
constants
that
we
will
use
within
the
contract,
including
both
entry
points
and
values.
The
contract
also
has
entry
points
which
serve
as
a
means
to
access
the
code
installed
in
global
state,
which
is
the
storage
layer
of
the
blockchain.
These
entry
points
may
be
called
by
either
session
code
or
another
smart
contract.
A
Each
entry
point
is
effectively
equivalent
to
a
static
main
entry
point
in
a
traditional
program
when
defining
entry
points
begin
with
a
no
mango
line
to
ensure
that
the
system
does
not
change
critical
syntax
within
the
method
names.
The
call
function
starts
the
code
execution
and
is
the
function
responsible
for
installing
the
contract
at
the
time
of
contract.
Installation
passing
parameters
is
runtime
arguments.
This
way,
you
will
collect
any
values
that
dictate
your
contract's
behavior.
A
The
call
function
replaces
a
traditional
main
function
and
executes
automatically
when
a
caller
interacts
with
the
contract
code
within
the
call
function.
We
Define
the
entry
points
that
the
caller
can
access
use
the
new
content
track
method
to
create
a
contract
with
its
named
keys
and
entry
points.
This
method
creates
the
contract,
object
and
saves
the
access
URF
and
the
contract
package
hash.
In
the
context
of
the
caller,
the
execution
engine
automatically
creates
a
contract
package
and
assigns
it
a
contract
package
hash.
Then
it
adds
the
contract
to
the
package
with
the
contract
hash.
A
Usually,
these
contracts
are
upgradable,
with
the
ability
to
add
new
versions
to
add
a
new
contract
version.
You
will
need
the
access
ureth
to
the
contract
package
without
the
access
UF.
You
cannot
upgrade
your
contract
if
you
want
to
prevent
any
upgrades
to
contract,
use
the
new
locked
contract
method.
Instead,
the
next
video
will
show
you
how
to
test
this
contract
locally
before
installing
it
on
a
Casper
Network.