Once the contract is deployed correctly, JavaScript code can be developed that will connect to the blockchain via web3, listen for the events from the smart contract in the blockchain, and turn the LED on via the Raspberry Pi.
Simply change the address in the file to what you see after deploying the contract.
The Essential Toolkit for Ethereum Smart Contract Development (Part 2)
Also, note that the HTTP-RPC server listening port on which Geth has been started on Raspberry Pi.
Remember to change this according to your Raspberry Pi setup and Geth configuration.
It is set to 9002 in the preceding example code because Geth running on Raspberry Pi is listening on 9002 in the example.
If it’s listening to a different port on your Raspberry Pi, then change it to that port: web3 = new Web3(new Web3.providers.HttpProvider(“http://localhost:9002”)); When Geth starts up it shown which port it has HTTP endpoint listening on.
This is also configurable with — rpcport in geth by specifying the port number value as a parameter to the flag.
This JavaScript code can be placed in a file on the Raspberry Pi, for example, index.js.
Why This Matters for Blockchain Technology
It can be run by using the following command: $ node index.js This will start the program, which will run on Node.js and listen for events from the smart contract.
Once the program is running correctly, the smart contract can be invoked by using the Truffle console. screenshot.
In this case, the getRent function is called with parameter 10, which is the expected value: Interaction with the contract After the contract is mined, roomRented will be triggered, which will turn on the LED.
In this example, it is a simple LED, but it can be any physical device such as a room lock that can be controlled via an actuator.
Key Points to Remember
- Truffle deploy Once the contract is deployed correctly, JavaScript code can be developed that will connect to the blockchain via web3, listen for the events from the smart contract in the blockchain, and turn the LED on via the Raspberry Pi.
- Simply change the address in the file to what you see after deploying the contract.
- Also, note that the HTTP-RPC server listening port on which Geth has been started on Raspberry Pi.
- Remember to change this according to your Raspberry Pi setup and Geth configuration.
Going Deeper: Advanced Concepts
If all works well, the LED will be turned on as a result of the smart contract function invocation. picture: Raspberry Pi with LED control Also, on node side it will display output similar to the one shown here: $ node index.js LED On As demonstrated in the preceding example, a private network of IoT devices can be built that runs a geth client on each of the nodes and can listen for events from smart contracts and trigger an action accordingly.
The example shown is simple on purpose but demonstrates the underlying principles of an Ethereum network that can be built using IoT devices along with smart contract-driven control of the physical devices.
In the next section, other applications of the blockchain technology in government, finance, and health will be discussed.
Conclusion
Truffle deploy represents one of the many innovative layers that make blockchain technology so powerful and transformative. As distributed systems continue to evolve, a solid understanding of these core concepts becomes increasingly valuable — not just for developers, but for anyone building, investing in, or working alongside blockchain-powered systems.
Whether you are just starting your blockchain journey or deepening existing expertise, mastering these fundamentals gives you the tools to think clearly about decentralized systems and make smarter decisions in this rapidly evolving space.