0

I am new to blockchain technology. I just want to know if it is possible to post the data from raspberry pi on blockchain (ethereum) and retrieve the posted data for viewing. My question is if its possible how can it be achieved ?

0

Yes that's totally possible and works exactly the same as if you wanted to do that e.g. on your laptop.

Depending on what you exactly intend to do there are several possibilites that you can easily find by doing some research, just to point one out:

  • Create a solidity contract that can hold your data
  • deploy your contract to an ethereum network
  • write a small nodejs application that connects to the blockchain via web3 (https://github.com/ethereum/wiki/wiki/JavaScript-API)
  • start nodejs application on raspberry pi

Some easy example code to watch for Events could look something like that:

var Web3 = require('web3'); 
var web3 = new Web3(new Web3.providers.HttpProvider("<insert rpc endpoint here>")); 
var contractABI = require('<insert abi here');
var contract = web3.eth.contract(contractABI);
var context = contract.at('<enter address of deployed contract here>')
var truth = context.allEvents({fromBlock: 0, toBlock: 'latest'});
truth.watch(function(error, result){   
  if(error){
    console.log("Error on listening to events:", error)
  }else{
    // do something with the code here 
  } 
})
2
  • Thank you so much. Can you please provide any site information/project as an example which has implementation details of your answer?
    – gvs
    Apr 26 '18 at 7:04
  • Code in my answer is pretty much just something I am using to do exactly what you are planning to do. Probably it would be best for you to begin with a basic tutorial like this: truffleframework.com/tutorials/pet-shop - truffle is a nice framework to help with blockchain dev. And as soon as you understood to basic concepts you can transfer that knowledge to what you actually want to achieve. Apr 26 '18 at 7:41

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.