I have a rpi3 and it have to be a node of a blockchain. I have a script python on raspberry, which gather data from an accelerometer. Checked some conditions,I should store these data,plus other strings(Gps coordinates and date)in a blockchain. I am using testrpc and I've installed web3.js.

I start my tester from cmd inserting "testrpc" and it shows me the available accounts with theirs private keys. Then to interact with it I have to open another cmd window,right?

To interact with a generic node I have to use web3 library,so from the second cmd window I should run a node.js script,which takes data from python script( with a socket for example) and use web3 function to interface with node. Something like this:

var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));


Now,imaging I wanted to store on blockchain just some values written in node.js(and not the real data yet). I don't know. For example var x=5 e var y=10. What would be the complete code to do this?

1 Answer 1


store on blockchain

Ethereum is a bit more complicated than a generic data storage cloud. You have to make yourself familiar with the concept of smart contracts, such as how you deploy them and how you interact with them. The go-to tool right now is Truffle . If I may ask, what do you intend to make the nodejs talk to, on your raspberry pi ?

  • For what i've understood,in this case node.js works as a simply wrapper which allow python script to comunicate with an ethereum node,through web3 api.So I "pass" data from one script to another and finally,Always in the second script,i will write some code to connect to node and deploy a contract who storage my data in the blockchain. My problem is the part of "connection to node " code...please help me,i am lost...xD
    – Nick9214
    Commented Jun 5, 2017 at 14:05
  • When connecting nodejs to nodes, two components come into play. Your NodeJS part should do it, now you need to have a node client running. For development, it's recommended to use TestRPC, as it has no mining time, enough ether to test, and you can define the numbner of accounts by adding --accounts="123" when launching it. For a real node, use geth, and look up the right RPC flags. I recommend --rpc --rpcport 8545 --rpcaddr --rpccorsdomain "*" --rpcapi "eth,web3,personal,debug" , but please change them for production accordingly.
    – n1cK
    Commented Jun 7, 2017 at 12:05
  • Sorry I don't understand " When connecting nodejs to nodes,two components come into play".My problem is that I don't know what to write in node.js script to connect with a node,beside those 3 lines I wrote up here.Or,to be more clear,I don't know how to write the code between those 3 lines and the body of smart contract
    – Nick9214
    Commented Jun 7, 2017 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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