A Yeoman is a trusted worker that executes actions on behalf of a user.
You need three files, take a
metadata.json
index.js
banner.jpeg
metadata.json
This is a simple file that describes the Yeoman.
{
"version": "1.0.0",
"name": "Claim Primodium",
"description": "Streamline the process of claiming Primodium, resources, Shard Asteroid Points, units, and objectives.",
"category": "Claim, Primodium, Resources, Units, Objectives",
"imageUrl": "",
"formFields": [
{
"id": "delay",
"type": "text",
"label": "Delay (seconds) on each claim",
"placeholder": "Please enter delay in seconds",
"required": true,
"value": 10
}
],
"mainScript": "index.js"
}
The formFields array describes the input fields that you expect from the user. In this case we just have one. The others are self explanatory. At the end we have mainScript which describes the file to execute on the user's device.
index.js
This file can have any name but it has to be a valid .js file that is executed on the user's browser. When a user installs a Yeoman, it appears on Command. After a script appears on Command, it can be executed (or run) after all the required formFields are completed. The JS file is then executed on the browser. To create a security isolation, the index.js is not executed in the same context as the rest of the script. We are still working on ways to make this more secure.
//This takes a delay parameter from the user. It is marked as required in the metadata.json
const delay = formFields['delay'];
const simulateGame = async () => {
do {
try {
//This is how status messages are displayed to the user.
YeomenAI.statusMessage('Running code script started');
//Each Yeoman will have ACCOUNT field injected into it by Command.
if (!YeomenAI.ACCOUNT) {
YeomenAI.statusMessage('Please reload command');
YeomenAI.exit(0);
}
//This ACCOUNT can be used to get the address and delegator values.
const ownerAddress = (YeomenAI.ACCOUNT.delegator ? YeomenAI.ACCOUNT.delegator : YeomenAI.ACCOUNT.address).toLowerCase();
const ownerEntity = WorkerUtils.addressToEntity(ownerAddress);
// TRUNCATED REST OF THE SCRIPT
} catch (err) {
//This displays error in the console, for developers.
console.error('Error in simulateGame:', err);
//This displays an error message for users.
YeomenAI.statusMessage('Running code script failed', YeomenAI.MESSAGE_TYPES.ERROR);
//This signifies an error and will report to the user as a failure.
YeomenAI.exit(1);
}
} while (true);
};
// Call the simulateGame function which triggers the process.
simulateGame();
banner.jpeg
This is used as a diplay picture, very useful to promote the Yeoman!