1.0.342 • Published 8 months ago

ethernity-cloud-sdk-js v1.0.342

Weekly downloads
-
License
AGPL-3.0
Repository
-
Last release
8 months ago

Ethernity Cloud SDK JS

This project provides a set of tools and scripts to work with the Ethernity Cloud SDK in a JavaScript environment.

Table of Contents

Installation

To install the package and its dependencies, run:

npm install ethernity-cloud-sdk-js

Usage

After installation, you can use the provided scripts to build, publish, and initialize your project.

Pre-requisites

The sdk requires the following to be installed on your system:

  • Node.js v20.04 or higher
  • npm
  • docker (daemon running in the background for build and publish scripts)

Operating System compatibility

The sdk has been tested on the following operating systems:

  • MacOS
  • Ubuntu 20.04
  • Windows 10

Blockchain compatibility

  • Bloxberg:
    • Testnet - tested and working
    • Mainnet - to be provided during the following updates
  • Polyhon:
    • Amoy Testnet - to be provided during the following updates
    • Mainnet - to be provided during the following updates

Scripts

  • Initialize: To initialize the project, run:

    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:

    npm run ecld-build

    the project will be built and the docker repository output will be stored in the registry/ directory. This is the stage where the backend functions are added to the secure images.

  • Publish: To publish the project, run:

    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:

    npm run start

    command to start the demo application and test the integration.

Project Structure

.gitignore
build.js
build.sh
demo/
init.js
nodenithy/
package.json
postinstall.js
publish.js
pynithy/

Notable Directories and Files

  • 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.

Usage

To use the SDK:

  • after installation, run npm run ecld-init to initialize the project
  • in you workspace, you will find the scr/serverless 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.:
function hello(msg='World') {
    return "Hello "+msg;
}

module.exports = { hello };

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 hello("World"); to be executed on the backend which will run in the Blockchain:

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}`);
            // display the result in page below the buttons
            const result = document.createElement("p");
            result.innerHTML = `Task Result: ${e.detail.message.result}`;
            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 (
        <div className="container">
            <button className="centeredButton" onClick={executeTask}>Execute Task</button>
            <button className="centeredButton" onClick={connectWallet}>Connect Wallet</button>
        </div>
    );
}
export default App;
  • 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.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the AGPL-3.0 License. See the LICENSE file for details.

1.0.341

8 months ago

1.0.342

8 months ago

1.0.340

8 months ago

1.0.338

8 months ago

1.0.337

8 months ago

1.0.339

8 months ago

1.0.334

8 months ago

1.0.333

8 months ago

1.0.336

8 months ago

1.0.335

8 months ago

1.0.305

10 months ago

1.0.304

10 months ago

1.0.307

10 months ago

1.0.306

10 months ago

1.0.301

10 months ago

1.0.303

10 months ago

1.0.302

10 months ago

1.0.321

9 months ago

1.0.320

9 months ago

1.0.327

9 months ago

1.0.326

9 months ago

1.0.329

9 months ago

1.0.328

9 months ago

1.0.325

9 months ago

1.0.319

9 months ago

1.0.310

10 months ago

1.0.316

9 months ago

1.0.315

9 months ago

1.0.318

9 months ago

1.0.317

9 months ago

1.0.311

9 months ago

1.0.314

9 months ago

1.0.313

9 months ago

1.0.309

10 months ago

1.0.308

10 months ago

1.0.330

9 months ago

1.0.332

9 months ago

1.0.331

9 months ago

1.0.300

11 months ago

1.0.205

11 months ago

1.0.220

11 months ago

1.0.221

11 months ago

1.0.225

11 months ago

1.0.210

11 months ago

1.0.215

11 months ago

1.0.240

11 months ago

1.0.230

11 months ago

1.0.235

11 months ago

1.0.200

11 months ago

1.0.202

11 months ago

1.0.201

11 months ago

1.0.194

11 months ago

1.0.193

11 months ago

1.0.192

11 months ago

1.0.191

11 months ago

1.0.186

11 months ago

1.0.189

11 months ago

1.0.188

11 months ago

1.0.185

11 months ago

1.0.190

11 months ago

1.0.181

11 months ago

1.0.178

11 months ago

1.0.176

12 months ago

1.0.175

12 months ago

1.0.174

12 months ago

1.0.173

12 months ago

1.0.172

12 months ago

1.0.171

12 months ago

1.0.170

12 months ago

1.0.169

12 months ago

1.0.168

12 months ago

1.0.167

12 months ago

1.0.166

12 months ago

1.0.165

12 months ago

1.0.163

12 months ago

1.0.162

12 months ago

1.0.161

12 months ago

1.0.160

12 months ago

1.0.158

12 months ago

1.0.157

12 months ago

1.0.156

12 months ago

1.0.155

12 months ago

1.0.153

12 months ago

1.0.152

12 months ago

1.0.151

12 months ago

1.0.150

12 months ago

1.0.141

12 months ago

1.0.140

12 months ago

1.0.139

12 months ago

1.0.138

12 months ago

1.0.137

12 months ago

1.0.135

12 months ago

1.0.134

12 months ago

1.0.133

12 months ago

1.0.132

12 months ago

1.0.130

12 months ago

1.0.127

12 months ago

1.0.126

12 months ago

1.0.125

12 months ago

1.0.124

12 months ago

1.0.123

12 months ago

1.0.122

12 months ago

1.0.121

12 months ago

1.0.120

12 months ago

1.0.119

12 months ago

1.0.118

12 months ago

1.0.117

12 months ago

1.0.116

12 months ago

1.0.115

12 months ago

1.0.114

12 months ago

1.0.113

12 months ago

1.0.112

12 months ago

1.0.111

12 months ago

1.0.110

12 months ago

1.0.109

12 months ago

1.0.108

12 months ago

1.0.107

12 months ago

1.0.106

12 months ago

1.0.105

12 months ago

1.0.104

12 months ago

1.0.103

12 months ago

1.0.102

12 months ago

1.0.101

12 months ago

1.0.10

12 months ago

1.0.9

12 months ago

1.0.8

12 months ago

1.0.7

12 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago