top of page

LEVEL 5

We are nearing completion now! Wohoo, how exciting!

Let us create 2 entrypoints in this level - because, why not :D!

Step 1:

First entrypoint: A function named create_random_power - which would create a random power for the superhero and allocate it.

How can we do this?

We will use a variable from the Chain library - known as Chain.timestamp. This will return the timestamp of the current block. We will add this with the index variable defined in our record "state".

Why are we doing this?

This will help you learn more about the parameters assocated with the Chain.

Step 2:

Step a:

Second entrypoint: create_superhero

This will take in a parameter "name" of type "string" and return nothing.

What should this entrypoint do?

1. This should check if the name satisfies the name check by passing it to the name_check function. For this, we will use the keyword - require.

What does the require function do?

It is used to add constraint to a function. If the require statement is not satisfied, the function execution will not proceed further.

Example boilerplate code:

require(function(argument), "Message that you would like to print")

Step b:

Create a variable power and call the function "create_random_power" with the name as the argument and assign the return value to this variable.

Example boilerplate code:

let var_name : data_type = create_random_power(name)

Step c:

 Now you need to call another function "create_superhero_with_values" with the name and the power as the parameters. This is the function that will create the superhero for us. We will write this function in the next level.

Let us create these two entrypoints and move forward!

If you want more information on Sophia, refer to this link here: https://github.com/aeternity/aesophia/blob/lima/docs/sophia.md

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