Integrated Energy Transaction Mechanisms Based on Blockchain Technology

: With the rapid development of distributed renewable energy (DRE), demand response (DR) programs, and the proposal of the energy internet, the current centralized trading of the electricity market model is unable to meet the trading needs of distributed energy. As a decentralized and distributed accounting mode, blockchain technology ﬁts the requirements of distributed energy to participate in the energy market. Corresponding to the transaction principle, a blockchain-based integrated energy transaction mechanism is proposed, which divides the trading process into two stages: the call auction stage and the continues auction stage. The transactions among the electricity and heat market participants were used as examples to explain the details of the trading process. Finally, the smart contracts of the transactions were designed and deployed on the Ethereum private blockchain site to demonstrate the validity of the proposed transaction scheme.


Introduction
With the promotion of technologies for distributed renewable energy (DRE) generators and demand response (DR) programs, the boundaries between generators and consumers are becoming blurred. Jeremy Rifkin presented the concept of energy interconnection, the cores of which are renewable distributed energy and energy internet that would enable access to distributed energy and fair trade [1]. This concept would also enable more forms of demand-side energy resources, such as heat and gas, to participate in the market. Traditional electricity transactions will develop into integrated energy resource (IER) transactions, which makes the transactions more complicated and the management more difficult [2]. The direction of energy delivery is vital to enhance efficiency and decrease energy consumption, such how to handle the first mile and last mile delivery logistics [3]. Therefore, designing an efficient trading scheme is vital to facilitate the development of the energy internet. The management of transactions can be divided into two primary categories: centralized and decentralized [4]. The centralized transactions may have such issues as high operating costs, excessive time consumption, and security problems. To arrange scheduling instructions, the trading center has to collect all information regarding the distributed energy, which will lead to personal privacy concerns [5]. In addition, when the number of transaction users increase, the data information will increase geometrically, which will increase the difficulty of scheduling resources in real time. Therefore, several scholars have presented the idea of decentralizing the distributed energy transactions [6].
The preconditions for the distributed energy trading were analyzed [7], which included the real-time information exchange, the self-optimizing strategy selection, the automatic transaction settlement, and the trading platform decentralization for the local energy internet. In [8], a fully decentralized microgrid platform, "Overgrid", is presented in order to carry out peer-to-peer (P2P)

Blockchain and Smart Contracts
Blockchain is a chain structure in which all transaction data are packed into blocks, and the blocks are connected in chronological order [30]. Using the technology of the asymmetric encryption, the Merkel tree, and the proof of work consensus mechanism, the transaction data can be transparent, non-destructive, and traceable. The essence of a blockchain is a decentralized distributed database. Compared with the traditional database, blockchain has the advantage that the data are tamper-resistant; therefore, information is safe. However, if blockchain is only applied to data storage, its function is limited. Therefore, it is proposed to combine blockchain with smart contracts to achieve more complex functions.
A smart contract is a set of digital programs that prescribes the rights and obligations to the consumer that is automatically executed by the computer system [15]. When an agent executes a contract locally, the other agents will update the contract's content to reach a new consensus. Thus, a credible partnership can be established in a distributed system without central supervision. The blockchain is the supporting technology of smart contracts and the Ethernet is the most widely used open source blockchain platform [33]. However, for the mass adoption of this technology, volume and speed of transaction processing need to be scaled up. There is presently an unresolved tension between scalability, security, and decentralization concerns, as only two of them at a time can (so far) be addressed satisfactorily. To address the trilemma, several solutions have been proposed, such as off-chain interaction technology.

Off-Chain Interaction Technologies
Each action on the main-chain is packed and recorded into a block, which is time-consuming and limits the transaction speed. To improve the speed of the transaction processing on blockchain, off-chain technologies that build onto the main-chain are proposed. Base-level protocols do not need to change. Instead, they exist as smart contracts on the Ethereum site that interact with off-chain software. The function of a public blockchain can be expanded such that the security and irreversibility are ensured.
The typical "off-chain" technologies include state channels, Plasma, and Truebit [34]. State channels and Plasma allow interactions outside the blockchain such that the platform will have an increased transaction throughput. Truebit completes the complex calculations in the smart contracts that are off-chain. This reduces the cost of executing smart contracts, i.e., gas in Ethereum, while completing those operations with costly computation expenses or those that cannot be completed on-chain.
Off-chain technologies allow transactions to achieve a balance among speed, irreversibility, and costs by sacrificing a little decentralization. Therefore, blockchain may be applied to more extensive and complex trading modes.

Decentralized Transactions of Integrated Energy
Distributed exchange models were first applied to the financial field. With an increase in the types of tokens, the circulation among them became more difficult. Centralized exchanges are confronted with multiple risks, such as network security and protection. To solve these problems, the open source community has completed a series of attempts to build distributed exchanges, such as EtherDelta, 0x protocol, Loopring and Kyber Network. The core of the distributed exchanges is a decentralized trading protocol, which is based on blockchain [35]. This study uses Loopring as an example to explain the exchanges' working mechanisms. In Loopring, a user authorizes the matchmaking contract to transfer the tokens to a smart contract. The exchange searches for a set of orders that can be matched and transfers the matching results to the smart contract's address after the user signs in, then the order can be matched off-chain and the asset is secured [36]. By using the off-chain technologies, the distributed exchanges can complete complex deals.
The distributed exchanges on blockchain can meet the demand which integrated energy requires in market transactions. First, the characteristics of blockchain, such as equality and decentralization, can support the numerous peer-to-peer transactions among the distributed energy resources. Second, the managers of the energy subsystems are different, but blockchain provides multiple users with a decentralized and trustless power market to reduce transaction costs. Third, smart contracts provide a platform for the implementation of advanced transactions [37]. As the decision-making mode of the energy system gradually transforms to the distributed mode, the users' decisions and transactions can be written into contracts to ensure efficient decision-making and fair transaction.

Transaction Framework of Distributed Integrated Energy Trading
In the distributed energy trading framework designed in this paper, we assumed that each user had a blockchain account with a pair of keys, i.e., a public key and a private key [4], and that smart meters were available to upload power data to the network. An energy usage plan should be determined before the trading session. The participants in the distributed energy trading must authorize the exchange to transfer a set number of tokens from their blockchain accounts to multi-signature wallets. Inspired by the mechanism of the stock market exchange, the transaction process proposed in this paper is divided into two stages: the call auction stage and the continuous double auction stage. The schematic process is presented in Figure 1. The energy buyer authorizes the exchange so that the software could transfer a set number of tokens from the blockchain account to multi-signature wallets (signed by both the buyer and the exchange). The order contracts which contain the buyers' order information and the sellers' information can be sent to the exchange with the digital signatures by using their private key. The exchange classifies the orders provided by the buyers and the sellers, followed by combining them into order books. The form of the order books requires conforming to two principles: the same kind of energy and the same delivery time, so that the two principles could enter the settlement within the same trading period T. Thereafter, the transaction processing contract or the matchmaking trading contract will facilitate the transactions. Moreover, the settlement contract will be created and deployed to the main chain for the purpose of ensuring the assets' safety for the traders. After reaching the transaction agreement, the smart meters' data will be uploaded to the settlement smart contract automatically and the tokens will be transferred as well.
Energies 2018, 11, x FOR PEER REVIEW 4 of 20 the user signs in, then the order can be matched off-chain and the asset is secured [36]. By using the off-chain technologies, the distributed exchanges can complete complex deals. The distributed exchanges on blockchain can meet the demand which integrated energy requires in market transactions. First, the characteristics of blockchain, such as equality and decentralization, can support the numerous peer-to-peer transactions among the distributed energy resources. Second, the managers of the energy subsystems are different, but blockchain provides multiple users with a decentralized and trustless power market to reduce transaction costs. Third, smart contracts provide a platform for the implementation of advanced transactions [37]. As the decision-making mode of the energy system gradually transforms to the distributed mode, the users' decisions and transactions can be written into contracts to ensure efficient decision-making and fair transaction.

Transaction Framework of Distributed Integrated Energy Trading
In the distributed energy trading framework designed in this paper, we assumed that each user had a blockchain account with a pair of keys, i.e., a public key and a private key [4], and that smart meters were available to upload power data to the network. An energy usage plan should be determined before the trading session. The participants in the distributed energy trading must authorize the exchange to transfer a set number of tokens from their blockchain accounts to multisignature wallets. Inspired by the mechanism of the stock market exchange, the transaction process proposed in this paper is divided into two stages: the call auction stage and the continuous double auction stage. The schematic process is presented in Figure 1. The energy buyer authorizes the exchange so that the software could transfer a set number of tokens from the blockchain account to multi-signature wallets (signed by both the buyer and the exchange). The order contracts which contain the buyers' order information and the sellers' information can be sent to the exchange with the digital signatures by using their private key. The exchange classifies the orders provided by the buyers and the sellers, followed by combining them into order books. The form of the order books requires conforming to two principles: the same kind of energy and the same delivery time, so that the two principles could enter the settlement within the same trading period T. Thereafter, the transaction processing contract or the matchmaking trading contract will facilitate the transactions. Moreover, the settlement contract will be created and deployed to the main chain for the purpose of ensuring the assets' safety for the traders. After reaching the transaction agreement, the smart meters' data will be uploaded to the settlement smart contract automatically and the tokens will be transferred as well.    The parameters used in this section are given in abbreviations Table 1.

Items
Meaning The electricity production of CCHP at time t F CHP The natural gas consumed by CCHP η CHP,E The electricity generation efficiency of CCHP Q CHP The recovered heat energy of CCHP η CHP,H The heat recovery efficiency of CCHP P Gi The energy amount provided by energy seller i p min

Gi
The price floor of energy seller i P Dj The energy demand of the buyer j σ The difference between energy demand and supply λ 0 The initial quoted price broadcasted to buyers λ k The energy price in kth iteration ρ The step length set in the iterative process The coefficients of the electricity user i's utility function U Di (P Di ) The benefit of the electricity user i if P Di is purchased π Di The profits of electricity user i E th,i The ith energy seller's profit P Gi The actual energy amount provided by the ith energy seller p T The energy's price τ The penalty parameter if the actual energy is too much or too little The buyer's appraisal price in the tth iteration of trading τ s (t) The seller's appraisal price in the tth iteration of trading p call The energy price got form call auction p Obid (t) The optimal purchase price in the tth iteration of trading p Oask (t) The optimal selling price in the tth iteration of trading η b , η s ∈ (0, 1] the increment rates of the buyer's and seller's quotation

Call Auction Stage
During the call auction stage, the seller and buyer will make disposable matchmaking transactions providing guiding prices for various types of energy at each period in a day. The matchmaking transaction may be used as a reference for the quoted price during the double auction stage. It should be noted that while there are many ways to hold a call auction, this paper uses only one of them.
Besides the proceeding transaction process, the process in call stage has its own features: (1) In call stage, a demand order contract address is required for each buyer's order; and the seller i writes its supply p T Gi and price floor p T,min Gi during the trading period T into its bid order. For presentation purpose, the superscript letter T of parameters are omitted in the following.
(2) All the information is sent to the exchange, which is responsible for classifying the orders into groups based on the energy types and trading time. The orders in the same order-book will be sent to one transaction processing smart contract, and the contract calculates the maximum value of the price floors submitted by all sellers, followed by delivering the price signal to the demand order contract. Demand (obtained from the demand order contract) and supply are followed by adjusting the price signal in accordance with the Formulas (1)-(3).
(3) In each interaction, the demand order contract modifies the amount of demand in accordance with its utility function. In the meantime, the supply is calculated at the quoted price signal. The interactions end until Formula (4) is satisfied.
We use the power buyers as an example. The electricity users' utility function [38] and profit function are shown as Formulas (5) and (6). Meanwhile, there are constraints on the users' purchase quantity, per Formula (7).
Based on the principle of profit maximization, the demand can be calculated according to Formula (8): Therefore, according to price λ k+1 i , corresponding P Di is provided by electricity users. This process can be written as a contract, which is deployed on the side-chain managed by the exchange, and executed off the main chain.
(4) When Formula (4) is satisfied, pre-transaction orders are generated. The exchange adjusts the orders as per the amounts of another type of energy provided by the multi-energy sellers.
For instance, the sellers, capable of supplying two or more types of energy, require special handling. The pre-transaction orders should be adjusted in accordance with their operation mode. For instance, combined cooling, heating and power (CCHP) follows the supply formula presented hereunder: The operation mode should be determined through the determination of either the power by heat or the heat by power. In case of determination of power by heat, the pending transaction will be based on the power. The heat energy supply is subsequently calculated in accordance with the power transaction volume. The exchange will replace the heat seller having the same amount, but at a higher price in the same period, and vice versa.
(5) The transaction processing smart contract creates objects for the settlement contracts based on the consensus of the transaction. Following the settlement, the transaction amount is calculated in accordance with the Formula (11), which is based on the seller's smart meter's data. The money E th,i in the multi-signature wallet is subsequently transferred to the seller by the means of state channels:

Continuous Double Auction Stage
After the call auction, traders who do not have a deal and new traders can hold continuous double auctions. During the trading cycle, buyers and sellers can submit their quotations at any time. The buyers' prices are ranked from high to low and the highest quotation is the optimal purchase price. The sellers' prices are ranked from low to high and the lowest quotation is the optimal selling price. The buyer who has the highest quotation can match the seller who has the lowest quotation. When the optimal purchase price is higher than or equal to the optimal selling price (the price margin is less than or equal to zero), a deal can be made, as Figure 2 shows. Actual price is the average price of the two quotations. If the prices are identical, the transactions are completed according to the quotations' submission time. During the matchmaking process, the matchmaking smart contracts need to update the status of each quotation (withdrawal or addition) in real time.
After the call auction, traders who do not have a deal and new traders can hold continuous double auctions. During the trading cycle, buyers and sellers can submit their quotations at any time. The buyers' prices are ranked from high to low and the highest quotation is the optimal purchase price. The sellers' prices are ranked from low to high and the lowest quotation is the optimal selling price. The buyer who has the highest quotation can match the seller who has the lowest quotation. When the optimal purchase price is higher than or equal to the optimal selling price (the price margin is less than or equal to zero), a deal can be made, as Figure 2 shows. Actual price is the average price of the two quotations. If the prices are identical, the transactions are completed according to the quotations' submission time. During the matchmaking process, the matchmaking smart contracts need to update the status of each quotation (withdrawal or addition) in real time. During the auction, market participants can adjust their quotations based on market information for the next cycle of trading until the total amount of electricity is sold out or the trading time is cut off. After completing the matching transactions, the two sides create the settlement smart contract and transfer the tokens.
Unlike the centralized approach, in the continuous double auction stage, the individuals participating in energy trading are interested in maximizing its utility (energy to be requested) without concern for the interests of others. Every participant can submit bidding to the matching contract at each trading interval. In this paper, we assume all participants adopted the AA strategy [Error! Reference source not found.], which adjusts the price according to the marketing environment.
Before entering the market, each buyer and seller calculate an appraisal price according to the expected purchasing price, production cost, deal price from the centralized competitive bidding stage and trading willingness [Error! Reference source not found.]. Thus, the buyer's quoted price  (12) and (13), respectively: In the first iteration of trading, the results of the call auction are used as the optimal purchase price and the optimal selling price. In the following transactions, if the sellers and the buyers have not completed a deal, the buyer and the seller can adjust the quotation according to the base price and the current optimal selling price. During the auction, market participants can adjust their quotations based on market information for the next cycle of trading until the total amount of electricity is sold out or the trading time is cut off. After completing the matching transactions, the two sides create the settlement smart contract and transfer the tokens.
Unlike the centralized approach, in the continuous double auction stage, the individuals participating in energy trading are interested in maximizing its utility (energy to be requested) without concern for the interests of others. Every participant can submit bidding to the matching contract at each trading interval. In this paper, we assume all participants adopted the AA strategy [39], which adjusts the price according to the marketing environment.
Before entering the market, each buyer and seller calculate an appraisal price according to the expected purchasing price, production cost, deal price from the centralized competitive bidding stage and trading willingness [39]. Thus, the buyer's quoted price p b (t) and the seller's quoted price p s (t) are calculated according to Formulas (12) and (13), respectively: In the first iteration of trading, the results of the call auction are used as the optimal purchase price and the optimal selling price. In the following transactions, if the sellers and the buyers have not completed a deal, the buyer and the seller can adjust the quotation according to the base price and the current optimal selling price.

Formulation of Smart Contracts
Off-chain interaction technology is still in the initial stage of development; even the most mature application, Lightning Network, which promises to ease network congestion by moving transactions off the main blockchain, while it has not been suitable for high value payment system in light of security, only realizes the micropayment function in the network. Therefore, we will only discuss the contract related to the transaction mechanism in this paper. This section will discuss the construction of smart contracts by using the transaction between the distributed generators and electricity users as an example. The transaction process involves five smart contracts in chronological order, including the transaction processing in the call auction stage, the determination of each user's demand, the adjustment of scheduled orders, the matchmaking in the continuous double auction stage and the transaction settlement.

The Transaction Processing Contract
The input of this contract is the supply amount during a certain period and the corresponding price floor submitted by the sellers. The smart contract will record all orders and calculate the total power supply at the power price obtained by the iterative double auction. The smart contract will subsequently adjust the price and send the new price to the address of the customer's demand order contract. The outputs include new electricity price (being sent back to the user's wallet when the iterative termination criteria are not satisfied) and the trading volume of each seller (output when the iterative termination criteria are satisfied).
When electricity supply equals the demand, the contract will check whether the heat orders have been processed. If so, the contract will do two jobs. One is to calculate the heat supply according to the quantity of electricity provided by the CCHP and then transmit the data to the adjustment contract of the scheduled heat sellers. The other is to adjust the scheduled sellers according to the power data from the adjustment contract of the scheduled heat sellers and replace the same amount of electricity bought from the generators with the highest price floor. The basic elements of the contract are provided in Table 2.

Demand Order Contract of Electricity Buyers
The buyers should transfer a deposit to the multi-signature wallet's address according to the local electricity retail price. This part of the work is done before the buyer joins the market (building a status channel or joining the side-chain managed by the exchange). The input of this contract is the energy type, energy amount, and delivery time of sellers and buyers. The output includes the buyer's address, the seller's address, the energy amount and the energy price.
The function of this contract is to calculate user demand according to the price provided by the transaction processing contract. The basic elements of the contract are shown in Table 3.

The Matchmaking Trading Contract
The matchmaking trading contract checks the delivery time and the energy type of the sellers and the buyers and classifies buyers and sellers of the same delivery time according to bid price. The contract then matches the sellers and buyers by the transaction mechanism presented in Section 3.2. The basic elements of the contract are shown in Table 4.

The Settlement Contract
By means of the settlement contract, the funds can be automatically transferred according to the pre-agreed terms and deal terms after the delivery time of the transaction. The basic elements of the contract are shown in Table 5. The energy amount supplied by the sellers is submitted by smart meters. The settlement rules should be clarified in the market access agreements signed before the smart contract is created. After the delivery period, the electric data will be transferred to the settlement contract. The contract will be executed and the tokens will be transferred from the multi-signature wallet to the multi-signature wallet of the seller and the exchange account.

Case Study
To verify the effectiveness of the transaction mechanism proposed in this paper, the smart contracts for the distributed transaction were released on the test network of the Ethernet for simulation. There were five electricity buyers, in addition to four generators, merely providing electricity and two CCHP in this test. One of the two CCHP works to determine power by heat operation mode (this CCHP joins in the heat transaction processing contact) and other works in the determination of the heat by power operation mode (this CCHP joins the electricity transaction processing contract). We employ the Remix platform to test the smart contracts.

Deploying the Demand Order Contract of Electricity Buyers
The demand order contract consists of a constructor, a power calculation function, a data transfer function, and auxiliary functions. Constructor function has the same name as the contract. With the aid of this function, the contract can be deployed preliminarily and the initial variable can be initialized. The inputs of constructor are the parameters of the electricity buyers' demand strategies, which are shown in Table 6. These buyers create the demand orders and send them to the exchange address. This paper places all user data into one contract for demonstration purposes. We use Solidity programming language, which is a contract-oriented, high-level language designed to target the Ethereum Virtual Machine (EVM), to build the contracts. Considering that the Solidity does not support decimal numeric storage, in order to ensure the accuracy of the calculation results, the initial data are magnified. The values of the buyers' parameters are magnified 100 times as the constructor input. The operating results of the contract are shown in Figure 3, which indicate the state of execution of the contract, the address of the contract, the address of the executor, the gas value of the execution of the contract, the contract's hash value, the log, and other information.

Deploying the Transaction Processing Contract
The transaction processing contract can be deployed on the exchange's wallet, to which the energy buyers transfer a margin prior to trading. This contract consists of a constructor, an input interface function, call functions, a price adjustment function, a supply amount calculation function, the other kind of energy's amount calculation function, a seller readjustment function, and auxiliary functions.
The assumed seller's parameters are presented in Table 7. It requires observation that only the sellers, having the same delivery time, will be sent to the same contract.
The result of input interface is presented in Figure 6. Furthermore, the initial quotation (11 Finney/MW) is transmitted to the buyers' demand order contract, and the process is recorded in an

Deploying the Transaction Processing Contract
The transaction processing contract can be deployed on the exchange's wallet, to which the energy buyers transfer a margin prior to trading. This contract consists of a constructor, an input interface function, call functions, a price adjustment function, a supply amount calculation function, the other kind of energy's amount calculation function, a seller readjustment function, and auxiliary functions. The assumed seller's parameters are presented in Table 7. It requires observation that only the sellers, having the same delivery time, will be sent to the same contract. The result of input interface is presented in Figure 6. Furthermore, the initial quotation (11 Finney/MW) is transmitted to the buyers' demand order contract, and the process is recorded in an event. By the call function, the integer data 1100 is transferred from the address of the transaction processing contract to the demand order contract, as presented in Figure 7.  The type of energy. Returning true indicates that initial quotation is transferred from the address of the transaction processing contract to the demand order contract successfully.
Following three iterations, the buyers' demands are 890, 550, 900, 760 and 1400 kW correspondingly, while the price is 12.24 Finney/MW. Subsequently, setting the balance indicator inside the contract to be "true" and checking the balance indicator of heat transaction processing contract. If the indicator is "true", then this contract will get the electricity generated by the CCHP that is scheduled by the heat transaction processing contract and send the heat generated by the CCHP which is scheduled by this contract. The way to transfer data between contracts is same to the call function mentioned above.
The sellers' scheduled energy amount is presented in Table 8. Assuming the electricity amount received from the heat transaction processing contract is 400 kW, which is provided by the CCHP "0xdd870fa1b7c4700f2bd7f44238821c26f7392148". The adjustment is recorded as an event, which is presented in Figure 8.
This figure suggests that the seller "0x14723a09acff6d2a60dcdf7aa4aff308fddc160c" reduces 400 kW. Table 8. Sellers' scheduled energy amount before adjustment.

Deploying the Matchmaking Trading Contract
This contract realizes the matchmaking of the sellers and the buyers in accordance with the method in the continuous double auction stage. This contract consists of a constructor, two input interface functions, a matchmaking function, a withdraw function and auxiliary functions.
The address of seller 2 The scheduled energy amount after adjustment The address of CCHP Before adjustment, CCHP has 0kW. After adjustment, CCHP has 400kW. Thus, CCHP gains 400kW.
The scheduled energy amount after adjustment Figure 8. Record of the sellers' scheduled amount after adjustment. The matchmaking function finds the highest buyers' bidding price and the lowest sellers' bidding price, followed by comparing them and calculating the transaction price and amount. If the bidding is executed in all, the contract will set the state indicator of the buyer or the seller as "true" in order to exclude them from the order set. The transaction in the first round is recorded in the event, called "Transaction log", as presented in Figure 9. The Seller0 sells Buyer1 200 kW at 10.72 Finney/MW, and the state indicator of Seller0 is set to be "true", implying that the Seller0's energy has been sold out. Seller 0 True denotes that Seller 0 has sold out Buyer 1 False denotes that buyer1's demand has not been satisfied.
Other functions are common in the functional design of smart contracts. The heat bidding can be processed in the same manner.
Over the trading cycle, there are 5 transactions concluded in 2 rounds of trading, as presented in Table 10.

Deploying the Transaction Settlement Contract
The transaction settlement contract primarily comprises the constructor, the funds transferring function, and auxiliary functions. This contract should be deployed on the main chain of Ethereum and the transfer of funds should be confirmed by the multiple signatures (the exchange and the buyer).
This paper takes the Seller0 and the Buyer1 in Table 8 as an example for the illustration of the process of the transaction settlement when the energy has been delivered.
The input parameters of the contractor function include "0xb868ab9cf247345f586fa0f0750ce110c2202db3" (the address of the user), 200 kW (the target output), 10.72 Finney/MW (the transaction price).
Assuming that the actual output of the seller is 150 kW, which is insufficient, the seller faces a punishment that the contract is settled at 90% of the transaction price. The amount that the buyer requires paying to the seller is presented in Figure 10. It records the transfer of tokens between the Other functions are common in the functional design of smart contracts. The heat bidding can be processed in the same manner.
Over the trading cycle, there are 5 transactions concluded in 2 rounds of trading, as presented in Table 10.

Deploying the Transaction Settlement Contract
The transaction settlement contract primarily comprises the constructor, the funds transferring function, and auxiliary functions. This contract should be deployed on the main chain of Ethereum and the transfer of funds should be confirmed by the multiple signatures (the exchange and the buyer).
This paper takes the Seller0 and the Buyer1 in Table 8 as an example for the illustration of the process of the transaction settlement when the energy has been delivered.
The input parameters of the contractor function include "0xb868ab9cf247345f586fa0f0750 ce110c2202db3" (the address of the user), 200 kW (the target output), 10.72 Finney/MW (the transaction price).
Assuming that the actual output of the seller is 150 kW, which is insufficient, the seller faces a punishment that the contract is settled at 90% of the transaction price. The amount that the buyer requires paying to the seller is presented in Figure 10. It records the transfer of tokens between the two addresses in the form of an event. The address of seller0 The amount of transaction The address of buyer1 The address of seller0 Contract address

Transaction Mechanism Comparision
The social welfare and market efficiency [40] are chosen as the evaluation indicators in order to compare the mechanism put forward in this paper, the single call auction mechanism and the single continuous action mechanism. The social welfare of the proposed mechanism, the single call auction mechanism and the single continuous action mechanism is 130.88 Finney, 130.49 Finney and 121.72 Finney, correspondingly. Market efficiency is the ratio between actual social welfare and maximum social welfare 134.18 Finney (all transactions are dealt with at a time, which is unrealistic because of the renewable energy's forecast errors and uncertainty of consumers' behaviors), which are 97.25%, 97.54% and 90.71%, correspondingly.
In accordance with the principle of economics, when the market transaction price is equal to the equilibrium price, social welfare is the largest, which is the situation with maximum social welfare. In the single call auction mechanism situation, the market is cleared once in each trading cycle (for instance, once in an hour); if the seller's or buyer's delivery time is close to the bidding time, it would not have a second bidding chance. The transaction model put forward in this paper is a compromise of market efficiency and uncertainty characteristics of market participants (for instance, renewable energies and energy consumption behaviour), which achieve the best performance among the three practical mechanisms. The mechanism put forward in this paper is superior to the single call auction mechanism since the transactions made in call stage reach the beneficial maximum. In short, the transaction model has the potential to balance the market efficiency and the trading convenience.

Conclusions
The decentralized characteristic of blockchain technology is its high compatibility with the trading demand of integrated energy resources. This paper discussed the application of blockchain technology in the integrated energy trading and put forward a decentralized transaction scheme, including the interaction process of the smart contracts.
The transaction process put forward in this paper is divided into two stages: the call auction stage and the continuous double auction stage. Accordingly, the trading parties adjusted their bidding by monitoring the information broadcasted in the blockchain so that more freedom could be provided for them to participate in the market. The authors designed and deployed the trading smart contracts on the Ethereum website, in addition to verifying the trading process. In the study case, distributed generations and users can achieve transaction conclusion and transaction settlement without the participation of centralized institutions; besides, the characteristics of blockchain can guarantee the interests of the market participants. In comparison with the single type transaction model, the proposed mechanism finds a compromise between the market efficiency and the participants' convenience. The proposed mechanism can meet the demand of the distributed, smallscale and low-cost transaction of the integrated energy resources in micro-grid, and can be extended to the transactions for the other production forms, such as energy efficiency in supply chain and transportation solutions. These contracts were deployed on Metamask, an application allowing the users to run Ethereum dApps in a browser. The event that records the transaction's process is presented in Figure 10. This figure reveals that 1.4472 Finney has been transferred from the address of the generator to the user.

Transaction Mechanism Comparision
The social welfare and market efficiency [40] are chosen as the evaluation indicators in order to compare the mechanism put forward in this paper, the single call auction mechanism and the single continuous action mechanism. The social welfare of the proposed mechanism, the single call auction mechanism and the single continuous action mechanism is 130.88 Finney, 130.49 Finney and 121.72 Finney, correspondingly. Market efficiency is the ratio between actual social welfare and maximum social welfare 134.18 Finney (all transactions are dealt with at a time, which is unrealistic because of the renewable energy's forecast errors and uncertainty of consumers' behaviors), which are 97.25%, 97.54% and 90.71%, correspondingly.
In accordance with the principle of economics, when the market transaction price is equal to the equilibrium price, social welfare is the largest, which is the situation with maximum social welfare. In the single call auction mechanism situation, the market is cleared once in each trading cycle (for instance, once in an hour); if the seller's or buyer's delivery time is close to the bidding time, it would not have a second bidding chance. The transaction model put forward in this paper is a compromise of market efficiency and uncertainty characteristics of market participants (for instance, renewable energies and energy consumption behaviour), which achieve the best performance among the three practical mechanisms. The mechanism put forward in this paper is superior to the single call auction mechanism since the transactions made in call stage reach the beneficial maximum. In short, the transaction model has the potential to balance the market efficiency and the trading convenience.

Conclusions
The decentralized characteristic of blockchain technology is its high compatibility with the trading demand of integrated energy resources. This paper discussed the application of blockchain technology in the integrated energy trading and put forward a decentralized transaction scheme, including the interaction process of the smart contracts.
The transaction process put forward in this paper is divided into two stages: the call auction stage and the continuous double auction stage. Accordingly, the trading parties adjusted their bidding by monitoring the information broadcasted in the blockchain so that more freedom could be provided for them to participate in the market. The authors designed and deployed the trading smart contracts on the Ethereum website, in addition to verifying the trading process. In the study case, distributed generations and users can achieve transaction conclusion and transaction settlement without the participation of centralized institutions; besides, the characteristics of blockchain can guarantee the interests of the market participants. In comparison with the single type transaction model, the proposed mechanism finds a compromise between the market efficiency and the participants' convenience. The proposed mechanism can meet the demand of the distributed, small-scale and low-cost transaction of the integrated energy resources in micro-grid, and can be extended to the transactions for the other production forms, such as energy efficiency in supply chain and transportation solutions.
Further studies will focus on two major parts: firstly, setting up a platform to put the distributed transaction mechanism into practice, and evaluating its effectiveness and practicability. Secondly, designing the blockchain-based transaction mechanism among the virtual power plants and the distributed resources.