►
From YouTube: NEAR Certified Demo | Episode 5.3 -- Magic Eight Ball
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-05--magic-eightball
---
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
Okay,
so
magic,
eight
ball
you're
next.
B
B
Okay,
everyone
can
see
this
guy,
my
ide
yeah,
okay,
okay,
so
mine
is
a
simple
magic
8-ball
which
the
contract
is
you,
you
ask
a
string
and
it
just
spits
out
a
random
answer
from
a
set
that
I
initiate
at
when
I
deploy-
or
I
guess,
when
yeah,
when
the
the
code
for
the
contract
runs
and
all
it
is,
is
just
a
vector
and
that
initializes.
B
When
this,
when
my
indexes
is
running
and
then
let
me
see
what
I
do
is
just.
I
use
the
random
number
generator
from
near
sdk
to
get
a
random
index
within
the
range
of
the
the
the
size
of
the
the
list,
and
then
I
just
spit
out
I
spit
out
that
random
index,
so
to
do
that,
I
basically
simply
should
be
deployed.
So
I'm
just
going
to
get
my
executable.
C
B
A
B
Client
commands
yeah,
I
was
putting
stuff
with
scripts
folders,
but
then
I
couldn't
it
wouldn't
reach
my
credentials
and
I
just
the
the
path
was
it
wasn't
finding
my
keys,
so
I
put
them
into
the
root
folder
and
then
it
solved
this.
That's
something
I
need
to
address,
but
I
didn't
have
time
to
do
it.
So
this
is
I'm
going
to
do
the
basic
one.
B
And
so
you
just
you
know,
this
is
the
command.
B
B
And
my
sources
say
no
well,
okay
sources
are
good,
and
so
I
can
just
keep
doing
this
and
it
should
spit
out
a
different
random
number
from
that
set.
So
the
the
problem
I
have
I
have,
I
have
there's
a
lot
of
collections.
I
could
use
to
do
this
one.
B
What
I
have
is
a
list
I'd
like
to
have
another
function
where
the
user
can
add
or
even
create
their
own
lists
of
answers
like
maybe
you
can
gift
this
to
someone
and
then
they
can
see
their
own
and
you
can
kind
of
give
it
almost
as
like
a
a
fun
little
game
that
you
make
for
somebody
on
their
birthday,
and
you
know
you
know
them,
you
can
have
fun
little
answers
to
any
of
their
questions.
B
I
think
that
would
be
good
so,
but
so
just
that
simple
function
of
just
adding
something
I
don't
want
to
just
add
a
new
answer
to
this
list.
I
want
to
add
a
unique
one.
So
that's
where
I've
been
running
into
trouble
with
gas
prices
is
trying
to
check
that
that
it's
unique,
and
so
it's
it's
funny.
I
keep
the
so
when
I
do
this.
This
is
going
to
say
this
on
up
gas
and
gasoline
exceeded,
and
that's
because
of
of
this
one.
B
This
one,
this
bit
of
logic
right
here,
I
basically
have
a
I
I
loop
I
loop
through,
and
I
have
to
compare
everything
because
I'm
looking
for
I'm
comparing
streams.
B
So
that's
so
there's
other
options
that
I
explored.
There's
one.
I
even
suggested
a
persistent
set,
which
kind
of
combines
a
persistent
vector
and
a
persistent
map,
and
you
get
the
best
of
both
worlds.
My
problem
is,
then,
I
run
into
the
trouble
of
finding
a
random
key
like
getting
a
random
one
and
then
and
then
I'll,
then
what
happens
is
this
call
function
works
where
I
can
add
something
really
easily
to
it.
B
But
then,
when
I
just
do
the
main
function,
the
main
feature
of
this
contract
it
then
I
exceed
gas
limit
because
I
I,
in
order
to
find
a
random
index
of
my
persistent
set,
I
have
to
run
this
function.
That
basically
gets
my
vector
spits.
It
out
turns
it
into
an
array
and
then-
and
then
I
you
know
you
get
a
random
value
and
then
that
that
costs
gas.
B
So
I'm
just
in
this
kind
of
in
this
weird
dilemma
of
how
to
reduce
gas
prices,
but
also
to
either
you
know,
get
something
random
from
the
set
and
then
also
add
something
unique
to
the
set
and
to
do
it
cheaply
on
the
blockchain.
I.
A
No,
no,
I
was
just
gonna,
say
ben,
you
know.
Sometimes
it's
it's
actually
quite
common
to
trade
off
compute
for
storage
in
in
cases
you
know.
So
in
this
case
you
might
trade
storage
and
just
have
two
copies
of
the
data.
One
is
a
set
and
one
is
a
vector
and
before
adding
you
check
the
set,
and
if
it's
okay,
you
add
it
to
the
set
and
the
vector
and
if
not,
you
reject,
and
that
way
you
use
the
vector
for
lookups
and
the
set
for
verification.
B
Yeah,
but
to
to-
and
I
can
I
yes
and
I
do
that
and
that's
how
I
and
I
can
get
the
random
index
from
there,
but
actually
to
to
grab
it.
I
have
to
do
a
values
method
on
it
and
then
that
that's
turns
it
into
an
array,
and
then
I
can
get
a
apply
the
random
index,
but
yeah
sure
I
I
I
was
thinking
that
just
seems
like
all
my
my
spidey
senses
are
like
what
I
can't
do:
duplicate
the
data
I'll
run
into
a
whole
other
storage
issue.
B
But
it
sounds
like
that
is
actually
appropriate
here
to
have
to
to
just
sync
them,
and
then
I
guess
would
I
sync
them
with
a
different
contract,
call
to
just
make
sure
that.
B
Okay,
then
I'm
going
to
add
that,
for
when
we
review
it,
that's
that'll
be
good,
but
that's
that's!
Basically
it
it's
a
simple
thing.
I
think
I
would
love
to
I'd
love
to
just
there's
so
many
things.
B
I
learned
from
doing
this
that
I
could
I'd
love
to
put
into
the
demo
as
I
like
a
tutorial,
because
I
think
it
really
explores
persistent
storage
a
little
bit
more
depth
than
some
of
the
basic
hello
world
and
it
allows
just
some
yeah,
just
some
fun
fun
things
to
do.
B
I
think
that
one
one
application
further
down
the
line
is
like
a
survey
or
even
like
a
decision
tree
where,
if
you
answer
or
ask
a
certain
amount
of
questions
or
get
a
certain
amount
of
answers,
then
it
will
lead
you
to
this
result
like
that
you
can,
you
know
maybe
either
use
or
leverage
to
get
a
token.
B
C
B
Nice
yeah,
I
actually
yeah,
so
I
I
did
it
into
a
singleton.
Then
I
ran
to
these
eras,
where
the
contract
wasn't
initialized,
and
so
I
spent
a
lot
of
time
pouring
through
that
and
I
was
like
I
gotta
demo.
This
thing:
let's
go
back
to
what
worked
and
then
you
know-
and
then
I
got
to
this
point
so
so
we're
you
know
we're
there.
I
mean
I
made
it
to
the
demo.
That's
that's
the
win
for
me.