I want to design a business model that includes:

  • An IoT device, it has a address and signed data to write into smart contract, but it cannot directly connect to the ethereum network, and also its address balance is zero.
  • A smart contract owner by the IoT device manager.
  • An ethereum node, which can write data for the iot device for reward.

So I write the following solidity sample code.

contract Storage
    mapping(address => string[]) dataOfAddr;
    function writeData(address _addr, string _data, uint8 v, bytes32 r, bytes32 s) payable public returns(uint)
        require(ecrecover(sha256(_data), v, r, s) == _addr);
        msg.sender.transfer(1 ether); //for example
        return dataOfAddr[_addr].length;

So that the iot device sends

  • contract address
  • (its address, data, signature(v, r, s))

to ethereum node. Ethereum node writes data for it, and get reward from the contract.

Now, the problem is how can the ethereum node determine it can gain reward? Since we can only get bytecode of contract instead of source code.


There might be another way but on my view,

For IoT you might use Respberry-pi or something, that can connect to any node or can be IoT Device as a node. Let us take example of R-pi, You can program on your way and watch any event, do any action.

Now the thing is address you want with balance. It depends on which consensus mechanism you used. If POW then it will be difficult.

In POA you may use any address of node that accumulate ether balance. If you are using your own network(To use account) Those EOA which you can use further any activity(manually transferring ether to account).

For contract you can deploy contract and use your logic code to transfer ether to other address that you won't want that reward and award on own account(account that explained above).

This may be helpful.

  • Very help. Your advice is valuable. And since we cannot read the source code of a smart contract, is it safe that we use a private variable to hardcode a private key into the contract? So that I can append a ecsign command to the wirteData function to get a signature, and use it as an ack to convince the iot device that I have already wrote the data?
    – zinan guo
    Apr 23 '18 at 14:51
  • Sure, you can use address as hard coded. You might be in fear that if someone use my address !! no ! to send the transaction with your account address they must have to unluck it. But the private key - public key concept restrict it.
    – Gopal ojha
    Apr 24 '18 at 9:23

you need to have a frontend that receives the data from the IoT device and sends it the contract as the device cant do it by itself. This can be done using web3.js. Or if you are good in python you can use web3.py

With web3 you can instantiate the contract, which will give you access to its functions. The transactions need to be done with an account with funds unlocked in the ethereum node in order to pay for the gas.

Hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.