A p2p energy transaction method based on smart contract

By using a P2P energy trading method based on smart contracts and combining it with blockchain technology, the problems of centralization and inefficiency in the energy trading market have been solved, achieving decentralized, automated, and efficient energy trading, and optimizing user satisfaction measurement.

CN114841813BActive Publication Date: 2026-07-31NORTH CHINA ELECTRIC POWER UNIV +2
View PDF 3 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
NORTH CHINA ELECTRIC POWER UNIV
Filing Date
2022-05-18
Publication Date
2026-07-31

AI Technical Summary

Technical Problem

The existing energy trading market suffers from centralization, untrustworthy third-party intermediaries, inefficiency in traditional energy trading, cumbersome settlement processes, and an inability to measure user satisfaction, leading to instability and resource waste.

Method used

This approach employs a P2P energy trading method based on smart contracts, combined with blockchain technology, to achieve decentralized transactions between producers and consumers. It utilizes smart contracts to automate and record transactions, optimizes the transaction process through PC-DA and clearing mechanisms, and sets user feedback values ​​to measure user satisfaction.

Benefits of technology

It enables decentralized energy trading, improves trading efficiency, reduces transmission losses, saves manpower and resources, ensures trading security, allows for the measurement of user satisfaction, and reduces transaction costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114841813B_ABST
    Figure CN114841813B_ABST
Patent Text Reader

Abstract

This invention discloses a P2P energy trading method based on smart contracts. First, a P2P energy trading model between producers and consumers based on smart contracts is constructed. Then, PC-DA is used to conduct P2P energy transactions between producers and consumers, generating transaction orders. The generated transaction orders are automatically cleared under the smart contract. After the transaction orders are matched, the feedback values ​​of all producers and consumers participating in this round of transactions are calculated, and user feedback analysis is performed. Finally, the generated transaction orders are packaged into blocks, which are then propagated in the network. After consensus is reached by consensus nodes, the block is added to the blockchain for processing. This invention combines blockchain with P2P energy trading, leveraging the advantages of blockchain to promote the consumption of clean energy and realize the automated execution of P2P energy transactions between producers and consumers under smart contracts, thus helping to improve energy trading efficiency and reduce costs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of energy trading technology, and in particular to a P2P energy trading method based on smart contracts. Background Technology

[0002] With increasing economic prosperity and rising living standards, energy consumption continues to grow, posing a risk of shortages and highlighting a severe imbalance between energy consumption and supply. The emergence and efficient utilization of renewable energy sources (such as solar, wind, and hydropower) have alleviated some of the energy consumption and shortage issues. Renewable energy will play a significant role in meeting the growing global energy demand. However, the intermittency and transmission losses caused by the increasing use of solar and wind power have introduced instability into the energy trading market. Microgrids aim to ensure a balance in energy supply, and the emergence of prosumers facilitates the absorption of renewable energy sources such as solar and wind power. Nevertheless, existing energy trading methods still have the following drawbacks:

[0003] 1) Traditional energy trading markets adopt a centralized management model, which involves third-party intermediaries, thus creating a centralization problem. In this case, it is essential to ensure the credibility of these third-party intermediaries. If a third-party intermediary engages in malicious operations, it will be impossible to restore energy trading information, which will cause irreversible damage to the energy trading market.

[0004] 2) In the traditional energy trading market, traditional energy is the main source, which has led to a significant reduction in traditional energy and caused certain environmental pollution. Meanwhile, the intermittency and transmission loss caused by renewable energy have brought instability to the energy trading market. Therefore, it is urgent to find a way to absorb renewable energy locally while ensuring the relevant benefits of the participants.

[0005] 3) The settlement process after the end of energy trading generally requires the participation of professionals such as banks. The workload is tedious, which wastes a lot of human and material resources. The possibility of errors is relatively large, resulting in low work efficiency. How to conduct settlement after trading faster, more accurately and more efficiently is also one of the problems we are currently facing.

[0006] 4) At present, no in-depth survey has been conducted on the satisfaction level of the participants after the energy transaction ended, and the participants' satisfaction level with this round of transactions is not understood. This is not conducive to the future development of the energy trading market. How to measure the participants' satisfaction with energy transactions is also one of the key issues that should be focused on at present. Summary of the Invention

[0007] The purpose of this invention is to provide a P2P energy trading method based on smart contracts, which combines blockchain with energy P2P trading, leverages the advantages of blockchain, addresses the problems existing in the current energy trading market, promotes the consumption of clean energy, and realizes automated execution of P2P energy transactions between producers and consumers under smart contracts, thereby helping to improve energy trading efficiency and reduce costs.

[0008] To achieve the above objectives, the present invention provides the following solution:

[0009] A P2P energy trading method based on smart contracts includes the following steps:

[0010] S1, for transactions within the microgrid, calls the smart contract function to register the microgrid with the number id, and registers users, namely prosumers and consumers, under the microgrid. At the same time, the microgrid and users are initialized, and a P2P energy trading model between prosumers and consumers based on smart contracts is constructed.

[0011] S2, the P2P energy trading model between prosumers and consumers uses PC-DA to conduct P2P energy transactions between prosumers and consumers and generate transaction orders;

[0012] S3 automatically clears generated transaction orders under smart contracts;

[0013] S4. After the transaction order is matched, calculate the feedback values ​​of all producers and consumers who participated in this round of transactions, and conduct user feedback analysis.

[0014] S5: After the specified time has elapsed, the node responsible for packaging will package the generated transaction orders into blocks. The blocks will then be propagated in the network. Once the consensus nodes reach a consensus, the blocks will be added to the blockchain for processing. At this point, the transaction round is complete.

[0015] Further, in step S1, for transactions within the microgrid, a smart contract function is invoked to register the microgrid with the ID id, and users, i.e., prosumers and consumers, are registered under this microgrid. Simultaneously, the microgrid and users are initialized, constructing a P2P energy trading model between prosumers and consumers based on a smart contract. Specifically, this includes:

[0016] Let the energy selling price and purchase price of the microgrid with ID id be SP, respectively. id BP id And let the microgrid ID be determined by m. id Individual consumers, n id Composed of individual consumers, prosumers use a set Consumers use sets They represent producers and consumers respectively. The selling price and the quantity of energy sold, where i = 1, 2, ..., m; They represent consumers respectively. The purchase price and the quantity of energy purchased, where j = 1, 2, ..., n.

[0017] Furthermore, in step S2, the P2P energy trading model between prosumers and consumers uses PC-DA to conduct P2P energy transactions between prosumers and consumers, generating transaction orders, specifically including:

[0018] Producers and consumers Publish by calling smart contract functions and Then the sorting rules are automatically triggered, according to... Sort the items from lowest to highest and add them to the sales array;

[0019] Meanwhile, consumers Publish by calling smart contract functions and And determine consumers Are there enough tokens to purchase? If there are enough tokens, the energy will automatically trigger the sorting rule, according to... Sort the items from highest to lowest and add them to the purchase array; otherwise, reject the purchase request. Participating in this round of energy trading;

[0020] A transaction order is generated by matching the sell array with the buy array one-to-one if the conditions are met.

[0021] Furthermore, the step of matching the sell array and the buy array one-to-one, and generating a transaction order if the conditions are met, specifically includes:

[0022] Determine whether the selling price and energy quantity of the first element of the array being sold satisfy the requirements of the buying price and energy quantity of the first element of the array being purchased, i.e., whether they are simultaneously satisfied. and

[0023] The two parties that meet the requirements form a matching transaction order, and then the process is iterated until the conditions are no longer met. The remaining unmatched users then transact with the microgrid operator.

[0024] Furthermore, step S3, which involves automatically clearing the generated transaction orders under the smart contract, specifically includes:

[0025] S301 uses the ERC20 smart contract standard as its basic protocol and converts tokens and energy prices using exchange rates. The average price and mixed price both refer to real-world currencies. Before settlement, tokens must be exchanged. The exchange mechanism is shown in equation (1):

[0026] token = token_rate * price (1)

[0027] In the formula, token represents a token, token_rate represents the exchange rate, and price represents the currency;

[0028] S302 sets the average price settlement mechanism to a 1-hour timeframe. Under this method, P2P energy transactions conclude using average price settlement. When the producer's bid and the consumer's bid are the same, the average price equals both. When the producer's bid is higher than the consumer's bid, a matching order cannot be formed. When the producer's bid is lower than the consumer's bid, settlement is based on the average price of the two. The average price... refers to producers and consumers of With consumers of The average of the two is shown in equation (2):

[0029]

[0030] S303 sets the hybrid price settlement mechanism to 1 hour. Under this method, P2P energy transactions conclude with hybrid price settlement, benefiting both producers and consumers. With consumers Mixed prices of transactions As shown in equation (3):

[0031]

[0032] Furthermore, in step S4, after the transaction orders are matched, the feedback values ​​of all prosumers and consumers participating in this round of transactions are calculated, and user feedback analysis is performed, specifically including:

[0033] S401, Prosumer Revenue Calculation: Prosumer As the producer's income As shown in equation (4):

[0034]

[0035] In the formula, These represent the producers and consumers under the microgrid ID. With consumers The amount of energy traded by microgrid operators; p ij Indicates producer-consumer With consumers The transaction price; the relationship between energy output and equipment expenditure is described using the ln function;

[0036] S402, Consumer Benefit Calculation: Consumer Benefits As shown in equation (5):

[0037]

[0038] In the formula, Consumers Benefits from energy purchases; They represent consumers respectively. The efficiency coefficient; These represent consumers under the microgrid ID. With producers and consumers The quantity of energy traded by microgrid operators; a quadratic function is used to describe the relationship between consumers' energy purchases and the resulting benefits, and... Consumers Benefit factors;

[0039] S403, Prosumer Feedback Value Calculation: Prosumer Feedback Value Feedback value As shown in equation (6):

[0040]

[0041] In the formula, They represent producers and consumers respectively. Price feedback value, energy trading volume feedback value, and revenue feedback value; Represents the preference coefficient;

[0042] S404, Consumer Feedback Value Calculation: Consumer Feedback value As shown in equation (7):

[0043]

[0044] In the formula, They represent consumers respectively. Price feedback value, energy trading volume feedback value, and revenue feedback value; This represents the preference coefficient.

[0045] According to specific embodiments provided by the present invention, the present invention discloses the following technical effects: The P2P energy trading method based on smart contracts provided by the present invention uses blockchain smart contracts as an important component of P2P energy trading, playing a very important role in transactions between producers and consumers, and bringing a series of advantages to P2P energy trading:

[0046] 1) Traditional power grid transactions require a fully trustworthy third-party intermediary as the transaction center. However, this invention uses blockchain and smart contracts to enable nodes that join the blockchain to trust each other unconditionally, thus achieving decentralization.

[0047] 2) P2P energy trading between producers and consumers can not only absorb renewable energy locally and reduce losses during transmission, but also bring greater benefits to producers and consumers compared to traditional energy trading models.

[0048] 3) Deploying the P2P energy trading model on smart contracts allows users with trading needs to register and join the energy trading platform, post their own needs, and simply wait for the smart contract to match them without human intervention, saving a lot of manpower, material resources, and financial resources.

[0049] 4) The automatic settlement function saves a lot of time, and both parties to the transaction do not need to worry about non-payment for energy or inability to use energy after payment;

[0050] 5) Setting user feedback values ​​in smart contracts to measure user satisfaction with the transaction can help microgrid operators better understand users' energy trading activities.

[0051] 6) Transaction orders are ultimately stored on the blockchain. The characteristics of the blockchain make transaction information tamper-proof, and all users can easily and promptly trace related information. Attached Figure Description

[0052] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0053] Figure 1 This is a flowchart illustrating the P2P energy trading method based on smart contracts according to an embodiment of the present invention.

[0054] Figure 2 This is a diagram of a P2P energy trading framework based on smart contracts, according to an embodiment of the present invention. Detailed Implementation

[0055] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0056] As an emerging distributed ledger, blockchain possesses characteristics such as transparency, decentralization, immutability, and traceability, which help improve energy trading efficiency and reduce costs. Currently, the energy trading market adopts a peer-to-peer (P2P) energy trading model. Combining blockchain with P2P energy trading can leverage the advantages of blockchain, address existing problems in the energy trading market, promote the consumption of clean energy, and automate P2P energy transactions between producers and consumers under smart contracts. Therefore, the purpose of this invention is to conduct research on energy trading between producers and consumers in the context of microgrids, and, with the assistance of blockchain smart contracts, attempt to propose a P2P energy trading method based on smart contracts.

[0057] In blockchain, a smart contract is a collection of code deployed on the blockchain that runs according to pre-defined logical rules. Currently, the main application platforms for smart contracts are Ethereum and Hyperledger Fabric. Ethereum, as the earliest platform to use smart contracts, has a relatively mature development and uses the Solidity language to write smart contracts. The Ethereum Virtual Machine (EVM), as the runtime environment for smart contracts, isolates them from external factors, thus playing a positive role in the operation of smart contracts. In Hyperledger Fabric, smart contracts are also called "chaincode," and are mainly written in languages ​​such as Go, Java, and Node.js. As a representative of consortium blockchains, Hyperledger Fabric has certain access controls for node joining.

[0058] As a regional power grid, microgrids provide support for the consumption of renewable energy. This invention will focus on microgrids and conduct peer-to-peer (P2P) energy trading. P2P energy trading in microgrids is mainly divided into internal microgrid energy trading and external microgrid energy trading. Participants in internal microgrid energy trading include microgrid operators, prosumers, and consumers. Prosumers and consumers are referred to as users. Participants in external microgrid energy trading are the microgrid operators of each microgrid. This study primarily considers internal microgrid trading; unless otherwise specified, all transactions described below are internal microgrid transactions.

[0059] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0060] like Figure 1 As shown, the P2P energy trading method based on smart contracts provided by this invention includes the following steps:

[0061] S1, for transactions within the microgrid, calls a smart contract function to register the microgrid with the ID id, and registers users (prosumers and consumers) under this microgrid. Simultaneously, it initializes the microgrid and users, constructing a P2P energy trading model between prosumers and consumers based on a smart contract; specifically including:

[0062] Let the energy selling price and purchase price of the microgrid with ID id be SP, respectively. id BP id And let the microgrid ID be determined by m. id Individual consumers, n id Composed of individual consumers, prosumers use a set Consumers use sets They represent producers and consumers respectively. The selling price and the quantity of energy sold, where i = 1, 2, ..., m; They represent consumers respectively. The purchase price and the quantity of energy purchased, where j = 1, 2, ..., n;

[0063] S2, the P2P energy trading model between prosumers and consumers uses PC-DA to conduct P2P energy transactions between prosumers and consumers and generate transaction orders;

[0064] S3 automatically clears generated transaction orders under smart contracts;

[0065] S4. After the transaction order is matched, calculate the feedback values ​​of all producers and consumers who participated in this round of transactions, and conduct user feedback analysis.

[0066] S5: After the specified time has elapsed, the node responsible for packaging will package the generated transaction orders into blocks. The blocks will then be propagated in the network. Once the consensus nodes reach a consensus, the blocks will be added to the blockchain for processing. At this point, the transaction round is complete.

[0067] Price-constrained double-sided auctions (PC-DA) incorporate price limits into two-way auctions, preventing users from participating in energy transactions with bids exceeding the limit. Within a microgrid, PC-DA is used for peer-to-peer (P2P) energy transactions between prosumers and consumers. PC-DA considers both bids from both parties and the quantity of energy. Prosumers are divided into three categories: Category 1 produces energy entirely for their own use; Category 2 produces energy for their own use and sells any surplus energy; and Category 3 produces energy for their own use and sells all of it. If all prosumers within the microgrid engage in P2P energy transactions as consumers, then PC-DA will only generate consumer orders, and no matching orders will be generated. If some or all prosumers within the microgrid engage in P2P energy transactions as producers, then PC-DA will involve both producers and consumers, potentially generating matching orders. Therefore, this invention assumes that the prosumers within the microgrid are Category 2 prosumers, meaning they consume energy for their own use while also selling surplus energy as producers, thus participating in energy transactions. Prosumers are divided into three categories: Category 1 users consume all energy themselves; Category 2 users sell surplus energy in addition to their own consumption; and Category 3 users sell all energy. Assuming that the prosumers within the microgrid are Category 2 users, they consume energy themselves while also acting as producers, selling surplus energy and participating in energy trading.

[0068] In step S2 of this invention, the P2P energy trading model between prosumers and consumers uses PC-DA to conduct P2P energy transactions between prosumers and consumers, generating transaction orders, specifically including:

[0069] Producers and consumers Publish by calling smart contract functions and Then the sorting rules are automatically triggered, according to... Sort the items from lowest to highest and add them to the sales array;

[0070] At the same time, consumers call smart contract functions release and And determine consumers Are there enough tokens to purchase? If there are enough tokens, the energy will automatically trigger the sorting rule, according to... Sort the items from highest to lowest and add them to the purchase array; otherwise, reject the purchase request. Participating in this round of energy trading;

[0071] Based on a one-to-one matching of the sell array and the buy array, a transaction order is generated if the conditions are met. Specifically, this includes:

[0072] Determine whether the selling price and energy quantity of the first element of the array being sold satisfy the requirements of the buying price and energy quantity of the first element of the array being purchased, i.e., whether they are simultaneously satisfied. and

[0073] The two parties that meet the requirements form a matching transaction order, and then the process is iterated until the conditions are no longer met. The remaining unmatched users then transact with the microgrid operator.

[0074] The choice of clearing mechanism determines the transaction price between the two parties. Microgrid operators can decide on the clearing mechanism for their microgrids. To study the impact of different clearing mechanisms on user feedback values, two clearing mechanisms were tested: the average price clearing mechanism and the hybrid price clearing mechanism.

[0075] In this invention, step S3, which involves automatically clearing the generated transaction orders under a smart contract, specifically includes:

[0076] S301 uses the ERC20 smart contract standard as its basic protocol and converts tokens and energy prices using exchange rates. The average price and mixed price both refer to real-world currencies. Before settlement, tokens must be exchanged. The exchange mechanism is shown in equation (1):

[0077] token = token_rate * price (1)

[0078] In the formula, token represents a token, token_rate represents the exchange rate, and price represents the currency;

[0079] S302 sets the average price settlement mechanism to a 1-hour timeframe. Under this method, P2P energy transactions conclude using average price settlement. When the producer's bid and the consumer's bid are the same, the average price equals both. When the producer's bid is higher than the consumer's bid, a matching order cannot be formed. When the producer's bid is lower than the consumer's bid, settlement is based on the average price of the two. The average price... refers to producers and consumers of With consumers of The average of the two is shown in equation (2):

[0080]

[0081] S303, the mixed price (Mp) refers to a price derived by comprehensively considering the bids from prosumers, consumers, and the microgrid price. This price indicates that it is related not only to the bids from prosumers and consumers but also to the selling and purchasing prices of the microgrid operator. The mixed price settlement mechanism is set for one hour. Under this method, P2P energy transactions conclude using mixed price settlement. With consumers Mixed prices of transactions As shown in equation (3):

[0082]

[0083] In step S4, after the transaction orders are matched, the feedback values ​​of all producers and consumers participating in this round of transactions are calculated, and user feedback analysis is performed, specifically including:

[0084] S401, Prosumer Revenue Calculation: Prosumers, as a special type of user in microgrids, produce and consume energy themselves while selling surplus energy to other users. Therefore, a prosumer's revenue as a producer includes income from selling energy to users within the microgrid, revenue from the microgrid operator, and expenditures on related equipment. A prosumer's revenue as a consumer is the same as that of a regular consumer, specifically referring to consumer revenue; Prosumer M iid As the producer's income As shown in equation (4):

[0085]

[0086] In the formula, These represent the producers and consumers under the microgrid ID. With consumers The amount of energy traded by microgrid operators; p ij Indicates producer-consumer With consumers The transaction price; the expenditure of producers and consumers on related equipment cannot be measured with precise values ​​due to its special nature. Therefore, the ln function is used to describe the relationship between energy output and equipment expenditure.

[0087] S402, Consumer Revenue Calculation: Consumers, as ordinary users of a microgrid, can only purchase energy and cannot produce it; consumer revenue includes the benefits gained from purchasing energy and the expenditure on purchasing energy from prosumers or microgrid operators. Consumer Benefits As shown in equation (5):

[0088]

[0089] In the formula, Consumers Benefits from energy purchases; They represent consumers respectively. The efficiency coefficient; These represent consumers under the microgrid ID. With producers and consumers The quantity of energy traded by microgrid operators; due to varying energy preferences among consumers, the benefits of purchasing the same energy may differ. For ease of calculation, a quadratic function is used to describe the relationship between energy purchases and resulting benefits, and... Consumers Benefit factors;

[0090] S403, User Feedback refers to the level of satisfaction among users participating in P2P energy trading after the conclusion of a particular trading round. User feedback includes two categories: prosumer feedback and consumer feedback. Both prosumer and consumer feedback are further divided into three parts: price feedback, energy transaction volume feedback, and revenue feedback. Prosumer feedback value calculation: Prosumer... Feedback value As shown in equation (6):

[0091]

[0092] In the formula, They represent producers and consumers respectively. Price feedback value, energy trading volume feedback value, and revenue feedback value; This represents the preference coefficient.

[0093] S404, Consumer Feedback Value Calculation: Consumer Feedback value As shown in equation (7):

[0094]

[0095] In the formula, They represent consumers respectively. Price feedback value, energy trading volume feedback value, and revenue feedback value; This represents the preference coefficient.

[0096] Finally, user feedback is categorized into four levels: very satisfied, satisfied, generally satisfied, and dissatisfied. A lower user feedback score indicates a higher level of satisfaction with the transaction.

[0097] Based on the construction of the P2P energy trading model in step S1, and its integration into a blockchain smart contract, automatic transaction settlement and user feedback value measurement are achieved. The P2P energy trading framework based on smart contracts is shown in the diagram below. Figure 2 As shown.

[0098] The P2P energy trading model based on smart contracts provided by this invention is mainly divided into the following five core functions: creation, trading, feedback, query, and settlement.

[0099] Registration: The registration function refers to registering microgrids, prosumers, and consumers. Microgrid registration can only be completed by the contract creator, who must specify the microgrid operator address. Prosumer and consumer registration are collectively referred to as user registration, which must also be completed by the contract creator. When registering a user, the user type (prosumer or consumer), the affiliated microgrid number, and the user address must be specified. During microgrid registration, the system should check if the microgrid exists. If it exists, a "microgrid exists" flag is returned; otherwise, the microgrid is initialized. Similarly, during user registration, the system should check if the affiliated microgrid and the user exist. If the affiliated microgrid does not exist or the user already exists, a "microgrid does not exist" or "user already exists" flag is returned; if both exist, the user is initialized.

[0100] Trading: The trading function refers to the transactions between participating entities, mainly including transactions between prosumers, between prosumers and consumers, between prosumers and microgrid operators, and between consumers and microgrid operators. Within the microgrid, prosumers and consumers publish the quantity and price of energy they sell and buy, and transaction orders are matched according to the PC-DA principle. Prosumers and consumers can engage in energy transactions with microgrid operators in situations of oversupply or undersupply in the P2P energy trading market, with transaction prices set by the microgrid operator.

[0101] Feedback: The feedback function refers to the level of satisfaction among prosumers or consumers who complete a round of P2P energy transactions based on matched orders during the microgrid's internal trading process. Satisfaction is measured using feedback values, which are then fed back to the microgrid operator after the transaction is completed. The microgrid operator can view the feedback values ​​of all users.

[0102] Inquiry: The inquiry function allows all participants to query information related to energy trading, including the selling and purchasing prices of microgrid operators, user feedback values, the quantity and price of energy purchased and sold by participants, and matching transaction orders.

[0103] Settlement: The settlement function refers to the automatic settlement of transactions after completion, whether within or outside the microgrid, according to a prescribed settlement mechanism, after which the amount is converted into tokens. This invention's energy settlement operates on a "use first, pay later" basis. Before a participant auctions energy, the smart contract automatically checks whether the participant's balance is sufficient to pay based on the quantity of energy purchased. If the balance is insufficient, participation in energy trading is prohibited; if the balance is sufficient, participation is allowed, and the corresponding tokens are frozen. The payment process for energy transactions is automatically completed by the smart contract, therefore, there is no issue of participants using energy without paying or having insufficient energy balances.

[0104] The P2P energy trading method based on smart contracts provided by this invention uses blockchain smart contracts as an important component of P2P energy trading, playing a crucial role in transactions between producers and consumers, and bringing a series of advantages to P2P energy trading:

[0105] 1) Traditional power grid transactions require a fully trustworthy third-party intermediary as the transaction center. However, this invention uses blockchain and smart contracts to enable nodes that join the blockchain to trust each other unconditionally, thus achieving decentralization.

[0106] 2) P2P energy trading between producers and consumers can not only absorb renewable energy locally and reduce losses during transmission, but also bring greater benefits to producers and consumers compared to traditional energy trading models.

[0107] 3) Deploying the P2P energy trading model on smart contracts allows users with trading needs to register and join the energy trading platform, post their own needs, and simply wait for the smart contract to match them without human intervention, saving a lot of manpower, material resources, and financial resources.

[0108] 4) The automatic settlement function saves a lot of time, and both parties to the transaction do not need to worry about non-payment for energy or inability to use energy after payment;

[0109] 5) Setting user feedback values ​​in smart contracts to measure user satisfaction with the transaction can help microgrid operators better understand users' energy trading activities.

[0110] 6) Transaction orders are ultimately stored on the blockchain. The characteristics of the blockchain make transaction information tamper-proof, and all users can easily and promptly trace related information.

[0111] This document uses specific examples to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. Furthermore, those skilled in the art will recognize that, based on the ideas of the present invention, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1.A method for peer-to-peer (P2P) energy transaction based on a smart contract, characterized in that, Includes the following steps: S1, for transactions within the microgrid, calls the smart contract function with the registration number [not specified]. id The microgrid is established, and users, namely prosumers and consumers, are registered under the microgrid. At the same time, the microgrid and users are initialized, and a P2P energy trading model between prosumers and consumers based on smart contracts is constructed. S2, the P2P energy trading model between prosumers and consumers uses PC-DA to conduct P2P energy transactions between prosumers and consumers and generate transaction orders; S3 automatically clears generated transaction orders under smart contracts; S4. After the transaction order is matched, calculate the feedback values ​​of all producers and consumers who participated in this round of transactions, and conduct user feedback analysis. S5. After the specified time has elapsed, the node responsible for packaging will package the generated transaction orders into a block. The block will then be propagated in the network. Once the consensus nodes reach a consensus, the block will be added to the blockchain for processing. At this point, the transaction round is complete. In step S1, for transactions within the microgrid, the smart contract function with the registration number is called. id The microgrid is established, and users (prosumers and consumers) are registered within it. Simultaneously, the microgrid and users are initialized, and a P2P energy trading model between prosumers and consumers based on smart contracts is constructed, specifically including: Let the number be id The microgrid energy sales price and purchase price are respectively SP id , BP id And a microgrid is set up. id Depend on m id Individual consumers, n id Composed of individual consumers, prosumers use a set M id = { M 1id , M 2id , ..., M mid Consumers use sets N id = { N 1id , N 2id , ..., N nid }; sp iid , sq iid They represent producers and consumers respectively. M iid The selling price and the quantity of energy sold, of which i= 1, 2, ..., m ; bp jid , bq jid They represent consumers respectively. N jid The purchase price and the quantity of energy purchased, among which j= 1, 2, ..., n; In step S2, the P2P energy trading model between prosumers and consumers uses PC-DA to conduct P2P energy transactions between prosumers and consumers, generating transaction orders, specifically including: Producers and consumers M iid Publish by calling smart contract functions sp iid and sq iid Then the sorting rules are automatically triggered, according to sp iid Sort the items from lowest to highest and add them to the sales array; Meanwhile, consumers N jid Publish by calling smart contract functions bp jid and bq jid And determine consumers N jid Are there enough tokens to purchase? bq jid If there are enough tokens, the energy will automatically trigger the sorting rule, according to... bp jid Sort the items from highest to lowest and add them to the purchase array; otherwise, reject the purchase request. N jid Participating in this round of energy trading; Based on a one-to-one match between the sell array and the buy array, a transaction order is generated if the conditions are met. The process of matching the sell array with the buy array one-to-one, and generating a transaction order if the conditions are met, specifically includes: Determine whether the selling price and energy quantity of the first element of the array being sold satisfy the requirements of the buying price and energy quantity of the first element of the array being purchased simultaneously. sp iid ≤ bp jid and sq iid ≥ bq jid ; The two parties that meet the requirements form a matching transaction order, and then the process is iterated until the conditions are no longer met. The remaining unmatched users then transact with the microgrid operator. Step S3, which involves automatically clearing the generated transaction orders under the smart contract, specifically includes: S301 uses the ERC20 smart contract standard as its basic protocol and converts tokens and energy prices using exchange rates. The average price and mixed price both refer to real-world currencies. Before settlement, tokens must be exchanged. The exchange mechanism is shown in equation (1): (1) In the formula, token Represents tokens, token_rate Indicates exchange rate, price Indicates currency; S302 sets the average price settlement mechanism to a 1-hour timeframe. Under this method, P2P energy transactions conclude using average price settlement. When the producer's bid and the consumer's bid are the same, the average price equals both. When the producer's bid is higher than the consumer's bid, a matching order cannot be formed. When the producer's bid is lower than the consumer's bid, settlement is based on the average price of the two. The average price... Ap ijid refers to producers and consumers M iid of sp iid With consumers N jid of bp jid The average of the two is shown in equation (2): (2) S303, set the mixed price clearing mechanism time to 1 hour, in which way the P2P energy transaction ends using mixed price clearing, producers and consumers M iid with the consumer N jid transaction mixed price Mp ijid As shown in equation (3): (3); In step S4, after the transaction orders are matched, the feedback values ​​of all producers and consumers participating in this round of transactions are calculated, and user feedback analysis is performed, specifically including: S401, producer-consumer revenue calculation: producer-consumer M iid revenue as a producer PIn iid as shown in equation (4): (4) In the formula, 、 They represent microgrids id Lower-level consumers M iid With consumers N jid The amount of energy traded by microgrid operators; p ij Indicates producer-consumer M iid With consumers N jid The transaction price; using ln The function describes the relationship between energy output and equipment expenditure; S402, Consumer Benefit Calculation: Consumer N jid Benefits CIn jid As shown in equation (5): (5) In the formula, Consumers N jid Benefits from energy purchases; , They represent consumers respectively. N jid The efficiency coefficient; , They represent microgrids id Consumers N jid With producers and consumers M iid The quantity of energy traded by microgrid operators; a quadratic function is used to describe the relationship between consumers' energy purchases and the resulting benefits, and... λ jid Consumers N jid Benefit factors; S403, producer-consumer feedback value calculation: producer-consumer M iid feedback value of the producer-consumer ps iid as shown in equation (6): (6) In the formula, psp iid , psq iid 1 / PIn iid They represent producers and consumers, respectively. M iid Price feedback value, energy trading volume feedback value, and revenue feedback value; ω iid , μ iid , η iid Represents the preference coefficient; S404, consumer feedback value calculation: consumer N jid feedback value cs jid as shown in equation (7): (7) In the formula, CSP jid , csq jid 1 / CIn jid They represent consumers respectively. N jid Price feedback value, energy trading volume feedback value, and revenue feedback value; , Ψ jid , γ jid This represents the preference coefficient.