Giter Club home page Giter Club logo

devicehive-plugin-ethereum's Introduction

Devicehive plugin ethereum

This plugin allows you to manipulate your custom smart contract via devicehive.

Before the start

You should have ethereum node running somewhere. You also need ethereum account's address and password. With this guide you can run ethereum node locally.

Specify ethereum configuration

Firstly you should specify ethereum configuration. Add ethereum url, account's address and account's password to config file (path - ./src/ethereum-node/config.json).
Note - you can use example to see how it works, just do not change other fields.

Specify plugin configuration

In plugin configuration there are already playground urls, however you can run devicehive locally and write your own. Add plugin topic and access token. Also add user access token, which you can copy from playground.

Simple start

  1. Create plugin (locally or on playground) and specify plugin configuration file
  2. Specify ethereum configuration file (plugin will start with contract in example folder)
  3. Run npm i
  4. Run npm start
  5. Send message from device. See example here.
  6. Wait for plugin receives the message and sends transaction to blockchain.

Logger will notify you about results. You will see message Transaction has been passed successfully, hash: ${transactionHash}.

Configuration

Plugin

You can find plugin configuration in ./config.json Plugin part of configuration you can find here. Also plugin authentication process and options are described here.

PLUGIN_PROPS - plugin's properties. There are only filters at the moment. PLUGIN_PROPS.OVERRIDE - set it to true and plugin's filters will be updated according to config. FILTERS - filters for your plugin. LOGGER - logger configuration.

Examples:

"FILTERS":{
    "notifications": true,
    "commands": false,
    "command_updates": false,
    "names": "blockchain-record"
}

"LOGGER":{
    "level": 0, // 0 - info + error, 1 - error
    "filePath": "./dhe-log.txt"
}

Ethereum smart contract

You can find configuration in ./ethereum-config.json

  • CONTRACT_PATH - path to your smart contract,
  • ETHEREUM_URL - url to ethereum node,
  • CONTRACT_INITIAL_ARGS - arguments for initializing smart contract,
  • ACCOUNT_ADDRESS - ethereum account address
  • ACCOUNT_PASSWORD - ethereum account password
  • GAS_LIMIT - maximum gas limit which can be used by device
  • TIME_PERIOD - time period in minutes, every TIME_PERIOD minutes gas limit will be updated
  • CONTRACT_ADDRESS - contract's address, which plugin will use
  • OVERRIDE_CONTRACT - set it to true, if you want to create new contract
  • ALLOWED_METHODS - methods, which can be used by device

Plugin parameters

After successfull creation of the contract plugin's parameters will be overwritten.
They will store ethereum node url, contract's address, allowed methods and initial transaction's hash.

Message name: blockchain-record Parameters: { "method": "increase", "args": { "amount": 1 }, "options": {} }

Message model

{
    "method":*method_name*,
    "args":{
        "arg1",
        "arg2",
        ...
    },
    "options":{
        "gas", // optional
        "gasPrice", // optional
        "value"" // optional
    }
}

Note: if gas or gasPrice are not specified then plugin will use min amount of gas for transaction.

How to run ethereum node locally

To start ethereum locally:

Note - with this guide you will run dev node, so you will not be working with real ethereum.

  1. Download and install geth.
  2. Open terminal and run geth --mine --minerthreads=1 --networkid=1999 --rpc --rpcaddr "127.0.0.1" --rpcapi="admin,debug,miner,shh,txpool,personal,eth,net,web3" --dev.
  3. Open another terminal window and run geth attach http://localhost:8545.
  4. In second window run personal.newAccount() and enter your password. You will get account's address.
  5. Make sure you have enough ethereum. You can run eth.accounts.forEach(function(account){if(account!==eth.coinbase){eth.sendTransaction({from:eth.coinbase,to:account,value:web3.toWei(1000000)})}}) to increase it on your account. You will see undefined in response. It means that transaction has been finished successfully.

Note - you can check your account's balance by entering web3.fromWei(eth.getBalance(${ACCOUNT_ADDRESS}), "ether") command.

devicehive-plugin-ethereum's People

Contributors

antgrisha avatar tmatvienko avatar

Stargazers

Baek avatar Sergey Nikitin avatar Michael Law avatar

Watchers

den avatar James Cloos avatar Igor Iliunin avatar Rafael Zubairov avatar Zhangxin (Jason) Chen avatar  avatar Michael Law avatar  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.