1.0.342 • Published 9 months ago

ethernity-cloud-sdk-js v1.0.342

Weekly downloads
-
License
AGPL-3.0
Repository
-
Last release
9 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

9 months ago

1.0.342

9 months ago

1.0.340

9 months ago

1.0.338

9 months ago

1.0.337

9 months ago

1.0.339

9 months ago

1.0.334

9 months ago

1.0.333

9 months ago

1.0.336

9 months ago

1.0.335

9 months ago

1.0.305

11 months ago

1.0.304

11 months ago

1.0.307

11 months ago

1.0.306

11 months ago

1.0.301

11 months ago

1.0.303

11 months ago

1.0.302

11 months ago

1.0.321

10 months ago

1.0.320

10 months ago

1.0.327

10 months ago

1.0.326

10 months ago

1.0.329

10 months ago

1.0.328

10 months ago

1.0.325

10 months ago

1.0.319

10 months ago

1.0.310

11 months ago

1.0.316

10 months ago

1.0.315

10 months ago

1.0.318

10 months ago

1.0.317

10 months ago

1.0.311

10 months ago

1.0.314

10 months ago

1.0.313

10 months ago

1.0.309

11 months ago

1.0.308

11 months ago

1.0.330

10 months ago

1.0.332

10 months ago

1.0.331

10 months ago

1.0.300

12 months ago

1.0.205

1 year ago

1.0.220

1 year ago

1.0.221

1 year ago

1.0.225

12 months ago

1.0.210

1 year ago

1.0.215

1 year ago

1.0.240

12 months ago

1.0.230

12 months ago

1.0.235

12 months ago

1.0.200

1 year ago

1.0.202

1 year ago

1.0.201

1 year ago

1.0.194

1 year ago

1.0.193

1 year ago

1.0.192

1 year ago

1.0.191

1 year ago

1.0.186

1 year ago

1.0.189

1 year ago

1.0.188

1 year ago

1.0.185

1 year ago

1.0.190

1 year ago

1.0.181

1 year ago

1.0.178

1 year ago

1.0.176

1 year ago

1.0.175

1 year ago

1.0.174

1 year ago

1.0.173

1 year ago

1.0.172

1 year ago

1.0.171

1 year ago

1.0.170

1 year ago

1.0.169

1 year ago

1.0.168

1 year ago

1.0.167

1 year ago

1.0.166

1 year ago

1.0.165

1 year ago

1.0.163

1 year ago

1.0.162

1 year ago

1.0.161

1 year ago

1.0.160

1 year ago

1.0.158

1 year ago

1.0.157

1 year ago

1.0.156

1 year ago

1.0.155

1 year ago

1.0.153

1 year ago

1.0.152

1 year ago

1.0.151

1 year ago

1.0.150

1 year ago

1.0.141

1 year ago

1.0.140

1 year ago

1.0.139

1 year ago

1.0.138

1 year ago

1.0.137

1 year ago

1.0.135

1 year ago

1.0.134

1 year ago

1.0.133

1 year ago

1.0.132

1 year ago

1.0.130

1 year ago

1.0.127

1 year ago

1.0.126

1 year ago

1.0.125

1 year ago

1.0.124

1 year ago

1.0.123

1 year ago

1.0.122

1 year ago

1.0.121

1 year ago

1.0.120

1 year ago

1.0.119

1 year ago

1.0.118

1 year ago

1.0.117

1 year ago

1.0.116

1 year ago

1.0.115

1 year ago

1.0.114

1 year ago

1.0.113

1 year ago

1.0.112

1 year ago

1.0.111

1 year ago

1.0.110

1 year ago

1.0.109

1 year ago

1.0.108

1 year ago

1.0.107

1 year ago

1.0.106

1 year ago

1.0.105

1 year ago

1.0.104

1 year ago

1.0.103

1 year ago

1.0.102

1 year ago

1.0.101

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year 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