## 1 Introduction  
Since 2008, when Bitcoin has emerged as the first label of blockchain application for decentralized currency [1], it has opened the eyes to a new paradigm which is decentralization, and its potential as a new disruptor in various industries. After the emergence of Ethereum and the smart contract concept, blockchain potential for enabling decentralized applications beyond finance has been unlocked. Since then, many companies have tried to adopt this technology in different sectors varying from e-voting, supply chain tracking, health care, agriculture, and so on. Another sector where blockchain technology is presenting itself as a new revolution is the Energy market [2]. In the recent past, in traditional centralized electric power systems, customers have been at the end of the supply chain. With the advent of smart grids, we are witnessing the disclosure of distributed energy resources (DERs) based on renewable energies that can contribute to the electricity system. This led to a paradigm shift in the energy trading architecture and the emergence of new players in the market, where consumers are becoming \"prosumers\" who may sell their surplus of energy to neighboring consumers. Power is produced using rooftop solar PV installations, micro wind generators, and battery energy storage systems [3; 4]. This new concept of prosumers ushered in a new era of what is known as Peer-to-Peer (P2P) energy trading, where generating nodes can enter the energy market as providers. However, it is difficult for parties involved in the trading to trust each other without the supervision of a central entity or any other middle broker organization. Providers cannot guarantee being paid for the energy they supply to the client, and clients cannot guarantee being supplied the requested energy if paying in advance. In such a scenario, the basic value of coupling energy with cryptocurrencies and blockchain technology [5] is a staple that enables the forcible payments and energy supply through a distributed smart contract [6]. Being embedded in the blockchain, smart contracts are reshaping the wave of innovation in today's technology in terms of automatic agreements between two parties, while excluding the intervention of a trusted third party. They allow services costs saving and reduce the risks of potential corrupt central entities [7]. In this work, we are presenting a P2P energy trading platform where energy can be traded in a decentralized manner on an Ethereum private blockchain. The energy traded on the platform is electrical energy, thus the two terms energy and electricity as well as client and consumer will be used interchangeably in this paper. The key features which the architecture of the Proposed P2P energy trading system involve:  
* Dynamic Time of Use pricing: This would maximize profit and enable consumers to get an appropriate and accurate demand response. The tariffs are proposed ahead of each trading period, based on energy consumption predictions using machine learning techniques [8]. The tariffs are then implemented in the smart contract to enable autonomous billing. A new smart contract is created ahead of each upcoming trading round, with updated tariffs based on the trading round electricity consumption predictions. Moreover, the tariffs are made known immediately after each trading round and their validity can be verified by all participants, since each one would be having his copy of the shared ledger containing the training set data. Indeed, each participant is aware of the state history representing the energy consumption data that is used in the prediction process. Based on the predictions, ToU ranges are defined using the K-mean clustering algorithm, implemented on a smart contract, and executed on the blockchain. This ensures that the ToU ranges are reliable and bias-free, since they are defined by an independent autonomous smart third party. * Prevention against fraudulent behavior: Considering energy is traded online, it is critical to ensure that the same energy is not sold more than once.