In a way of starting the bootcamp that kicked off in University of Jos, We started by talking about what smart contracts really are and what they do in an application. Also what should be contained in a smart contract and how it can be written, tested and deployed.
We wrote a simply little smart contract written and compiled on the fire editor.
payable contract LifeHack =
record hackUser =
{
creatorAddress : address,
imageUrl : string,
name : string,
tutorial : string,
like : bool,
likeCount : int
}
record state = {
hack : map(int, hackUser),
hackLength : int}
entrypoint init() = {
hack = {},
hackLength = 0}
entrypoint getHack(index : int) =
switch(Map.lookup(index, state.hack))
None => abort(“Product does not exist with this index”)
Some(x) => x
//create a life hack
stateful entrypoint writeHack( imageUrl’ : string, name’ : string, tutorial’ : string) =
let hackUser = {
creatorAddress = Call.caller,
imageUrl = imageUrl’,
name = name’,
tutorial = tutorial’,
like = false,
likeCount = 0
}
let index = getHackLength() + 1
put(state{hack[index] = hackUser, hackLength = index})
//returns lenght of life hacks registered
entrypoint getHackLength() : int =
state.hackLength
//returns number of likes
entrypoint getlikeCount(index : int) =
state.hack[index].likeCount
//like a lifehack
stateful entrypoint likeLifeHack(index : int) =
let product = getHack(index)
let update = {
creatorAddress = product.creatorAddress,
imageUrl = product.imageUrl,
name = product.name,
tutorial = product.tutorial,
like = true,
likeCount = product.likeCount+1}
put(state{hack[index] = update})
"LIfe Hack has BEEN LIKED SUCCESSFULLY"
This is to bring everyone to speed and we move together. We will build a frontend and backend and connect it to the smart contract. We aim to have a Daepp the school can adopt at the end of the bootcamp.