CE-SDT: A new blockchain-based distributed community energy trading mechanism

With the spread of distributed renewable energy, residents are shifting from being mere consumers to being energy producers and consumers. This role shift poses challenges to the electricity trading mechanism that connects distributed renewable energy sources to the grid. In this paper, a new efficient and secure blockchain-based distributed community energy trading mechanism is proposed, called CE-SDT. Our system is proved to be stable and scalable. It can also help shift loads and power peaks and reduce customer costs by 60%. As a result, our proposed blockchain-based trading mechanism, as compared to the centralized trading mechanism, is applied to microgrids formed by distributed renewable energy sources, not only obtaining greater economic benefits but also reducing the carbon footprint of residents, and furthermore, it promotes low or zero-carbon configurations of the power system, thereby achieving certain environmental benefits.

Neighboring energy trading enables energy transfer and transactions in the neighborhood to achieve greater economic benefits (Logenthiran et al., 2012). This microgrid, which integrates the distributed load and power generation, can minimize the loss of electrical energy and achieve cost reduction. Likewise, it can reduce greenhouse gas emissions, achieve a low or zero-carbon configuration of the power system, and reduce the carbon footprint in the production and management of energy (Hanna et al., 2017;Du et al., 2019;Su et al., 2021). To fully realize the economic and environmental benefits of microgrids, it is critical to establish an efficient power trading mechanism to integrate environmentally friendly, reliable, and flexible distributed renewable energy into the power grid.
The traditional power trading model uses a centralized approach by establishing a centralized trusted third party (TTP) to control the collection and exchange of the entire transmission data (Yang and Wang, 2016). However, great amounts of work have indicated the weakness behind it. For instance, the unified and centralized management of trading networks is similar to other centralized computing solutions, which leads to a series of privacy and security challenges (Aitzhan and Svetinovic, 2018). The electricity consumption behaviors of users and trading price ranges are easily eavesdropped on by attacking the control center (Niyato et al., 2011). Also, it is difficult to adapt to the large-scale utilization of renewable energy in the unified management (Lu et al., 2019). Furthermore, the renewable energy supply differs from the traditional long-term generation trading with fixed characteristics. There is the uncertainty of generation and time-sharing trading (Jiawei et al., 2018). Decentralized energy management solutions based on the blockchain technology are gaining attention to address these issues and better realize the economic and environmental benefits of microgrids.
The decentralized, asymmetric encryption and smart contract applications that characterize blockchains have great potential in many areas, such as finance, computer applications, and resource monetization (Ali et al., 2019;Li et al., 2021). Similarly, the blockchain technology holds great promise for applications in the energy sector. Yinan et al. (2019) proposed a new type of network innovation architecture of software-defined networking based on blockchain computing. By separating all control commands and operations of the energy internet, the system becomes more flexible. The blockchain helps peer-to-peer (P2P) interactions in the electricity market and reduces the threshold of the local retailer participation (S, 1963). Yorozu et al. (1987) studied the conversion problems between the virtual currency and the real currency, when traded in a blockchain. A credit-based payment scheme can be established to enable users to manage and transfer energy coins. Blockchains are also widely used in the energy industry in the area of carbon quotas (Hua and Sun, 2019;Hua et al., 2020;Yuan et al., 2021).
The use of blockchains in decentralized energy management is also being demonstrated. Based on the advantages of the blockchain technology, Li and Li (2019) proposed a microgrid management scheme that incorporates the demand for electric vehicles. Fan et al. (2018) used the blockchain technology to explore the issues of trading and valuation of the energy internet and provided useful references for producers, consumers, and regulators as participants. Pipattanasomporn et al. (2018) implemented a blockchain networkbased solar energy exchange project in their laboratory. Hou et al. (2019) created a system that allows nodes to use locally stored power to meet their own power load before participating in the trading market as sellers while still having a large amount of power. There are also studies that have established P2P energy trading platforms based on a blockchain. Alcarria et al. (2018) proposed an empowerment platform based on the blockchain technology to facilitate the exchange of information and the transaction of resources within the community. Park et al. (2018) designed and simulated a blockchain-based P2P energy trading platform and compared the economic benefits of the platform with those of traditional power generation companies based on the simulation results. In the long run, the blockchain-based P2P energy trading platform can lead to a secure, energy-efficient, trustworthy, and sustainable energy trading environment.
However, for community-oriented distributed energy trading mechanisms, there are still gaps between theory and practical applications.
• The sheer volume of data and limited computing resources make it difficult to meet the demand and work properly. • Although the concept of a decentralized system has been developed, the bid trade mechanism among local producers and consumers is still being ignored. In the neighborhood trade event, individuals would bid simultaneously; so, detailed regulations need to be provided in bid operations.
In this paper, we propose a blockchain-based secure distributed trading (SDT) mechanism that enables individuals in a community to trade energy in a distributed manner, called community energy (CE)-SDT. The smart contract is adopted in CE-SDT to ensure confidentiality, authenticity, incontestability, and integrity of the shared information. Through simulation, we analyze different scales of residential users from the generation side to determine whether the installation of solar panels, batteries, and smart contract-based trading systems increase the smartness and selfsufficiency of these homes and businesses. This will help reduce the carbon footprint of households and bring some economic benefits. This paper offers the following contributions: • A new blockchain-based secure distributed trading framework is designed to connect households and the grid using smart contracts to automate bidding and decision-making to enable the energy exchange. • An energy management model is developed to determine the appropriate sell/buy strategy, optimizing the amount of individual value and shifting the system peak demand. • Our CE-SDT is shown to be stable and scalable. It can also help shift loads and power peaks and reduce customer costs.
The remaining parts of this paper are summarized as follows: Section 2 describes the system structure and workflow of CE-SDT; Section 3 describes the energy management model. Section 4 shows the deployment of CE-SDT in simulation and discusses the simulation results. Section 5 draws conclusions and looks forward to future research.

System structure
The CE-SDT trading prototype considered in this paper comprises multiple autonomous residential buildings, which actively respond to Frontiers in Energy Research frontiersin.org demand-side management signals and utilize the user-side energy.
There is a regional smart contract that performs the entire energy management in trading and transformation. The control architecture of the proposed system is shown in Figure 1. In the residential end, some smart buildings are equipped with a rooftop PV solar source and a battery energy storage system (BESS). The BESS is used to accommodate solar power and provide power for domestic use. It may also store the extra solar panel or get cheap power from the grid for future usage. The smart meter is installed in every home, taking the role of a communication agent between the smart contract and the home. A home energy management system (HEMS) is deployed in a smart home, managing home energy resources, including solar penetration data, some electrical appliances, and BESS. It communicates with the smart meter, home energy resources, and smart contract, and it also interacts with the user. When trading happens, the HEMS collects information about the forecasted personal power usage, real-time pricing data from the grid, and real-time personal solar generation data.
When residential trading happens, the HEMS obtains bidding information from the regional smart contract. Simultaneously, it forecasts the load consumption profile in the next stage duration and submits the forecasting excrescent/missing load profiles to the smart contract for selling/buying. Based on this concept, the smart contract sets up an optimal energy management model to determine the proper selling/buying strategy, optimizing the amount of individual value and the shifting system peak demand.
At the simulation level, our model works in the flow, as shown in Figure 2.
(1) The user makes a request to the smart contract, indicating the required electricity consumption and bidding method.
(2) The smart contract confirms the grid power price and gives a suggested price based on the recently traded price (the model is shown in Section 3.3).
(3) It determines whether users request bidding.
(3.1) No bidding, supply power directly from the grid and shift to 9.
(3.2) Requires bidding, shift to 4. (4) The smart contract broadcasts user requests to other user nodes with power generation capabilities. (5) After receiving a request, the supply user node determines the amount of power that can be provided. It then autonomously provides an offer to the smart contract based on the suggested price. (6) The smart contract keeps accepting offers from supply nodes until timeout. (7) It sorts the prices in the offers. (8) It accepts offers in order and gives feedback to supply nodes.
(6.1) The power in the accepted offers has met the customer's demand.
(6.2) If all offers have been accepted and the power still does not meet the customer's demand, then the remaining demand will be provided by the grid. Frontiers in Energy Research frontiersin.org (9) The smart contract calculates the bill and supplies the power to the requested customer.
Following the system schematic representation presented upon, in this section, we first illustrate the generic CE-SDT models; then, we formulate the proposed HEMS with different kinds of operational dependencies due to living habits, which are considered as an additional constraint of the CE-SDT-based real-time trading model.

Model
In this section, we introduce the main models in the CE-SDT system, including the user classification, power generation model, and bidding model. These models define and constrain behavior patterns of users in the system.

Generic classification of resident users
Consider residential units with N controllable users and denote the set of users as Ω, i.e., |Ω| N. The controllable users are further categorized into the following sets based on their operational characteristics: Ω 1 : Set of users operating with the power in the range of [P a min , P a max ], a ∈ Ω 1 but without the energy generation ability. In addition to that, a disutility function is applied to measure the dissatisfaction of the user on deviating from a nominal operating point. Typical users in this set consume but do not generate electricity.
Ω 2 : Set of users generating power in the range of [P a min , P a max ], a ∈ Ω 2 and having a prescribed energy consumption that must be completed in a specific time range. Typical users in this class equip a battery energy storage system (BESS) and generate electricity that they can supply to themselves and other residents.

Residential photovoltaic solar power models
The power output from the PV solar panel is related to solar radiation, the panel's surface area, and the energy conversion efficiency of the panel, expressed as follows: where P pv t denotes the solar power output at time t (kW); A is the surface area of the PV solar panel (m 2 ), and σ defines the energy conversion efficiency of the PV solar panel (%); and r t is the solar radiation at time t (kW/m 2 ).

Energy bidding models
Denote the energy consumption schedule for each controllable user as follows: P k P k,1 , P k,2 , . . . , P k,T ∀k ∈ Ω.
( 2 ) The power consumption schedule of N controllable appliances can then be represented as a matrix with N × T dimensions, where the entry P a,t represents the power consumption of an appliance a at the time interval t. The net-power consumption of the home can be correspondingly represented as follows: P h t P mr t + i∈Ω P k,t − P pv t t 1: T, where P mr t is the must-run home load at time t (W).

FIGURE 2
Energy trading workflow.
Frontiers in Energy Research frontiersin.org

Objective
The objective of the proposed energy bidding model in this study is to realize the energy self-arrangement of the demand side. All bid strategies will be decided and recorded in the smart contract, and the selling/buying prices will be arranged from high to low.
where p S denotes the selling price determined by the smart contract. There are two components in the model. The first is the redundant energy generated by the users, Ω 2 , at time t; the second is the average bidding price. λ and μ are different weighting coefficients.
where p B denotes the buying price determined by the smart contract. The first component is the user requirement energy at time t; the second is the average buying price. β and ] are different weighting coefficients.

Mandatory constraints
The energy bidding model is subjected to the following constraints: (1) Operational constraints of users in Ω 2 , i.e., a BESS in this study.
The operation of the BESS must satisfy the following constraints: E ess t+1 E ess t + Δtη c P ess t − E ess t η l Δt P ess t > 0 E ess t − P ess t η d Δt − E ess t η l Δt P ess t ≤ 0 , t 1: T − 1, (7) SOC ess t E ess t E ess,rate t 1: T, P ess t ≤ P ess,rate t 1: T, SOC min ≤ SOC ess t < SOC max t 1: T, SOC ess t ≥ SOC dsr t T.
Equations 7, 8 model the variation of energy stored in the BESS; constraint (9) specifies the BESS's maximum charging/discharging power; constraint (10) ensures that the BESS's SOC is maintained within an allowable range; constraint (11) ensures that the SOC level of the BESS is larger or equal to a pre-specified threshold at the end of the day.
(2) The bidding ranking constraints of users in Ω 2 in this study. The smart contract arranges the selling/buying price as follows: The smart contract will arrange the selling price from low to high and the buying price from high to low, pairing each of them following this sequence. For example, the smart contract will pair p S1 t and p B1 t first and then pair others and so forth. The user node sends a request to the smart contract to ask for power. When receiving the request, the smart contract starts bidding and asks for an offer. Other user nodes who have the capacity to provide the power will reply with an offer to the contract. The smart contract will also ask the power grid for its power price. Then, the smart contract will collect these offers and make decisions.

CE-SDT deployment
We used our own blockchain simulation tool to run early tests on the CE-SDT system. As shown in Table 1, there are several parameters we can change in the simulation.
We obtained some data on power usage from the government publicity. Figure 3 shows the average hourly power usage of 15 different users on 11/2012 in NSW, Australia. We set these 15 users' data as 15 types of user power usage inputs.
After an investigation, the most popular home-use power generator was found to be that with 5 kW. So, we set a default power output as 5 kW. Figure 3 shows the average hourly power generation of three different users with a 5-kW power generator on 11/ 2012 in NSW, Australia. We set these three users' data as three types of user power generation inputs. To fit the generation capacity of users and meet the need of the settlement, we give each user a 5,000-Wh power storage ability to store the power they have generated. The users are disabled to store the power they get from the power grid, but it can be activated in future research.
Since the number of users will be set to more than 15, each user will randomly select one of these 15 types as its input. It is similar to the input selection of the user power generation. Figure 4 shows the average hourly power usage of 15 different users. To differentiate the same type of users, we set a random settlement interval (ST) instead of an hourly interval. The settled power is calculated as follows: This settlement interval will also help us reduce network congestion.
The price of power in November from Energy AU is shown in Table 2.
The solar feed-in tariff is about 10 cents/kWh.

Results
With the definition shown previously, we get the following results: Figure 5 shows the power usage of the system under default settings. The user usage line means the quantity of power that users need from the system, which has already been subtracted from the power generated and used by them. The grid usage line means the quantity of power the grid has provided to users. The gap between the two lines is the power transacted through the bidding system.
As shown in Figure 6, when the number of users increases, the average power that each user needs from the system remains stable. On the other hand, in Figure 7, the average power that the grid provides to each user decreases in the middle of the day. It means that the more the users, the more likely are the transactions to be completed between users and the more the system will be activated. Our system illustrates great scalability. Figure 8 shows that when the percentage of users who have the power generation capacity increases, the power each user needs from the system will decrease from 9 a.m.
As shown in Figure 9, as the percentage rises, the power grid provides a decrease at the high level, which means that we can utilize Frontiers in Energy Research frontiersin.org this to help the grid to conduct peak load shifting at noon. We can also find out that when the percentage is more than 50%, the generation capacity exceeds electricity consumption, which means that some power is wasted. This may be solved by giving users a higher power storage capacity.
In Figure 10, we can find out that, as the percentage rises, the daily power cost has been decreasing, no matter whether the user has the power generation capacity or not. Ω 2 can even earn money when the percentage is up to 70%; at the same time, Ω 1 can reduce the cost to 44.7%. When the percentage is over 30%, Ω 1 in our system can spend less money than Ω 2 in a traditional power system, only 68.3% of the original cost. When half the users have the power generation capacity, the cost for Ω 1 and Ω 2 can be reduced to 60.2% and 19.6%,

FIGURE 3
Power generation types.

FIGURE 4
Power usage types.  Total power usage with default settings.

FIGURE 6
User power usage with different user numbers.

FIGURE 7
Grid power usage with different user numbers.
Frontiers in Energy Research frontiersin.org 07

FIGURE 8
User power needs with different generated user percentages.

FIGURE 9
Grid power usage with different generated user percentages.

FIGURE 10
Average cost with different settings.

Frontiers in Energy Research
frontiersin.org 08 respectively, and 43.1% for all users. It shows that our system can help users reduce their spending on power usage.

Conclusion
Intelligent smart metering facilities and two-way communication infrastructure enable residential buildings to actively generate and trade energy on the demand side. However, the traditional centralized power management mode causes unreliability and lack of privacy in information exchange. Energy losses from inefficient management models produce large amounts of carbon emissions and lead to irreversible changes to the climate. In this study, we propose a privacy-preserving, efficient, and robust distributed energy exchange scheme supported by the smart contract, called CE-SDT. An efficient bidding model is first introduced for the demand side to achieve peer-to-peer trading of electricity in the real-time market. The entire exchanges of data are implemented in the smart contract to guarantee information safety and traceability with a decentralized scheme. The proposed solution achieves reliable and stable trading objects under the premise of information security. We deploy it in the simulation framework to test its feasibility. The result shows that our CE-SDT is stable and extendable. Also, it can help shift the load and peak power usage, thereby reducing costs for users. Even users without the power generation capacity can only pay 44% of the original electricity bill. We conducted a systematic and comprehensive applicability analysis of the proposed mechanism, and it further confirms that the system can be applied in a home energy management system. However, the process of blockchain mining requires a large number of hash operations, and in order to obtain more computational power, traditional blockchain computing requires a large amount of power. In future research, 1) we want to find out a way to conduct the verification work using a power grid bidding system instead of a smart contract. 2) We hope to change the way the blockchain reaches consensus. There can be a local division in the power grid itself, and the blockchain will reach a consensus in the region first and then send the results of the local consensus to the whole network for verification. In this way, we can make use of the surplus power in the power grid for mining and realize peak load shifting by transferring the consensus area. 3) We hope to continue to incorporate carbon quotas into our proposed blockchain-based distributed trading mechanisms to enable residents to directly obtain active incentives to reduce carbon emissions, thereby realizing greater environmental benefits.

Data availability statement
The datasets presented in this study can be found in online repositories. The names of the repository/repositories and accession number(s) can be found in the article/Supplementary Material.