## 1 Introduction  
Energy crisis and environmental pollution have become two critical concerns in the last decade [1]. The smart grid with renewable energy resources is a promising approach to alleviate these problems, and its implementation can be facilitated by microgrids. In smart grids, new models, technologies, and flexible solutions are to be developed for intelligent energy management, to facilitate the optimal energy and power flow strategies. Specifically, energy trading, as an essential component in energy management, is undergoing an evolution from centralized to distributed manner. In the traditional energy market, the energy users can only buy electricity from the power utilities. In a smart grid, the energy users play a role as both power consumer and supplier. The excessive renewable energy generations can be traded with the utility and other users in the deficit of power supplies for mutual benefits. The development of the traditional centralized energy market model has encountered bottlenecks and faced many problems [2]:  
1. Centralized management: In traditional energy market model, energy trading highly relies on the centralized third party servers, thus it is apt to cause single point of failures [3; 4]. In addition, the centralized management leads to high operating costs, low transparency, and the potential risk of transaction data tampering [5]. 2. Privacy protection and security issues. Third parties may disclose the user's energy generation pattern and predict a user's daily activities based on historical data [6; 7]. Meanwhile, communication security is also a challenging issue [8]. 3. The lack of competition between renewable energy pricing and traditional market pricing will discourage the investment in renewable energy [9]. 4. The power grid lacks the resilience to cyber-attacks [10]. 5. Electricity comes mainly from large energy plants, which needs to pass through long-distance power transmission line before reaching the end customers. Due to the complexity of the power management, it is difficult to meet the dynamic energy demands timely and flexibly [11]. 6. Long-distance one-way energy transmission makes the power supply be vulnerable to disruptions. In modern electrical power systems, the distributed bidirectional energy management is desirable to improve the system efficiency and stability [11; 12]. Additionally, in the transition from traditional power grid to smart power grid, the efficiency, demand, cost and emission issues also need to be fully considered [13]. Meanwhile, as an emerging technology, blockchain has been widely adopted in many fields for its well-known advantages [14; 15]. Blockchain was indeed flawed when it first emerged. Nevertheless, studies have found these problems and made corresponding improvements, such as the measurement research and exploration of the re-parameterization of blockchain to improve its scalability [16]; the Bitcoin-NG [17], which can tolerate Byzantine fault tolerance and achieve very good scalability; and the Protocol \"Ouroboros Praos\", which can defend against complete adaptive corruption [18]. The application fields of the blockchain technology include finance, Internet of Things [19], public social services, reputation system, security and privacy, and so on [20]. For example, in [21], blockchain is used to enhance privacy through a decentralized personal information management system. It can ensure that users have control over data, proving that blockchain may serve as an important tool for trusted computing. The Hawk model proposed in [22] also addresses the issue of transaction privacy, by using an intelligent contract system that enables the compiler to automatically generate an efficient encryption protocol. As for the Internet of Things, blockchain can enable the sharing of services and resources, and automate several existing time-consuming workflows in the form of cryptographic authentication [23]. Beekeeper, a secure blockchain-based threshold IoT service system is proposed in [24].