A Smart Contract-Based P2P Energy Trading System with Dynamic Pricing on Ethereum Blockchain
Abstract
:1. Introduction
- (1)
- Dynamic pricing for automatic balancing of total supply and total demand within a microgrid: We assume that our energy trading system within a microgrid will help prosumers and consumers to trade small amounts of energy in each short trading period, for example, an hour. Under this assumption, it would be cumbersome for prosumers and consumers to bid or ask in every trade for each period. To avoid this hassle, in our system, a single price is determined for each period as a function of total demand and total supply submitted. The price increases/decreases per each period depend on the ratio of total demand over total supply. The increased/decreased price will encourage/discourage supply/demand for prosumers (consumers) in the next trading period. The speed of convergence is adjustable for faster convergence or stable operation through manipulation of the pricing formula. This mechanism will help our trading system automatically achieve equilibrium (total supply = total demand) or operate close to it without any intervention by a third party.
- (2)
- Prevention of double sale: Since energy is traded online, it is imperative to guarantee that the same energy is not sold more than once. For this, we introduce an energy ownership structure and implement it inside a smart contract [3] on Ethereum blockchain [4]. The energy ownership structure guarantees integrity for every state change of energy: “Injected”, “On-board for sale”, “Matched” and so on. Change of states is only allowed for qualified participants and protected from any hacking or tampering by any unauthorized party. For example, injection of energy is only verified by DSO (distribution system operator) and hence only the DSO is qualified to update the corresponding state with its private key. Traditionally, the DSO is responsible for almost everything for trading on the energy market and is vulnerable to hacking or tampering. In our system, we replace the DSO by Ethereum blockchain as much as possible, excluding indispensable parts such as transmission, confirmation of injection and pricing policy. Matching, payment, prevention of double sale, et cetera, are automatically and forcefully executed by a smart contract, free from hacking or tampering.
- (3)
- Automatic and autonomous operation: The trading procedure is implemented as a smart contract on Ethereum and hence trade in each period is performed automatically and autonomously. At the start of each trading period, prosumers and consumers send request_to_sell and request_to_buy, respectively, to the smart contract. The consumers deposit enough money to cover their purchase to the smart contract. The smart contract collects all the requests and computes an energy price according to a preset formula. Matching and clearing are also performed by the smart contract. Thus, all the procedures are automatic and autonomous, requiring neither intervention of third parties nor costly firewalls. The smart contract performs as an escrow between prosumer, consumer and DSO to ensure that the promised transaction is actually delivered. In our current implementation, the DSO is responsible for transmission and withdrawal of power. The DSO uses its private key to create a digital signature which guarantees transmission and withdrawal of power. As for payment, the smart contract performs as an escrow to verify the delivery of power by the DSO and to ensure that the payment is done accordingly.
- (4)
- Experiment on a testbed: Many known works in the literature on trading on blockchain sketch their schemes without actual implementation. We perform an experiment on a testbed using Raspberry Pis as prosumers, consumers and a DSO. All nodes have their own virtual machine called Ethereum Virtual Machine (EVM) [5] on which a smart contract is executed. Prosumers, consumers and DSO use Node.js and web3.js API to control Geth (a command line interface to access EVM). The GUI is built with MATLAB [6].
- (5)
- Simulation via persona: We borrow from existing energy production and consumption data to create virtual prosumers and consumers to experiment on our testbed. We generate personas in such a way that they respond to price increase/decrease to increase/decrease supply or decrease/increase demand, correspondingly. Their behaviors are programmable to suit any scenario.
2. Related Works
2.1. Pricing Models
2.2. Blockchain Technology
2.3. Blockchains in Energy Trading
3. The Proposed P2P Energy Trading System with Dynamic Pricing
3.1. Dynamic Pricing
3.2. The Proposed Dynamic Pricing Algorithm
3.3. The State Diagram Representation and Solidity Program
Algorithm 1: Energy Trading Algorithm |
|
4. The Proposed P2P Energy Trading Implementation on a Private Ethereum Blockchain
4.1. Prevent Tampering of Transaction Records
4.2. Prevent Double Sale of Energy
4.2.1. Implementation of State Diagram
4.2.2. Energy Ownership Structure
4.2.3. Prevent Double Sale Using Smart Contract
4.3. Inject Energy Using Whisper
4.4. Matching between Prosumers and Consumers
4.5. Settlement
5. Experiment Using a Test Ethereum Blockchain
5.1. Creation of Virtual Prosumers and Consumers
5.2. Setup of an Experimental Ethereum Blockchain
5.3. Execute Functions or Detect Events in a Smart Contract
5.4. Create Persona from Real Prosumers and Consumers
5.4.1. Inject Energy
5.4.2. Aggregation
5.4.3. Matching
5.4.4. Settlement
5.5. Ethereum Gas Cost
6. Conclusions
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Acknowledgments
Conflicts of Interest
References
- Luo, Y.; Itaya, S.; Nakamura, S.; Davis, P. Autonomous Cooperative Energy Trading Between Prosumers for Microgrid Systems. In Proceedings of the 39th Annual IEEE Conference on Local Computer Networks Workshops, Edmonton, AB, Canada, 8–11 September 2014. [Google Scholar]
- Enabling Trust on the Blockchain. Available online: https://shorishresearch.com/wp-content/uploads/2017/11/shorish_research_wp_2017a.pdf (accessed on 26 December 2020).
- Szabo, N. Formalizing and securing relationships on public networks. First Monday 1997, 2, 9. [Google Scholar] [CrossRef]
- Ethereum Whitepaper. Available online: https://ethereum.org/en/whitepaper/ (accessed on 21 December 2020).
- Swan, M. Chapter Five—Blockchain for Business: Next-Generation Enterprise Artificial Intelligence Systems. Adv. Comput. 2018, 111, 121–162. [Google Scholar]
- Etter, D.M.; Kuncicky, D.C. Introduction to MATLAB; Prentice-Hall: Upper Saddle River, NJ, USA, 2011. [Google Scholar]
- Faqiry, M.N.; Das, S. Double-Sided Energy Auction in Microgrid: Equilibrium Under Price Anticipation. IEEE Access 2016, 4, 3794–3805. [Google Scholar] [CrossRef] [Green Version]
- Lee, J.H. A New distribution Energy Market Using Asynchronous Double Auction Mechanism. Master’s Thesis, Sogang University, Seoul, Korea, 2019. [Google Scholar]
- Park, J.H.; Kim, Y.S.; Eom, I.K.; Lee, K.Y. Economic load dispatch for piecewise quadratic cost function using Hopfield neural network. IEEE Trans. Power Syst. 1993, 8, 1030–1038. [Google Scholar] [CrossRef] [Green Version]
- Liang, X.; Li, X.; Lu, R.; Lin, X.; Shen, X. UDP: Usage-based dynamic pricing with privacy preservation for smart grid. IEEE Trans. Smart Grid 2013, 4, 141–150. [Google Scholar] [CrossRef] [Green Version]
- Fan, Z. A distributed demand response algorithm and its application to PHEV charging in smart grids. IEEE Trans. Smart Grid 2012, 3, 1280–1290. [Google Scholar] [CrossRef]
- Misra, S.; Bera, S.; Oiha, T. D2p: Distributed dynamic pricing policy in smart grid for PHEVs management. IEEE Trans. Parallel Distrib. Syst. 2015, 26, 702–712. [Google Scholar] [CrossRef]
- Chekired, D.A.; Khoukhi, L.; Mouftah, H.T. Decentralized cloud-SDN architecture in smart grid: A dynamic pricing model. IEEE Trans. Ind. Inform. 2018, 14, 1220–1231. [Google Scholar] [CrossRef]
- Singh, S.; Singh, N. Blockchain: Future of financial and cyber security. In Proceedings of the 2016 2nd International Conference on Contemporary Computing and Informatics(IC3I), Greater Noida, India, 14–17 December 2016; pp. 463–467. [Google Scholar]
- Solidity. Available online: https://solidity.readthedocs.io/en/v0.5.11/ (accessed on 28 September 2019).
- Skowronski, R. On the applicability of the GRIDNET protocol to Smart Grid environments. In Proceedings of the 2017 IEEE International Conference on Smart Grid Communications, Dresden, Germany, 23–27 October 2017; pp. 200–206. [Google Scholar]
- Skowronski, R. The open blockchain-aided multi-agent symbiotic cyber-physical systems. Future Gener. Comput. Syst. 2019, 94, 430–443. [Google Scholar] [CrossRef]
- Aitzhan, N.Z.; Svetinovic, D. Security and privacy in decentralized energy trading through multi-signatures, blockchain and anonymous messaging streams. IEEE Trans. Dependable 2016, 15, 840–852. [Google Scholar] [CrossRef]
- Warren, J. Bitmessage: A Peer-to-Peer Message Authentication and Delivery System. 2012. Available online: http://kevinriggen.com/files/bitmessage.pdf (accessed on 1 June 2020).
- Nakamoto, S. Bitcoin: A Peer-to-Peer Electronic Cash System. 2008. Available online: https://bitcoin.org/bitcoin.pdf (accessed on 1 June 2020).
- Victoria, H.; Val, M. A persona-based approach to domestic energy retrofit. Build. Res. Inf. 2014, 42, 462–476. [Google Scholar]
- go-ethereum. Available online: https://github.com/ethereum/go-ethereum (accessed on 8 October 2020).
- Whisper. Available online: https://github.com/ethereum/go-ethereum/wiki/Whisper (accessed on 10 November 2019).
- Mining. Available online: https://github.com/ethereum/go-ethereum/wiki/Mining (accessed on 3 June 2020).
- ERC: Token standard #20. Available online: https://github.com/ethereum/eips/issues/20 (accessed on 26 November 2019).
- Node.js. Available online: https://github.com/nodejs/node/blob/master/README.md (accessed on 3 June 2020).
- bignumber.js. Available online: https://mikemcl.github.io/bignumber.js/ (accessed on 19 October 2020).
- Etherscan. Available online: https://etherscan.io (accessed on 4 January 2021).
- Galal, H.S.; Youssef, A.M. Verifiable sealed-bid auction on the ethereum blockchain. Financ. Cryptogr. Data Secur. 2019, 265–278. [Google Scholar] [CrossRef]
txAddrX | An externally owned account in Ethereum for X |
msgAddrX | An address for X in Ethereum messaging Whisper |
txAddr | Transaction address of the i-th producer |
msgAddr | Message address of the i-th producer |
txAddr | Transaction address of the j-th consumer |
msgAddr | Message address of the j-th consumer |
Energy amount injected by prosumer i | |
Producer’s energy ownership structure | |
Consumer’s energy ownership structure | |
Amount of intent to sell | |
Matched amount of | |
Amount of demand to buy | |
Matched amount of |
Parameter (Postfix) | Description |
i.MaxSupply | The maximum supply that prosumer i can request to sell |
i.MinSupply | The minimum supply that prosumer i can request to sell |
j.MaxDemand | The maximum demand that consumer j can request to buy |
j.MinDemand | The minimum demand that consumer j can request to buy |
i.PriceUp, j.PriceUp | Highest price (No more increase/decrease in supply/demand after the price reaches this value) |
i.PriceDown, j.PriceDown | Lowest price (No more increase/decrease in supply/demand after the price reaches this value) |
Average Energy Supply per Hour | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Hour | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
kWh | 388 | 386 | 401 | 416 | 442 | 468 | 503 | 538 | 573 | 608 | 637 | 665 |
Hour | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
kWh | 696 | 727 | 736 | 745 | 738 | 731 | 695 | 658 | 596 | 534 | 435 | 336 |
Average Energy Demand per Hour | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Hour | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
kWh | 336 | 324 | 330 | 335 | 353 | 370 | 406 | 442 | 493 | 544 | 580 | 616 |
Hour | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
kWh | 651 | 686 | 702 | 718 | 707 | 696 | 657 | 618 | 530 | 442 | 335 | 228 |
Prosumer | Supply | Consumer | Demand |
---|---|---|---|
1 | 71 kWh | 1 | 50 kWh |
2 | 55 kWh | 2 | 53 kWh |
3 | 60 kWh | 3 | 35 kWh |
4 | 100 kWh | 4 | 60 kWh |
5 | 50 kWh | 5 | 30 kWh |
Total | 336 kWh | Total | 228 kWh |
Prosumer | Matched Supply | Unmatched Supply | Consumer | Matched Demand |
---|---|---|---|---|
1 | 48 kWh | 23 kWh | 1 | 50 kWh |
2 | 37 kWh | 18 kWh | 2 | 53 kWh |
3 | 41 kWh | 19 kWh | 3 | 35 kWh |
4 | 68 kWh | 32 kWh | 4 | 60 kWh |
5 | 34 kWh | 16 kWh | 5 | 30 kWh |
Total | 228 kWh | 108 kWh | Total | 228 kWh |
Prosumer | Paid | Consumer | Refund |
---|---|---|---|
1 | 4747.2 | 1 | 1555 |
2 | 3659.3 | 2 | 1648.3 |
3 | 4054.9 | 3 | 1088.5 |
4 | 6725.2 | 4 | 1866 |
5 | 3362.6 | 5 | 933 |
Total | 22,549.2 | Total | 7090.8 |
Function | Gas Consumption | Gas Cost ($) |
---|---|---|
Deployment | 3,003,112 | 552.90 |
Register | 160,284 | 29.51 |
Inject | 131,679 | 24.24 |
Request to Buy | 23,523 | 4.33 |
Request to Sell | 23,591 | 4.34 |
Matching | 354,520 | 65.27 |
Transfer | 25,574 | 4.71 |
Total Gas Consumptions | |
---|---|
4 Prosumers and 4 Consumers | |
3,003,112 | 3,003,112 |
1,282,272 | ( + ) × 160,284 |
526,716 | × 131,679 |
94,092 | × 23,523 |
94,364 | × 23,591 |
354,520 | 354,520 |
204,592 | () × 25,574 |
5,559,668 | 3,357,632 + × 341,128 + × 209,381 |
Our System | Galal and Youssef [29] | ||
---|---|---|---|
Function | Gas Consumption | Function | Gas Consumption |
Deployment | 3,003,112 | Deployment | 3,131,261 |
Register | 160,284 | Bid | 130,084 |
Inject | 131,679 | Reveal | 132,849 |
Request to Buy | 23,523 | ClaimWinner | 166,288 |
Request to Sell | 23,591 | ZKPCommit | 656,689 |
Matching | 354,520 | ZKPVerify | 2,002,490 |
Transfer | 25,574 | VerifyAll | 46,580 |
Withdraw | 47,112 | ||
Total | 3,722,283 | Total | 6,313,353 |
Participant | Contents | Per Participant | |
---|---|---|---|
Prosumer | Energy ownership states (5 key/value pairs) + Account | 5 × 64 bytes + 52 bytes = 372 bytes | × 372 bytes |
Consumer | Energy ownership states (3 key/value pairs) + Account | 3 × 64 bytes + 52 bytes = 244 bytes | × 244 bytes |
DSO | Management (ex. Price Setting) | 2 KB | 2 KB |
Smart Contract | Registration of participants | 96 bytes per participant | ( + + 1) × 96 bytes |
Total | - | - | ( × 468 + × 340 + 2144) bytes |
Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations. |
© 2021 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).
Share and Cite
Song, J.G.; Kang, E.s.; Shin, H.W.; Jang, J.W. A Smart Contract-Based P2P Energy Trading System with Dynamic Pricing on Ethereum Blockchain. Sensors 2021, 21, 1985. https://doi.org/10.3390/s21061985
Song JG, Kang Es, Shin HW, Jang JW. A Smart Contract-Based P2P Energy Trading System with Dynamic Pricing on Ethereum Blockchain. Sensors. 2021; 21(6):1985. https://doi.org/10.3390/s21061985
Chicago/Turabian StyleSong, Jae Geun, Eung seon Kang, Hyeon Woo Shin, and Ju Wook Jang. 2021. "A Smart Contract-Based P2P Energy Trading System with Dynamic Pricing on Ethereum Blockchain" Sensors 21, no. 6: 1985. https://doi.org/10.3390/s21061985
APA StyleSong, J. G., Kang, E. s., Shin, H. W., & Jang, J. W. (2021). A Smart Contract-Based P2P Energy Trading System with Dynamic Pricing on Ethereum Blockchain. Sensors, 21(6), 1985. https://doi.org/10.3390/s21061985