Skip to content

paul-cruz/ConnectIoT-API

Repository files navigation

NEAR REST API SERVER FOR Connect IoT

This repository is a specific implementation for the Connect IoT project based on the official NEAR REST API SERVER repository following its license, so if you use this code, keep in mind to check its protection.


Overview

Click on a route for more information and examples

Route Method Description
CONNECT IOT CONTRACT
/call POST Performs a call to the smart contract, validating the method

Requirements

NEAR_CONTRACT_ID=dev-1659666583036-94152895119798

Setup

  1. Clone repository
https://github.com/paul-cruz/Connect-IoT-API.git
  1. Install dependencies
npm install
  1. Configure near-api-server.config.json Default settings:
{
  "server_host": "0.0.0.0",
  "server_port": 5000,
  "rpc_node": "https://rpc.testnet.near.org",
  "init_disabled": true
}
  1. Start server
node app

Contract

/call

Performs a call to the smart contract, validating the method.

Method: POST

Valid methods:

  • create_registry
  • delete_registry
  • add_device_to_registry
  • delete_device_from_registry
  • set_device_data
  • get_device_data
  • set_device_data_param
  • get_device_data_param
  • set_device_metadata
  • get_device_metadata
  • set_device_metadata_param
  • get_device_metadata_param
Param Description
account_id Account id that will be performing the call and will be charged for gas and attached tokens / deposit.
seed_phrase OR private_key Seed phrase OR private key of the account id above.
method A valid method for the ConnectIoT method.
params Arguments the method of the contract takes.

Note: Use near login to save your key pair to your local machine.

Example:

{
  "account_id": "paulcruz.testnet",
  "private_key": "5a92dJw8NtnwPZmHAuCt3M123pE1aD2wM5z7BkTasdnCxbEHX22Gei2jnoWjaGcZUk2ZZtPriMa25CLpcp96s7Mw",
  "method": "get_device_metadata_param",
  "params": {"registry_name": "my_registry", "device_name": "my_device", "param": "timestamp"}
}
Example Response:

{
    "data": "1659740812726"
}

Example:

{
  "account_id": "paulcruz.testnet",
  "private_key": "5a92dJw8NtnwPZmHAuCt3M123pE1aD2wM5z7BkTasdnCxbEHX22Gei2jnoWjaGcZUk2ZZtPriMa25CLpcp96s7Mw",
  "method": "get_device_metadata",
  "params": {"registry_name": "my_registry", "device_name": "my_device", "param": "timestamp"}
}
Example Response:

{
    "read_type": "streaming",
    "timestamp": "1659740812726",
    "area": "west"
}


About

API to connect the project libraries with the NEAR Protocol smart contract

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors