A package to run ethernity cloud build scripts
npm install ethernity-cloud-sdk-jsThis project provides a set of tools and scripts to work with the Ethernity Cloud SDK in a JavaScript environment.
- Installation
- Usage
- Scripts
- Project Structure
- Contributing
- License
To install the package and its dependencies, run:
``sh`
npm install ethernity-cloud-sdk-js
After installation, you can use the provided scripts to build, publish, and initialize your project.
- Initialize: To initialize the project, run:
`sh`
npm run ecld-init
at this step, all the initial configurations will be set up and the project will be ready to be built, published and run.
- Build: To build the project, run:
`sh`
npm run ecld-build
registry/
the project will be built and the docker repository output will be stored in the directory. This is the stage where the backend functions are added to the secure images.
- Publish: To publish the project, run:
`sh`
npm run ecld-publish
Required after build, to build and integrate the secure certificates that will be used during executions and to register the project to the Ethernity Cloud Image Register.
- Run: To run the project, run:
`sh`
npm run start
command to start the demo application and test the integration.
``
.gitignore
build.js
build.sh
demo/
init.js
nodenithy/
package.json
postinstall.js
publish.js
pynithy/
- build.js: Script to build the project.
- init.js: Script to initialize the project.
- publish.js: Script to publish the project.
- postinstall.js: Script that runs after the package is installed.
- nodenithy/: Contains various scripts and modules for the project.
- pynithy/: Contains Python-related scripts and configurations.
To use the SDK:
- after installation, run npm run ecld-init to initialize the projectscr/serverless
- in you workspace, you will find the directory, this contains a backend.js file. This file will be imported in the dApp images to provide the backend functions for calling from the frontend of your application, eg.:`js
function hello(msg='World') {
return "Hello "+msg;
}
module.exports = { hello };
`hello("World");
From your frontend application, using the ethernity cloud runner library, you will be calling the function as seen in the below example, where we pass to be executed on the backend which will run in the Blockchain:`js
const AppCss = require('./App.css');
import EthernityCloudRunner from "@ethernity-cloud/runner";
import {ECEvent, ECRunner, ECStatus} from "@ethernity-cloud/runner/enums";
import Web3 from 'web3';
const PROJECT_NAME = "";
const IPFS_ENDPOINT = "";
const code = hello("World");;
function App() {
const executeTask = async () => {
const runner = new EthernityCloudRunner();
// this is a server provided by Ethernity CLOUD, please bear in mind that you can use your own Decentralized Storage server
const ipfsAddress = IPFS_ENDPOINT;
runner.initializeStorage(ipfsAddress);
console.log(PROJECT_NAME)
const onTaskProgress = (e) => {
if (e.detail.status === ECStatus.ERROR) {
console.error(e.detail.message);
} else {
console.log(e.detail.message);
}
};
const onTaskCompleted = (e) => {
console.log(Task Result: ${e.detail.message.result});Task Result: ${e.detail.message.result}
// display the result in page below the buttons
const result = document.createElement("p");
result.innerHTML = ;
document.body.appendChild(result);
}
runner.addEventListener(ECEvent.TASK_PROGRESS, onTaskProgress);
runner.addEventListener(ECEvent.TASK_COMPLETED, onTaskCompleted);
await runner.run(PROJECT_NAME,
code,
'',
{ taskPrice: 10, cpu: 1, memory: 1, storage: 10, bandwidth: 1, duration: 1, validators: 1 });
};
const connectWallet = async () => {
if (window.ethereum) {
window.web3 = new Web3(window.ethereum);
try {
// Request account access
await window.ethereum.request({ method: 'eth_requestAccounts' });
console.log("Wallet connected");
} catch (error) {
console.error("User denied account access");
}
} else {
console.log('Please install MetaMask!');
}
};
return (
- you are able to define the functions needed to be used in the backend, while making sure that the function that is script is compilable and that it exports the function that will be called from the frontend, in the above example, the hello` function.Contributions are welcome! Please open an issue or submit a pull request.
This project is licensed under the AGPL-3.0 License. See the LICENSE file for details.