You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class AlienFinder : SmartContract {
public class Alien {
public uint xna;
public string alienName;
}
public static void Main (string alienName) {
ulong random = RandomNumber ();
uint xna // Call FindXna () here
Alien someAlien = new Alien {
// Change the arguments here
};
// Notify here
}
private static ulong RandomNumber () {
uint blockHeight = Blockchain.GetHeight ();
return Blockchain.GetHeader (blockHeight).ConsensusData;
}
private static uint FindXna (ulong randomNumber) {
// Return the last 8 digits here
}
}
public class AlienFinder : SmartContract {
public class Alien {
public uint xna;
public string alienName;
}
public static void Main (string alienName) {
ulong randomNumber = RandomNumber ();
uint xna = FindXna (randomNumber);
Alien someAlien = new Alien {
xna = xna,
alienName = alienName,
};
Runtime.Notify (alienName, "created!");
}
private static ulong RandomNumber () {
uint blockHeight = Blockchain.GetHeight ();
return Blockchain.GetHeader (blockHeight).ConsensusData;
}
private static uint FindXna (ulong randomNumber) {
return (uint)(randomNumber % 100000000);
}
}
The last thing to implement is the generation of XNA. Since the number ganerated from RandomNumber can be a very large integer (0 to 18,446,744,073,709), we will take the last 8 digits to form the XNA value.
The Runtime.Notify Method
We would also want to notify the client running the contract that a new alien has been created. In NEO, this can be achieved with Runtime.Notify. This function raises a 'Notify' event to the client. It can take any number of parameters of any type.