GithubHelp home page GithubHelp logo

19860207 / chia-agent Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chia-mine/chia-agent

0.0 0.0 0.0 144 KB

chia websocket client for chia daemon

License: MIT License

JavaScript 38.38% TypeScript 61.62%

chia-agent's Introduction

chia-agent

npm version License: MIT

Websocket client for chia daemon for nodejs.

What chia-agent can do.

chia-agent connects to chia daemon via websocket and monitor realtime chia status.

For example, you can develop your own nodejs script to:

  • Send email when proof is found.
  • Get customizable stats report.
  • Trigger your scripts when target event is observed.
  • start/stop services.
  • etc, etc

I'm working on additional api documentation. Please be patient.

Install

npm install chia-agent
# or
yarn add chia-agent

Sample Node.js script for sending email when proof is found.

*chia daemon must be started in advance. Chia daemon automatically starts up when running GUI or

// sample.js
const {getDaemon, setLogLevel} = require("chia-agent");
setLogLevel("debug"); // none/error/warning/info/debug is avaiable.

const daemon = getDaemon();

(async function(){
  await daemon.connect();
  // By subscribing "wallet_ui", you can monitor messages sent for GUI.
  // Available subscription will be provided later.
  await daemon.subscribe("wallet_ui");

  // Detailed API specification will be provided later.
  daemon.addMessageListener("chia_farmer", (e) => {
    if(e.command === "new_farming_info"){
      const {farming_info} = e.data;
      const {challenge_hash, passed_filter, proofs, total_plots, timestamp} = farming_info;
      const date = new Date(timestamp*1000);

      console.log(`${challenge_hash.substr(0, 32)}... ${passed_filter}/${total_plots} ${proofs} ${date.toLocaleTimeString()}`);
      
      if(proofs > 0){
        // You can implement some code here to send email.
      }
    }
  });

})();

//  You can implement onClose event handler.
process.addListener("SIGTERM", onTerminate);
process.addListener("SIGINT", onTerminate);
async function onTerminate(){
  console.log("Terminating process. Please wait for a moment...");
  
  // Do some closing stuff.
  
  let timer = null;
  daemon.addEventListener("close", () => {
    if(timer) clearTimeout(timer);
    process.exit(0);
  });
  await daemon.close();
  
  timer = setTimeout(() => {
    console.error("Closing request timed out.");
    timer = null;
    process.exit(1);
  }, 15*1000);
}

API

See Document here

chia-agent's People

Contributors

chiaminejp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.