# BPET: A Unified Blockchain-Based Framework for Peer-to-Peer Energy Trading
## 1 Introduction  
As distributed energy resources (DERs) such as solar panels, wind turbines, geothermal energy, plug-in electric vehicles, and bioenergy are growing, there is a pressing need for a decentralized and open market to facilitate energy trading between small-scale producers (prosumers) and consumers. Peer-to-peer energy trading (P2P-ET) refers to the direct energy exchange between prosumers and consumers. An example is the exchange of surplus renewable energy originating from DERs, like solar generation in homes, offices, factories, and other establishments [1]. P2P-ET has the potential to enhance the benefits of prosumers and consumers, providing increased flexibility to end-users to access clean energy and facilitating the transition to a low-carbon energy system. P2P-ET also affords advantages to other electricity market participants through lowering peak demand, reducing operational expenses, and enhancing system reliability [2]. A blockchain-based system provides a tamper-proof and decentralized solution to ensure the originality and authenticity of the energy data mathematically. Unlike the centralized system, the blockchain stores data copies in a large number of decentralized ledger nodes geographically distributed worldwide. Therefore, blockchain technologies have attracted a lot of attention from researchers and industry practitioners to resolve trust and information security issues in smart grids [3, 4]. However, developing such a system entails substantial effort and cost. Challenges include but are not limited to technical complexity, blockchain platforms' scalability and interoperability, regulatory frameworks and standardization, smart contract vulnerabilities, and market dynamics [5; 6]. On one hand, the intricacies of the blockchain technology stack demand experienced developers to ensure system security and efficiency. The integration of blockchain into the energy sector requires developers to have a comprehensive understanding of blockchain consensus, cryptographic protocols, smart contract security best practices, and energy trading business logic [7]. On the other hand, the diversity of the energy markets poses challenges in directly reusing existing solutions. Each project must commence from scratch, including deploying a blockchain network, designing smart contracts, and developing the front-end web application. This challenge hinders the widespread adoption of blockchain-based P2P-ET systems globally. To address this challenge, we have devised a unified and extensible blockchain-based P2P-ET framework. The performant and versatile Enterprise Ethereum client Hyperledger Besu is selected to construct the blockchain infrastructure. Its modular design facilitates the integration of various consensus algorithms, including Proof of Work (PoW), Proof of Stake (PoS), and Prof of Authority (PoA), i.e., Clique, IBFT2.0, and QBFT. Microservices have been implemented to ensure the system's reliability. The objective of this framework is to empower developers to swiftly create localized P2P-ET systems and explore the potential of blockchain technology in fostering sustainable and efficient energy management practices. The main contributions of this work are summarized as follows:  
* We propose a novel unified blockchain-based P2P-ET framework that facilitates diverse energy trading markets at distribution and end-user levels. It enables developers to plug in customized market rules and swiftly create localized P2P-ET systems. * Using the proposed framework, we create modular smart contracts based on a local energy market mechanism and build a decentralized application for P2P-ET in the Alberta wholesale market. * We conduct a case study using real data from the AESO to demonstrate the feasibility and efficiency of the proposed BPET system. The remainder of this paper is organized as follows. In Section 2, we review the related work on blockchain-based P2P-ET.