# A Framework for Decentralized Energy Trading Based on Blockchain Technology
## 2 Methodology
### Blockchain-Based Energy Market Design  
When dealing with the mechanism's design, three key goals have to be considered:  
1. How to deal with the agreement break, because of the inertial fluctuation property of renewable energy resources;
2. How to promote the use of storage in the network; \begin{table}
\begin{tabular}{c c} \hline \hline
**Items** & **Contents** \\ \hline Number of Transactions & 1367 \\ Output Total & 22,400.38218251 BTC \\ Estimated Transaction Volume & 3786.9922673 BTC \\ Transaction Fees & 15.6770646 BTC \\ Height & 464,944 (Man Chain) \\ Timestamp & 5 May 2017 12-46:38 p.m. \\ Received Time & 5 May 2017 12-46:38 p.m. \\ Relayed By & BitPurch \\ Difficulty & 521,974,519,553.63 \\ Bits & 402,791,230 \\ Size & 989.195 KB \\ Version & 0.0 \(\times\) 2000,0002 \\ Hash & 00000000000000000e0453241 bbf356738 ade0 bc170714 bc2 ec319 bc53a8 \\ Previous Block & 000000000000000014f2 ab7e4b480d8614 fd53d7 ea5c637 aeaabeeb683 cdd3c4 \\ Next Block(s) & 00000000000000019134 cd0 db5b354 cdde1b58e5e01d1 ec47e46e9084 bf6e78 \\ Merkle Root & C2B8b82579c-b41b57a7c92936(d95b8369b8 cd32e8500c4d038d3e7 \\ \end{tabular} Network Propagation  
\end{table} 
Table 1: Summary of transactions from Bitcoin block No. 4644. Figure 2: Process to publish a block. How to deal with grid security. In this paper, a new blockchain-based energy trading market is designed accordingly. Participants in the market are divided into four populations: producer, consumer, speculator and regulator. The physical entities of each population are shown in Figure 3.  
In each dispatch cycle, consumers and suppliers will submit purchases, sale prices and quantities to the Internet according to the highest and lowest purchase price in the prior cycle. Each node will deal with the order handling and security check. The speculator can store energy during the low-price period and sell energy when the price is higher. The role of the regulator is to prevent price fluctuations and maintain the stability of the trading platform. After the optimal energy transfer route is solved, transactions are stored on the blockchain in the form of smart contracts, and money is transferred automatically after a transaction is completed. (1) Producer  
In a bidding cycle, each generator is an independent participant with independent decision-making strategies and can adjust the bidding price and quantity simultaneously. Assuming that there are n generators in the market, if the i-th generator posts an order with an initial bidding price \(\mathrm{p}^{0}_{\mathrm{G,i}}\) and initial quantity \(\mathrm{q}^{0}_{\mathrm{G,i}}\), then the generator's profit \(\varepsilon^{0}_{\mathrm{G,i}}\) can be calculated by  
\[\left\{ \begin{aligned} \varepsilon^{\mathrm{t}}_{\mathrm{G,i}}= \mathrm{q}^{\mathrm{t}}_{\mathrm{G,i}}\times\left(\mathrm{p}^{\mathrm{t}}_{ \mathrm{G,i}}-\mathrm{c}_{\mathrm{G,i}}\right)&\text{if }\mathrm{p}^{\mathrm{t}}_{ \mathrm{i}}>0\\ \varepsilon^{\mathrm{t}}_{\mathrm{G,i}}=-\sigma_{\mathrm{G,i}}& \text{if }\mathrm{p}^{\mathrm{t}}_{\mathrm{i}}=0\end{aligned} \right. \tag{1}\]  
where \(\varepsilon^{\mathrm{t}}_{\mathrm{G,i}}\) is the profit in the t-th time step. \(\mathrm{c}_{\mathrm{G,i}}\) is the unit cost of producer i and \(\mathrm{\sigma}_{\mathrm{G,i}}\) is the breakdown loss. If the producer does not produce energy, a financial loss will be generated. This is in line with the actual situation but also can prevent producers from maliciously reducing the production quantity and raising energy prices. The operation goal for the generator can expressed as follows:  
\[ \begin{aligned} \text{Max }\varepsilon^{\mathrm{t}}_{ \mathrm{G,i}}\\ \text{s.t.0}\leq\mathrm{q}^{\mathrm{t}}_{\mathrm{G,i}}\leq\mathrm{q} _{\mathrm{G,i,max}}\end{aligned}  \tag{2}\]  
Figure 3: Sample of roles for participants in energy trading. In reality, a speculator may separate a portion of the storage capacity for ordinary energy producers.