top of page

LEVEL 4

Now is where we come to the interesting part of our smart contract! Stay put!!

Now you need to start creating your entrypoints to perform various functionalities.

Let us write our very first entrypoint called "name_check"

What are we doing in this entrypoint?

We will restrict the name of the Superhero to be created to 4 options - Thor, Hulk, Ironman and Captain America.

How can we do this? We will write a simple "if" condition to check if the name sent to this function is equivalent(==) to any of the above four names. If yes, we will return true, if not, we will return false.

Why do we need this function?

Because we want to learn how to write constraints in our smart contract.

Here is some example boilerplate code:

public entrypoint check_name_example(param_name: string) : bool =

if(param_name == "Write 4 values one by one using OR operator(||) " )

    true

else

    false

There are 2 main pointers to note here:

1. The way to pass an argument to a function is: name_of_the_argument : type_of_argument

2. If you want to return a value from your function, you need to mention it like:

function_name(argument_list): return_type

Let us now write our entrypoint titled "name_check"

avengers.jpg
Try my code
Show solution
Add boilerplate code
bottom of page