GithubHelp home page GithubHelp logo

hybotics / machinefi-getstarted-preview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from funkymonkey5150/machinefi-getstarted-preview

0.0 0.0 0.0 40 KB

Code for the Send Verifiable Data tutorial

Shell 2.51% JavaScript 4.36% C++ 13.29% Python 6.75% TypeScript 66.42% Dockerfile 0.22% Solidity 6.45%

machinefi-getstarted-preview's Introduction

MachineFi - Getting started

Get started with a minimal MachineFi architecture including an MQTT broker, Postgres database, Hasura engine and a basic Layer-2 service to implement the data logic based on data received from devices and blockchain smart contracts that manage the authorization and tokenomics part. A simple data simulator script is also included to facilitate prototyping.

Note: โš ๏ธ this is only boilerplate code to facilitate MachineFi Dapps prototyping. However, it's not intended for production applications as this architecture is not scalable or composable.
A full tutorial is available at https://developers.iotex.io/posts/deploy-a-machinefi-dapp.

Please stay tuned on next releases of the IoTeX MachineFi architecture.

Requirements

  • NodeJS: tested using version 14
  • Python 3
  • Npm
  • Docker and docker-compose

Running the app

Open a terminal on the directory where you have cloned this repository.
Install npm packages:

npm install

Setup your environment variables. This can be done using an .env file. Copy the provided template to run use the defaults:

cp .env.template .env

Launch the services using docker-compose:

docker-compose up

Create the database:

./create-db.sh

Deploy the contracts:

cd blockchain
npm install
echo IOTEX_PRIVATE_KEY=<YOUR_PRIVATE_KEY> > .env
npx hardhat run scripts/deploy.js --network <NETWORK>

Edit src/projects/app/project.yaml and change startHeight and DataSourceRegistry to match your contract details.

Register a device:

cd blockchain
npm install
npx hardhat registerDevice --deviceaddress <DEVICE_ADDRESS> --contractaddress <CONTRACT_ADDRESS> --network <NETWORK>

Run the simulator:

cd simulator
python3 simulator.py

Build the data layer app and initialize the database:

npm run build
npm run initdb

Start the data layer app:

npm run app

Modifying the app

You can monitor other contracts just by adding them to src/projects/app/project.yaml. For each contract, you should define your event handlers based on your application.
Edit handlers.ts to add additional handlers for contract events and MQTT data received events.
You can add more tables to the database by modifying the files inside src/project/app/models.

Debugging in VSCode

Open the folder in VS Code and use the provided launch configuration to launch the app in debug mode.

machinefi-getstarted-preview's People

Contributors

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