►
From YouTube: NEAR Certified Demo | Episode 1.2 -- Wagers
Description
This demonstration was presented by the author(s) after just 1 week of working with the NEAR platform as part of the NEAR Certified Developer program.
You can find the source code to this demo here:
https://github.com/Learn-NEAR/NCD-01--wagers
--- Follow the latest from NEAR Protocol on:
Website: https://near.org/
Discord: https://near.chat/
Blog: https://near.org/blog/
Twitter: https://twitter.com/NEARProtocol
GitHub: https://github.com/near https://github.com/nearprotocol
#Blockchain #FutureIsNEAR #NEAR #nearprotocol
A
A
B
Okay,
perfect,
so
I
only
worked
on
writing
the
contract.
So
there
isn't
a
nice
fancy
front.
End.
Sorry.
B
So
I'll
send
the
link
to
just
the
github
gist
that
I
put
the
code
on
earlier
today,
so
you
can
follow
along
and
also
share
my
screen,
so
you
can
okay,
so,
okay,
so
I
wrote
a
contract
that
will
support
setting
wagers
on,
like
the
value
of
certain
things,
like
maybe
a
stock
or
a
cryptocurrency,
and
then
in
oracle.
We'll
update
those
values
at
a
particular
time-
and
you
know
whoever
wins
the
wager
at
a
particular
time
will
just
the
winner
takes
all
kind
of
yeah.
B
So
I
kind
of
modeled
this
after
a
lot
of
the
different
near
demos
that
I
saw
also,
this
is
written
in
assembly
script
instead
of
rust,
I'm
a
lot
more
familiar
with
typescript,
I'm
a
web
developer
by
day
yeah.
So
I
suppose
we
can
go
through
this.
There
is
a
couple
things
to
note
that
these
functions
are
not
intended
to
be
used
in
regular
times.
It's
just
because
I
messed
up
my
storage
a
bunch
of
times,
so
I
needed
to
clear
it
out
yeah.
B
So
I
suppose
we
can
start
from
minting
which
is
down
here.
This
follows
very
closely
to
the
fungible
token
kind
of
idea
here,
as
I
was
writing
this
I
was
thinking
it
might
actually
be
a
better
idea
for
me
to
like
create
my
own
separate,
fungal
token
contract
and
then
have
some
inter-contract
communication
here,
like
one
that
manages
the
wagers
and
one
that
manages
the
currency,
but
I
didn't
get
around
to
doing
that
pretty
much
all
it
does.
B
Is
it
sets
the
mentor
of
the
contract
as
the
one
and
only
oracle
who
can
update
the
values
of
symbols
at
particular
times.
So
that's
kind
of
like
an
improvement
that
I
could
see
for
this
contract
is
allow
multiple
oracles
to
register
themselves
for
different
symbols.
B
So
after
we
mint,
we
have
our
standard,
you
know
get
functions,
get
balance
for
a
user,
get
the
total
supply
transfer
nothing
too
much
interesting
there.
But
this
is
where
things
kind
of
start,
to
get
more
unique
under
the
create
wager
function
where
any
user
can
create
a
wager
for
a
symbol,
they
can
choose
whether
they're
going
well,
then
they
choose
a
value
that
they
predict,
that
symbol
will
either
fall
or
fall
below
or
go
above.
B
That's
what
this
boolean
flag
says
is,
if
they're
betting,
that
it
goes
above
or
below
that
value,
how
much
they're
betting
that
it
will
do
that
and
at
what
block
time
stamp,
and
we
have
a
bunch
of
assertions
to
make
sure
that
all
the
values
are
same.
B
So,
for
example,
a
symbol
would
be
something
like
btc
for
bitcoin
if
you're
betting
on
the
price
of
bitcoin
or
it
could
be
something
like
you
know-
the
symbol
for
tesla,
if
you're
betting
on
stock
market
okay,
so
then
another
user
can
accept
a
wager
given
by
their
id
a
couple
of
just
sanity
assertions
here,
making
sure
that
you
know
you
can't
accept
a
wager.
That's
already
expired,
making
sure
that
someone
else
hasn't
accepted
the
wager
already,
and
you
also
can't
accept
your
own
wager,
because
that
would
be
dumb
yeah.
B
And
so
then
it
just
fills
in
either
the
over
the
under
field.
Whichever
was
empty
with
whoever
is
accepting
the
contract
or
whoever
is
accepting
the
wager
rather
and
updates
a
couple
of
those
lists
again,
you
can
only
delete
a
wager
if
it
hasn't
already
or
sorry.
You
can
only
rescind
a
wager
delete,
a
wager,
that's
a
helper
function,
so
this
is
an
actually
exported
function.
B
You
can
only
rescind
a
wager
if
no
one's
accepted
it
yet,
and
then
it
will
restore
your
balance
by
the
way,
so
this
kind
of
has
its
own
fungible
token.
That
is
minted
along
with
this
contract,
more
or
less.
So
whenever
you
create
a
wager,
it
kind
of
it
takes
some
of
that
some
of
your
balance
and
ties
it
up
in
that
wager.
So
it
removes
that
from
your
actual
user
balance,
but
the
wager
is
still
tied
to
your
account
id.
B
So
you
can
still
recover
that
if
you
rescind
the
wager
before
it's
been
accepted,
okay
and
then
only
the
oracle
is
allowed
to
report
a
symbol
so,
for
example,
you're
going
to
update
the
contract
with
the
price
of
bitcoin,
and
so
then
you're
going
to
get
all
the
wagers
that
are
associated
with
the
btc
symbol,
and
then
this
is
kind
of
expensive.
I
haven't
really
written
many
smart
con
writing.
B
A
loop
is
probably
going
to
be
relatively
expensive,
so
I'm
trying
to
figure
out
if
there's
a
better
way
more
optimal
way
to
do
this.
I
didn't
come
up
with
anything,
so
it's
just.
This
would
just
be
rather
expensive
to
run
if
you
have
a
lot
of
wagers
on
a
particular
symbol,
but
then
it
checks
that
the
wager's
time
has
passed
and
that
the
wager
has
been
accepted.
B
Then
it
will
distribute
the
winnings
based
on
the
simple
algorithm
of
determining.
If
the
symbol
value
is
above
the
value
or
if
the
symbol
value
is
below
the
value
and
it
will
distribute
the
winnings
to
the
under
or
over
better
accordingly.
Otherwise,
in
the
chance
that
there's
a
tie,
it
will
just
distribute
them
evenly.
B
These
again
are
just
for
debugging
purposes
and
then
a
couple
of
git
functions
for
getting
wagers
associated
with
an
account
for
a
symbol.
These
just
return
wager
ids
and
then
this
actually
returns
the
details
about
a
particular
wager
yeah
and
that's
that's
pretty
much
it.
It
is
deployed
on
test
net
right
now.
So
if
I
have
time,
I
could
right
a
couple
commands
in
my
terminal
here.
A
B
Okay,
cool,
so
something
I
noticed
is
that
whenever
I'm
calling
things
on
from
from
testnet,
it
tends
to
time
out
about
three
times
before
it
actually
works.
So
I
I
don't
know
why
that
is
so.
I
just
need
to
copy
that.
B
B
B
Okay,
oh
yeah,
okay,
so
that's
about
9
000
tokens
and
then
I
can.
B
Create
a
wager
for
I'll
create
a
wager
not
on
the
oracle
account,
because
that
sounds
dishonest
here
and
so
then
I
need
to
put
in
a
symbol
and
I'll
just
have
my
symbol
be
actually,
let's
just
btc.
B
B
Let's
so
technically,
you'd
probably
want
to
put
this
in
in
satoshi's
or
something
I'm
just
going
to
put
in
a
dummy
value.
So
let's
say
the
price
of
bitcoin
is
five,
and
I
have
to
put
that
in
as
a
string,
because
I
discovered
last
night.
That's
a
json.
Doesn't
support
120
bit
eight
bit
integers.
B
So
then
my
bet,
I'm
gonna,
bet
40
tokens.
Oh,
that
needs
to
be
a
string,
two
40
tokens
and
then
at
I
have
to
generate
this
value.
Just
give
me
one.
Second,.
B
So
I
generate
that
by
saying
so,
if
I
give
myself,
I
have
given
myself
two
minutes
here.
B
Okay,
so
that
looks
like
it
works
now
we
can
say
get
wagers
and
that
will
list
the
ids
of
our
wagers.
Oh
no
shoot.
I
that's
not
the
name
of
the
function.
It's
get
wagers
for
account,
get
wagers
for
account.
B
Oh
yeah:
well
it
should
be
I'm
just
trying
to
not
take
too
much
time.
Sorry,
we
could
get
the
details
for
that
wager.
Technically.
I
suppose
I
have
two
oh
sh.
I
have
to
accept
it
too.
So
sorry,
just
a
second.
A
We're
at
we're
at
about
10
minutes
jacob,
but
I
mean
I'm
also
able
to
verify
all
your
transactions
here
on
testnet.
I
can
see
that
that
all
this
is
coming
through
and
and
and
it's
it's
it's-
it's
obviously
making
sense
in
terms
of
the
story
that
you're
building
don't
feel
the
pressure
to
kind
of
finish
out
the
entire,
the
entire
narrative.
If
you
don't,
if
you
don't
have
to.
B
I'm
gonna
try
and
accept
the
wager,
hopefully
I'm
still
under
the
two
minute
time
that
I
give
myself
okay,
so
it
looks
like
I
myaccount5.testnet
has
now
accepted
that
wager,
and
so,
if
I
get
wager,
I'm
just
leaving
these
all
as
calls,
even
though
they
should
be
views,
oh
well,
get
wager
wager
id
is
seven,
then
we
should
see
the
over
and
the
under
are
bit
and
five
respectively
yeah,
so
those
that
have
been
assigned-
hopefully
I'm
past
my
time
now
so
like
the
wager
time
has
passed
and
let's
see
I
need
to.
B
Obviously,
a
web
developer,
because
this
is
how
I
figure
out
what
what
time
it
is:
okay,
840,
yeah,
okay,
we're
past
time
now,
so
I
can
report
this
symbol,
btc
report,
symbol.
It's
a
report
symbol!
I
think
that's
what
it's
called
and
it's
going
to
be
symbol
is
btc
yeah
and
the
value
so
we're
gonna
say
the
value
is
six.
So
that
means
that
bit.testnet
should
win
80
of
my
tokens
and
only
only
hatchet.testnet
can
call
this
because
they're
the
oracle.
So
anyone
else
can't
call
this
function
all
right.
B
So
now,
if
I
say
get
balance
for
bit.testnet,
we
should
see
that
it
is
40
more
than
here,
so
it
should
be
knowing
8
six
zero
and
there
we
go
all
right.
That's
that's
the
conclusion
of
my
demo.
That's
great.