IoT integration and blockchain technologies have created new opportunities in energy management. Peer-to-peer (P2P) energy trading is made possible by this study's innovative framework, which uses blockchain and IoT to provide direct energy exchange amongst prosumers in a decentralised network. IoT devices offer real-time monitoring, while blockchain makes sure that transactions are transparent and secure. Transaction costs are decreased via smart contracts, which automate the process. Our experiments in the real world and simulations show better resource use, lower carbon foot-prints, and more consumer autonomy. This framework encourages innovative energy management practices and sustainable energy systems