Electric Vehicles Charging Using Photovoltaic Energy Surplus: A Framework Based on Blockchain

<jats:p>In the present day, it is crucial for individuals and companies to reduce their carbon footprints in a society more self-conscious about climate change and other environmental issues. In this sense, public and private institutions are investing in photovoltaic (PV) systems to produce clean energy for self-consumption. Nevertheless, an essential part of this energy is wasted due to lower consumption during non-business periods. This work proposes a novel framework that uses solar-generated energy surplus to charge external electric vehicles (EVs), creating new business opportunities. Furthermore, this paper introduces a novel marketplace platform based on blockchain technology to allow energy trading between institutions and EV owners. Since the energy provided to charge the EV comes from distributed PV generation, the energy’s selling price can be more attractive than the one offered by the retailers—meaning economic gains for the institutions and savings for the users. A case study was carried out to evaluate the feasibility of the proposed solution and its economic advantages. Given the assumptions considered in the study, 3213 EVs could be fully charged by one institution in one year, resulting in over EUR 45,000 in yearly profits. Further, the economic analysis depicts a payback of approximately two years, a net present value of EUR 33,485, and an internal rate of return of 61%. These results indicate that implementing the proposed framework could enable synergy between institutions and EV owners, providing clean and affordable energy to charge vehicles.</jats:p>

section_content: The increased awareness of climate change effects advancing toward a net-zero economy has driven investments in sustainable technologies. Therefore, decarbonisation strategies are gaining prominence in many countries' government agendas [1]. However, transportation remains one of the most pollutant economic sectors. For instance, road transportation alone contributes approximately 25% of total emissions [2] [3] [4] in the European Union (EU). Although accounting for a third of total energy demand, it is also the sector with the lowest use of Renewable Energy Sources (RES) [5]. Therefore, promoting the electrification of transportation means can enhance energy security, climate change mitigation, and reduce air pollution in urban environments [6]. Electric mobility is the most viable option for passenger cars and small trucks, while railroad freight, aviation, and shipping are still future challenges. Thus, many governments are applying subsidies and tax reductions to expand the adoption of electric vehicles (EVs) in cities [7]. One is the European Green Deal, which established a set of propositions to review and update EU legislation on climate, energy, and transportation, aiming for carbon neutrality [8]. 

With the expected growth of EVs, there is a need for more resilient power systems to prevent overloading the distribution network [9]. To address this issue, integrating buildings with distributed energy generation, such as solar and wind power, along with EVs, is a practical strategy that can enhance the grid's robustness [10]. Many studies argue that only charging EVs with a large share of RES can effectively reduce greenhouse gas (GHG) emissions [11] [12] [13]. Thus, combining EV charging stations with photovoltaic (PV) solar systems can play an essential role in decarbonising the transportation sector and improving grid resilience simultaneously. In addition, it is essential to note that achieving a more sustainable mobility system requires considering a variety of factors. A circular EV manufacturing framework [14, 15], the development of local industrial chains [16], and battery recycling [17] [18] [19] [20] are all essential components that must be incorporated to create a more sustainable and resilient transportation sector. For instance, the production of batteries is expected to reach approximately 2500 GWh by 2025 [21]. In this scenario, greater technological advancements are required to enhance autonomy, affordability, and sustainability throughout the battery life cycle. Therefore, the circular battery industry is emerging as a vital contributor to the energy transition, as it can aid in reducing costs and minimising waste resources. 

More specifically, this paper discusses the integration of EVs and PV towards sustainable transportation. The adoption of distributed generation has experienced a steady increase in recent years, primarily due to the economic advantages of installing PV panels in residential and commercial buildings. Furthermore, policymaking also plays a role in the dissemination of distributed generation. For instance, it is expected that the EU commission will require the installation of PV panels in new buildings and buildings undergoing roof renovations (for public, commercial, residential use, and parking lots) by 2023 [22, 23]. The panorama is promising; however, integrating EVs and PV generation still needs to surpass some limitations to be employed extensively. Factors such as generation intermittency, market prices, and charging infrastructure availability are vital in evaluating the system's benefits and viability. Another challenge refers to PV energy surplus generation. Typically, the generated energy is sent back to the grid during non-business periods (e. g., weekends, holidays, and summer vacations). Storing electricity is expensive and does not configure the ideal solution to deal with such an energy surplus. Further, there is a lack of a market focused on using such clean energy. 

In this sense, encouraging energy policies to support the penetration of RES, such as Feed-in-Tariffs (FIT), Feed-in-Premiums (FIP), and quota obligations, can play a role in response to the rising demand for electricity. It should be noted that the current wholesale market model is inadequate for scenarios with significant levels of RES penetration. In the past, implementing these tariffs was successful in many countries, such as the UK, Germany, Japan, and others. However, the price offered to those who sell energy to the grid is no longer attractive, leading to the increased adoption of more profitable mechanisms, such as blockchain, in many cases [24]. 

In this panorama, this study proposes to evaluate the potential to charge EVs using PV energy surplus at a more competitive price than those offered by the retailer market. This power system configuration alleviates the grid burden while promoting a clean well-towheel EV operation. Such an energy trading market would need a reliable and decentralised transaction platform to become feasible. There is some research related to using energy surplus for charging EVs [25] [26] [27] [28]. However, most studies do not present a reliable business model for transacting energy between the parties. This research proposes developing a blockchain-based energy transaction framework to address this gap. In this sense, the contributions of our work are as follows:
section_name: Introduction

section_content: We introduce a reliable and economically consistent business model for energy trading between small energy producers and EV owners, filling a critical gap in the existing literature.
section_name: •

section_content: We present a blockchain-based application that enables energy trading in a decentralised market, providing a secure and transparent means of performing transactions.
section_name: •

section_content: We evaluate the feasibility of utilising surplus PV-generated energy from small energy producers to charge EVs, offering a promising solution for promoting sustainable energy use.
section_name: •

section_content: We conduct a case study to assess the economic and environmental impacts of the proposed framework, demonstrating its potential as a viable and effective means of promoting sustainable energy practices. 

This paper is organised as follows. Section 2 presents the literature that grounds this work, highlighting methods and gaps. Section 3 exposes the methodological approach developed in this paper. Section 4 introduces the case study carried out in this work and discusses the results. Section 5 concludes this paper and presents limitations and future work perspectives.
section_name: •

section_content: EVs are a crucial piece for the success of decarbonising our planet. Beyond playing a role in the transportation sector as our daily locomotion source, EVs also can be integrated with the power grid as a supporting tool for decentralising electricity generation in coordination with Battery Energy Storage Systems (BESS) and demand response programs [29]. In this sense, a collection of studies with important contributions from the literature is provided in this section-the first two subsections present studies concerning the integration of EVs and distributed energy generation systems (mainly PV). We detailed the methods, objectives, and outcomes of each of them. The last subsection introduces some studies concerning blockchain technology applications in the EV sector.
section_name: Overview of EVs and Distributed Energy Systems Integration

section_content: The authors in [30] introduced a detailed review regarding better-integrating EVs and buildings considering PV generation with BESS. The paper discussed technology trends, economic factors, and user acceptance (a significant factor in investment decisions for distributed energy systems). In [31], an EV fleet was employed as BESS to absorb the surplus of wind and solar generation in dry land in India, working together as a hybrid renewable energy microgrid. Another study integrating wind and solar generation with EVs was developed in [32]. Solar-energy-producing and consuming assets (e. g., EVs, PV panels, and wind power turbines) were coordinated with other agents such as smart lamps, BESS, computers, and other facilities in a multi-agent interaction mode. The local energy surplus charges the EVs parked at the building instead of sending it to the grid. In [33], the authors developed a novel energy management system using a Building-to-Vehicleto-Building scheme. Single-family houses and office spaces are connected in a microgrid using EVs as BESS and transferring system. The buildings generate an energy surplus using PV-mounted panels, which will later feed the local BESS and the EVs or be sold to the power grid. Another illustration of integrating buildings with local surplus generation and EVs was demonstrated in [34]. In this case, the excess power generated by a high-rise office building in Hong Kong was stored in EV batteries to improve system performance. Additionally, the system was integrated with BESS. The authors of [35] proposed the development of transactive energy communities using stationary and mobile BESS as flexibility sources. The framework accounted for a microgrid community of buildings on a university and EV charging stations on site. The outcomes indicated an increase in RES self-consumption and a reduction in electricity costs using the proposed framework. Creating a bridge between the integration of EVs with PV and the use of optimisation applied for this subject, Vopava et al. [36] investigated the synergistic effects between EVs charged at work and PV potential in Leoben (Austria), using a cell-based grid model and simulations for different scenarios. The results showed that overloads due to PV production could not be avoided but could be reduced with the right charging control strategy of the vehicles. Daily and seasonal fluctuations in surplus were identified using accurate irradiation data.
section_name: PV Energy Generation and EVs

section_content: Focusing on the use of Machine Learning (ML) and Mathematical Optimization (MO) methods, the authors of [37] investigated the operation of an energy management system in a smart office building connected to a microgrid with distributed energy resources. The study considered the stochastic driving behaviour of a fleet. The authors developed a Mixed-Integer Linear Programming (MILP) approach to evaluate the impacts of an EV driving schedule. Regarding optimisation methods for EV-building integration, the study in [38] proposed a novel control strategy called Boundary Expansion Scenario to mitigate the limited use of EV batteries beyond the boundary of a zero-emission office building supported by a hybrid PV and wind turbine generation system. A combination of ML and MO was presented in [39]. The authors developed an MILP model to integrate a PV-based energy system with onsite BESS and EV fleets in residential buildings in Belgium. The objectives were to minimise the import electricity costs and optimise the charging operations of batteries and EVs. A supervised learning algorithm called Gradient Tree Boosting Ensemble predicted the PV production and EV power values. Later, the acquired data were optimised with an MILP approach. A total of 10 scenarios were simulated, and the best scenario presented an annual cost reduction of 31% and an increase of the onsite-energy fraction of 23%. According to the authors, the proposed framework has the potential to bring buildings closer to achieving a net-zero energy balance. The authors of [40] presented an MO model to prioritise charging and discharging EVs with the surplus in a workplace in Japan, considering charging availability and battery capacities that allowed the vehicles to work as a flexible energy source for a workplace. An MILP optimised the current charging and discharging schemes to achieve the objectives. Later, an optimisation electric-load dispatching model was created to prioritise the mentioned methods. In [41] was proposed an MILP framework to evaluate the cooperative interaction of a fleet of EVs with PV generation in a building. The authors considered three main aspects: (i) the possibility of bidirectional energy trading; (ii) the impact of PV intermittent generation in charging the vehicles when compared with a deterministic scenario; and (iii) the effect of selling energy back to the grid in the face of different prioritisation factors. The outcomes indicated the necessity of considering the stochastic behaviour of energy generation to operate microgrid systems better.
section_name: Optimisation Frameworks for EVs in the Context of Distributed Generation

section_content: The main contribution of this work is to develop a framework that uses blockchain to transact surplus energy for charging EVs. Such an approach is novel in the literature, to the best of found knowledge. However, blockchain has been applied in transactions that involve EV users, and the findings are presented as follows. In [42], the authors developed an EV energy demand prediction model based on deep learning. To avoid data privacy leak problems, the authors implemented a novel blockchain framework, preserving the predicted energy demands of the charging networks. The paper presented a cryptosystem-based secure communication protocol to guarantee the confidentiality of the data. In [43], a blockchain-based smart charging station management platform was proposed. The method protects EV users' privacy, ensures transaction fairness, and meets energy demands. The authors employed a smart-contract framework to integrate the energy management system. The outcomes indicated the feasibility of the strategies since it dealt with feeder congestion, power supply, and grid demand imbalance in real-time. A novel hierarchical blockchain architecture for a vehicle-to-grid (V2G) trading system was presented in [44]. In [45], the authors designed a Peer-to-Peer (P2P) transaction model on the basis of blockchain to incentivise consumers to inject reactive power into the grid to minimise voltage drops and active power to minimise cable loading. The main objective was to improve grid resilience and enable optimal EV charging and discharging. The authors in [46] introduced the concept of EV-shared charging, where charging stations were shared among users to avoid grid congestion or lack of charging infrastructures. The paper proposed a blockchain architecture to build a trusting environment among the actors involved in the charging process. The article in [47] implemented a blockchain structure for EV energy trading. To guarantee security, the authors integrated an interplanetary file system with a double auction mechanism handled through a remix smart contract environment. In [48], a PV-EV bidding model considered carbon emissions and distributed storage. Blockchain smart contract technology was employed to guarantee the reliability of the transactions. A similar approach was proposed in [49]. The authors outlined a novel energy trading platform that used blockchain technology to facilitate transparent transactions through smart contracts without requiring the involvement of a third party. That platform was designed to serve prosumers who generate excess electricity and those who use energy stored in BESS. Transactions between sellers and buyers occurred within a P2P network. In [50], the advantages of integrating blockchain with energy trading systems were highlighted, such as direct transactions between prosumers and consumers, anti-bribery and corruption measures, and increased share of RES. Future improvements in privacy and security, power management, and integration with artificial intelligence were also suggested. Another blockchain technology advance was demonstrated in [51], where the EVs acted as prosumers together with other players (buyers and sellers) in a novel P2P energy-backed token market. The vehicles could interact bilaterally (as buyers and sellers) with the market during the scheduled period, allowing them to participate in the electricity market with real-time pricing and increase their welfare. 

Table 1 summarises the literature review findings by comparing the references most aligned with this study, approaching research perspectives, applied methodology, and evaluation aspects.
section_name: Blockchain Application in the EV Sector

section_content: In this section, we introduce an overview of the business model applied in the context of this research to make energy surplus transactions profitable for small producers and more affordable for EV users. In the case study, we further discuss and evaluate this business model (see Section 4). Later, we also present the blockchain energy trading framework based on Ethereum Smart Contracts. Figure 1 summarises the developed methodology of this paper. 

Energies 2023, 16, x FOR PEER REVIEW 6 of 25

Generation/Demand matching x x x Charging operation optimisation x x x x x
section_name: Methodological Approach

section_content: In this section, we introduce an overview of the business model applied in the context of this research to make energy surplus transactions profitable for small producers and more affordable for EV users. In the case study, we further discuss and evaluate this business model (see Section 4). Later, we also present the blockchain energy trading framework based on Ethereum Smart Contracts. Figure 1 summarises the developed methodology of this paper.
section_name: Methodological Approach

section_content: The business model considers entities (e. g., companies, private organisations, and public institutions) that produce renewable energy for self-consumption as energy providers. In this context, some energy is wasted due to lower consumption during non-business periods. This surplus could be used to charge EVs, creating new business opportunities. In this panorama, the energy selling price could be more attractive than the ones employed in the regular energy market-since the energy source would come from distributed generation. To join the energy production entities with the EV owners, we propose developing a mobile application (named Blockcharging). The application would be responsible for informing the users of the location/availability of the chargers with energy surplus and validating the energy transactions through a marketplace on the basis of blockchain (detailed in Section 3. 2). It is essential to highlight that power availability may be compromised due to adverse weather conditions (e. g., cloudy sky, rain, or snow), jeopardising the charging service. In this situation, as a last resort, the charging operation would be completed using energy from the grid. Figure 2 depicts the primary interfaces of the application. 

Further, it is expected that the application will have the following attributes:

• Responsiveness: Support for smartphones and tablets. 

• Integration: Ability to provide solutions for application connectivity to the database. 

• Application Architecture: Ability to support native and hybrid applications. Crossplatform support. 

• Management and Security: Ability to provide secure user authentication methods and payment gateways.
section_name: Business Model

section_content: The business model considers entities (e. g., companies, private organisations, and public institutions) that produce renewable energy for self-consumption as energy providers. In this context, some energy is wasted due to lower consumption during non-business periods. This surplus could be used to charge EVs, creating new business opportunities. In this panorama, the energy selling price could be more attractive than the ones employed in the regular energy market-since the energy source would come from distributed generation. To join the energy production entities with the EV owners, we propose developing a mobile application (named Blockcharging). The application would be responsible for informing the users of the location/availability of the chargers with energy surplus and validating the energy transactions through a marketplace on the basis of blockchain (detailed in Section 3. 2). It is essential to highlight that power availability may be compromised due to adverse weather conditions (e. g., cloudy sky, rain, or snow), jeopardising the charging service. In this situation, as a last resort, the charging operation would be completed using energy from the grid. Figure 2 depicts the primary interfaces of the application. 

Further, it is expected that the application will have the following attributes:

• Responsiveness: Support for smartphones and tablets.
section_name: Business Model

section_content: Integration: Ability to provide solutions for application connectivity to the database.
section_name: •

section_content: Application Architecture: Ability to support native and hybrid applications. Crossplatform support.
section_name: •

section_content: Management and Security: Ability to provide secure user authentication methods and payment gateways. 

Figure 3 illustrates the business model developed for this framework. The main objective is to introduce an economically viable and sustainable value proposition while also promoting the adoption of EVs and diversification of charging infrastructure. The application would operationalise the transactions between EV owners and energy production entities. The energy surplus selling price would be approximately 25% less expensive than the price performed in the conventional EV charging market. Such a price scheme is possible due to the decentralisation of energy generation. To illustrate, The application would operationalise the transactions between EV owners and energy production entities. The energy surplus selling price would be approximately 25% less expensive than the price performed in the conventional EV charging market. Such a price scheme is possible due to the decentralisation of energy generation. To illustrate, Table 2 compares the tariffs incurred when using public chargers and Blockcharging (for the values, see Section 4. 2).
section_name: •

section_name: Tariff

section_content: Price varies according to the daily schedule x x Electric Mobility Suppliers (EMS)

x -Charging Point Operator (CPO)

x -Value-Added Tax (VAT)

x x Special Tax on Electricity (STE)

x -

In the current energy commercialisation market model, different tariffs are charged daily to meet the load demand variation associated with energy supply costs. However, our business model applies a unique and competitive price and revenue based on a transaction commission of 20%.
section_name: Public Chargers Blockcharging

section_content: This paper proposes a blockchain framework based on Ethereum smart contracts to process financial transactions, aiming for transparency and security. The system works on the basis of a mobile application that serves as a platform between an institution (selling energy) and an EV owner (buying energy). If the customer is interested in charging an EV or fleet for the set price, the Blockcharging system would reliably offer this connection. 

However, before discussing the applicability of blockchain in this research, it is essential to comprehend the evolution of the technology, cyber security issues, and smart contracts. We briefly introduce these concepts in the following. 

Blockchain: Blockchain technology enables transactions to be executed more transparently and democratically and optimises processes by reducing transactional costs. In addition, there is no need for third-party participation in decentralised transactions due to the coordination facility and ensuring the reliability of a P2P database. Transactions are verified before being added to the blockchain through a validation consensus mechanism, making the insertion of fraudulent data almost impossible. It also innovatively allows support for new business model applications, as in the case of this work [53]. Despite its positive impacts, blockchain implementation can be complex and costly. For example, Ethereum processes fewer than 50 transactions per second, which may not be adequate for specific use cases. Furthermore, integrating blockchain with external data sources requires improvement, and regulatory uncertainties and a lack of international standards pose significant challenges. 

Smart Contracts: Smart contracts are computer programs that define actions for various conditions and are deployed into the blockchain. They provide security, transparency, and cost-saving benefits, eliminating the need for third parties to charge transaction fees. Once the contract conditions are met, actions are automatically taken. This approach is more efficient than traditional contracts, which can involve lengthy and error-prone document filling. Algorithm 1 expresses an example of a smart contract's logic acting as an online digital asset store intermediary. Costs to deploy a smart contract: Deployment costs are associated with using a smart contract. The main price is a transactional fee used to reward validators. The complexity of validating a transaction is measured using a unit called Gas. Equation (1) calculates the monthly Ethereum currency (ETH) cost for deploying a smart contract to the Ethereum blockchain. 

where C T is the cost of N transactions in ETH, N is the number of calls to the smart contract, G is the number of Gas units used for a transaction, and P GU is the unitary Gas price and is specific to each blockchain. The value of P GU is not static and is influenced by the network's demand, supply, and condition. The fiat currency cost is determined by the conversion rate of ETH at the time of the transaction. The maximum price for all transactions is regulated by the value of N, which can be approximated through average computation or forecasting. Developers can restrict the number of gas units (G) used in a transaction to a maximum value of G L. Transactions that exceed this limit will fail. The parameter G, which depends on the complexity of the contract, is the only aspect that developers can control. 

Blockcharging transactions logic: The logic behind the transactions is described in Figure 4, where the Ethereum smart contract plays a significant role. 

Energies 2023, 16, x FOR PEER REVIEW 10 of 25

where C T is the cost of N transactions in ETH, N is the number of calls to the smart contract, G is the number of Gas units used for a transaction, and P GU is the unitary Gas price and is specific to each blockchain. The value of P GU is not static and is influenced by the network's demand, supply, and condition. The fiat currency cost is determined by the conversion rate of ETH at the time of the transaction. The maximum price for all transactions is regulated by the value of N, which can be approximated through average computation or forecasting. Developers can restrict the number of gas units (G) used in a transaction to a maximum value of G L. Transactions that exceed this limit will fail. The parameter G, which depends on the complexity of the contract, is the only aspect that developers can control. 

Blockcharging transactions logic: The logic behind the transactions is described in Figure 4, where the Ethereum smart contract plays a significant role. 

Customers can schedule the EV charging through the mobile application. The application interacts with the producer to evaluate the current surplus and the charging point availability and interacts with the corresponding smart contract to initiate the transaction protocol. The smart contract is programmed to ensure that all stakeholders meet the terms and conditions to carry out the trade. Each operational charging point is associated with a smart contract. Once this is characterised as P2P trading, the trustless aspect of the smart contract makes it a strong candidate to operate the transaction logic since its content is observable and immutable, rendering a secure and transparent solution. The algorithm proposed to carry out the transaction is depicted in Figure 5 (source code available in the Data Availability section). The smart contract can be modelled as a state machine, where the rectangles represent the different states, and the arrows represent other functions. Customers can schedule the EV charging through the mobile application. The application interacts with the producer to evaluate the current surplus and the charging point availability and interacts with the corresponding smart contract to initiate the transaction protocol. The smart contract is programmed to ensure that all stakeholders meet the terms and conditions to carry out the trade. Each operational charging point is associated with a smart contract. Once this is characterised as P2P trading, the trustless aspect of the smart contract makes it a strong candidate to operate the transaction logic since its content is observable and immutable, rendering a secure and transparent solution. The algorithm proposed to carry out the transaction is depicted in Figure 5 (source code available in the Data Availability section). The smart contract can be modelled as a state machine, where the rectangles represent the different states, and the arrows represent other functions.
section_name: Blockchain Applied in the Context of This Research

section_content: • Charger Available is the state that represents a charger ready to be used. If there is energy available, any eligible user can make a reservation. The smart contract verifies the user's eligibility.
section_name: State descriptions:

section_content: Charger Reserved is the state where the smart contract locks a specific charger to a particular customer. If the user does not get to the charger within a predefined time window, the smart contract frees the charging point by reversing the smart contract's state to the Charger Available state via the Reject function.
section_name: •

section_content: Charging Started is the state where the actual energy transfer is being performed. From this point forward, the customer is always set for the energy transferred. In this state, the smart contract holds the currency necessary for the desired charging session. These funds will be transferred to the energy seller once the charging is complete.
section_name: •

section_content: Charging Complete is the state where the contract arrives when the user quits charging. After receiving the amount transferred to each part of the trade, this contract automatically executes the Payment function, which transfers the amounts to the stakeholders.
section_name: •

section_content: • Place Order is the function that enables the user to reserve a charging point. To secure a spot, the smart contract checks for eligibility criteria for the user and the charging point itself, such as non-zero funds on the user's wallet and energy availability on the charging point. This function changes the state of the contract to Charger Reserved.
section_name: Functions description:

section_content: Reject is the function that returns the charging point to the default state Charger Available. This function is called whenever the desired condition is unmet in the Charger Reserved state.
section_name: •

section_content: Accept Order is the function which initiates the energy transaction. This function transfers the currency necessary for the charging session to the smart contract. These funds are transferred to the seller once the service is complete. This function changes the state of the contract to Charger Started. State descriptions:

• Charger Available is the state that represents a charger ready to be used. If there is energy available, any eligible user can make a reservation. The smart contract verifies the user's eligibility.
section_name: •

section_content: Accept Order is the function which initiates the energy transaction. This function transfers the currency necessary for the charging session to the smart contract. These funds are transferred to the seller once the service is complete. This function changes the state of the contract to Charger Started.
section_name: •

section_content: Charging Event is the function that is triggered when the charging operation is interrupted. This function calculates the amount of energy sold and translates it to the amount of currency that should be transferred to each party. This function changes the state of the contract to Charging Complete.
section_name: •

section_content: Payment is the function that transfers funds to the stakeholders and performs the necessary checks to return the charger to the Charger Available state. 

Communication and security across the system: It is essential to present some communication and safety measures concerning the developed framework. Two main communication links can be identified throughout the system architecture:
section_name: •

section_content: Front-end to back-end communication: Secure HTTP protocol is the standard communication protocol for this scenario. WebSockets can be used as redundancy. If the application is solely mobile, WebSockets can be fully utilised instead of secure HTTP, thus providing two independent communication channels between the back-and front-end. Secure communication over these protocols can be enforced using modern encryption algorithms
section_name: •

section_content: From the back-end to the smart contract: deploying the smart contract to the blockchain will be assured by a 3rd party platform, such as Azure or IBM. The communication from the back-end server to the blockchain is caried out through APIs built on top of protocols HTTP, WebSockets, or IPC. Existing libraries, such as web3js, provide an API using many of these protocols, with some being used as redundancy. Furthermore, the load on this link is lower than on the back-front link (smart contracts calls are fast). 

Further, to address cybersecurity concerns, [54] proposes the Block Alliance Consensus (BAC) algorithm based on Hashgraph, which is applied to an energy trading blockchain system based on vehicle-to-vehicle transactions. BAC can protect the system from largescale cyber attacks and software errors while supporting dynamic node addition and deletion without requiring high computational power. Additionally, the authors in [55] propose a consortium scheme for EVs in a Smart City environment, using a proof-ofauthority consensus mechanism to validate transactions and smart contracts to ensure fair pricing. The Oyente analysis method is chosen to protect the system against cyber attacks and provide security and privacy for users.
section_name: •

section_content: In this section, we present the case study that grounds the outcomes of this research. The first subsection introduces the institution's characteristics that generate the PV energy surplus. Later, we present the tariffs applied in the context of the Portuguese market to charge EVs and compare the total costs of using a conventional public charger with the framework proposed in this paper. In addition, an estimation of emissions savings is presented. Lastly, we developed an economic analysis that comprehends economic indicators-payback time, Net Present Value (NPV), and Internal Rate of Return (IRR)-to unveil the feasibility of applying the framework in real life.
section_name: Case Study

section_content: The data were acquired from a higher education institution in Lisbon, Portugal, which generates clean energy from PV panels distributed across the campus, with a total installed capacity of 724 kWp. Portugal presents one of the highest solar irradiation indexes in the EU, with annual averages of approximately 1. 8 MWh/m 2 [56]. In this sense, we first calculated the solar irradiation for one year to estimate the energy availability to charge EVs. Figure 6 illustrates the irradiation profile of the institution for the evaluated period. Using the irradiation data and a PV module datasheet [57] and considering the efficiency losses described in Table 3, we estimate the PV energy output for the studied period. We considered Equations ( 2 ) and (3) [58, 59] to calculate the PV energy output. 

where E is the PV energy output (Wh), Pmax (G, T) is the maximum cell power in function of incident solar irradiation and temperature, n is the number of months in the period, PR is the cell performance ratio, G is the incident solar irradiation (W/m 2 ), T is the temperature (°C), A is the PV panel area (m 2 ), η is the solar cell efficiency (%), and Δt is the time of sunlight hours in the i-th month (h). We analysed the institution's energy consumption behaviour using the retrieved solar irradiation profile and summarised the findings in Table 4. Using the irradiation data and a PV module datasheet [57] and considering the efficiency losses described in Table 3, we estimate the PV energy output for the studied period. We considered Equations ( 2 ) and (3) [58, 59] to calculate the PV energy output. 

where E is the PV energy output (Wh), P max (G, T) is the maximum cell power in function of incident solar irradiation and temperature, n is the number of months in the period, PR is the cell performance ratio, G is the incident solar irradiation (W/m 2 ), T is the temperature ( • C), A is the PV panel area (m 2 ), η is the solar cell efficiency (%), and ∆t is the time of sunlight hours in the i-th month (h). We analysed the institution's energy consumption behaviour using the retrieved solar irradiation profile and summarised the findings in Table 4. 

The analysis unveils the availability of energy surplus due to low energy consumption on some days. The consumption is lower in non-working periods (weekends, holidays, and summer vacations), corresponding to almost 40% of the days in a year. In this scenario, the institution is "losing" energy to the grid that could be used to charge EVs. In addition, PV-system owners can negotiate through adjacent markets, such as the carbon emission market, and guarantees of origin market (green certificates market) [60] to reduce their carbon footprint and increase their revenue streams. Selling surplus energy to power EVs can reduce capital expenditure and operating expenses. For instance, European subsidies for the use of renewable energy provide governmental co-participation in the investment related to the installation of RES systems, remuneration for energy produced and delivered to the network, and tax reductions granted to prosumers [61]. These subsidies can significantly impact PV systems' profitability, reducing the electricity generated cost and making them more competitive with conventional energy sources. Subsidies can be based on various factors, including the price of CO 2 emissions and FIP, which can provide financial incentives to PV system owners and increase their profitability. To provide more details, Figure 7 illustrates the energy profile of the institution in August (the month with the highest surplus). The Appendix A presents the other energy profiles. We develop costs and emissions comparisons to assess the benefits of charging the EVs using the developed framework earlier presented. The results are described below. 

Cost Comparison: Considering the taxes applied in the EV charging market, Table 6 We consider a Tesla ® Model Y as a base EV to estimate the number of vehicles that could be charged in one year using only PV-surplus. This vehicle has a battery capacity of 82 kWh and was the best-selling EV in Europe in 2022. Considering the annual energy surplus of 263. 51 MWh in this setting, 3213 EVs could be charged using only clean energy. Considering that vehicles are not usually charged from 0% to 100% SOC, the number of EV owners that can take advantage of this energy surplus could be even higher than this initial estimation. However, the periods of energy surplus generation and EV charging demand may not match. The Blockcharging application can facilitate the connection of EV owners and PV-generation entities in such a situation. Table 5 highlights the parameters employed in this case study.
section_name: Case Study Characteristics

section_content: We develop costs and emissions comparisons to assess the benefits of charging the EVs using the developed framework earlier presented. The results are described below. 

Cost Comparison: Considering the taxes applied in the EV charging market, Table 6 presents the charging costs of slow and fast public chargers in Portugal. We considered a Tesla ® Model Y charging the battery from 50 to 100% SOC to evaluate the costs. We assume a fixed total charging time (fast-charging: 1 h 25 min; slow-charging: 5 h 30 min), three different energy tariffs, and taxes to perform the calculation. As mentioned earlier, the Blockcharging energy transaction model proposes to sell the energy surplus 25% less expensively than the price applied in the market. Table 7 compares the final costs. Emissions savings: To evaluate the environmental benefits of the proposed framework, we compare the emissions per kilometre of three different vehicle settings: (i) Internal Combustion Engine (ICE), (ii) EV powered in the grid, and (iii) EV powered with PV energy. We assume that the vehicles have similar sizes and are charged using the electric mix of Portugal (in the case of EVs). Further, we employ a well-to-wheel analysis to consider the carbon footprint of the vehicles. The data to perform this evaluation were retrieved from [63]. Figure 8 depicts the emissions from each one of the settings of the vehicles. 

nal Combustion Engine (ICE), (ii) EV powered in the grid, and (iii) EV powered with PV energy. We assume that the vehicles have similar sizes and are charged using the electric mix of Portugal (in the case of EVs). Further, we employ a well-to-wheel analysis to consider the carbon footprint of the vehicles. The data to perform this evaluation were retrieved from [63]. Figure 8 depicts the emissions from each one of the settings of the vehicles. As expected, in the long run, EVs perform much better than ICEs in terms of emissions. Furthermore, using only PV energy to charge the cars brings more benefits. For a driving usage of 200,000 Km, savings in emissions would reach 20% (2 tonnes less CO2) compared with EVs in the regular electricity mix.
section_name: Cost Comparison and Emissions Savings

section_content: The economic analysis comprises the costs related to the smart contracts calls in the blockchain framework, the development of the application, and cloud services to run the database. As expected, in the long run, EVs perform much better than ICEs in terms of emissions. Furthermore, using only PV energy to charge the cars brings more benefits. For a driving usage of 200,000 Km, savings in emissions would reach 20% (2 tonnes less CO 2 ) compared with EVs in the regular electricity mix.
section_name: Economic Analysis

section_content: The economic analysis comprises the costs related to the smart contracts calls in the blockchain framework, the development of the application, and cloud services to run the database. 

Smart contracts transactions: To evaluate the costs associated with smart contracts, we assume the price of N = 3213 calls (expected number of charged EVs in a year) with an average of G = 21, 000 gas units per transaction, leading to a cost of N transactions in Ethereum (ETH) described below. 

C T = 3213 × 21, 000 × 9 × 10 -9 ETH ∼ = 0. 607 ETH (5)

At the time of writing, 1 ETH ∼ = EUR 1213, implying that C T ∼ = EUR 736. 3. By normalising, we acquire the cost per transaction (Equation ( 6 )).
section_name: Economic Analysis

section_content: C T N ∼ = EUR 0. 23/transaction ∼ = 0. 00019 ETH/transaction (6)

Transactional sensitivity analysis: For a single transaction, the cost associated with the smart contract is given by C T = G•P GU. Therefore, the profit P made on a single transaction is P = K•R T -C T, with K being the applied commission and R T the revenue generated by a transaction. It is assumed here that a vehicle needs to be charged at most once a day and that a single charge requires a single call to the smart contract, which are realistic assumptions. To generate positive profit, bounds for G and P GU can be estimated using a one-at-a-time approach [64], as stated in Equation ( 7 ):

Thus, 0 ≤ G < K•R T P GU and 0 ≤ P GU < K•R T G. Table 8 illustrates the maximal values of G and P GU using charging revenue values (see Table 7) in the context of this sensitivity analysis. For the calculation, we used the following fixed values: commission rate, K, equal to 20. 00%; gas units, G, equal to 21,000; and price per gas unit, P GU, equal to 9 × 10 -9. Revenues and cash flow analysis: Further, we make some assumptions to perform the economic analysis. The energy price imposed on the customers in this study will be 25% less expensive than in the conventional EV charging market (see Table 7 ). We consider solar irradiation from 10 am to 3 pm. The charging events occur in this same time window (energy mid-peak tariff). Lastly, we assume a fixed commission fee of 20% per transaction. Considering the scenario above, Blockcharging could generate profit up to EUR 11,121. 21/year (slow charging) or EUR 11,530. 84/year (fast charging). In addition, the institution would receive 80% of the total amount, representing a gain of EUR 44,484. 85/year (slow charging) or EUR 46,123. 34/year (fast charging). Figure 9 presents an overview of the revenue streams of the stakeholders involved in this analysis. Considering all those instances, we projected a cash flow over five years (Figure 10 ). In this setting, the payback time would be approximately two years, the NPV would be EUR 33,485, and the IRR would be equal to 61% at a 4% discount rate. These metrics demonstrate the project's economic feasibility and the viability of the business plan. Considering all those instances, we projected a cash flow over five years (Figure 10 ). In this setting, the payback time would be approximately two years, the NPV would be EUR 33,485, and the IRR would be equal to 61% at a 4% discount rate. These metrics demonstrate the project's economic feasibility and the viability of the business plan. Considering all those instances, we projected a cash flow over five years (Figure 10 ). In this setting, the payback time would be approximately two years, the NPV would be EUR 33,485, and the IRR would be equal to 61% at a 4% discount rate. These metrics demonstrate the project's economic feasibility and the viability of the business plan.
section_name: C T normal =

section_content: The transportation sector will undergo a significant transformation in the coming years due to the electric mobility revolution. However, urban environments need more time to be ready to deliver a charging infrastructure that meets the energy demand. In this context, photovoltaics (PV) surplus generation can charge electric vehicle (EV) fleets, bringing energy efficiency, financial innovation, and sustainability toward a greener and more electrified future. However, it is important to notice that combining Renewable Energy Sources (RES) and EVs alone is insufficient for achieving sustainable mobility. First, the local industrial chain is a critical factor. This aspect refers to developing local production and supply chains for EVs and their components, which can reduce the reliance on imports and support local economies. Establishing local industrial chains can foster innovation and create new jobs in the green economy. Moreover, developing battery recycling approaches is crucial for achieving sustainable mobility. EVs rely on batteries that contain critical and rare materials such as lithium, cobalt, and nickel. Battery recycling can help to recover these materials, reducing the need for new mining and extraction activities and minimising the environmental impact associated with these activities. Therefore, a sustainable and low-carbon mobility system in a green transition panorama requires a holistic approach that incorporates the development of RES, local industrial chains, and battery recycling, all of which are critical for achieving a more sustainable and resilient transportation sector. 

More specifically, our study centred on a novel charging framework that utilises surplus PV generation to charge EVs. We introduced the Blockcharging mobile application, which presents a sustainable and efficient framework to deal with PV energy surplus by integrating EV charging with a blockchain-based Peer-to-Peer (P2P) market. Hence, customers can schedule the charging through the mobile application, make the payments, and save emissions at the end of each charging procedure. We propose that the energy selling price be approximately 25% less expensive than the price performed in the conventional market. This business model is possible due to the decentralisation of energy generation. The blockchain framework deployed in the context of this study is based on Ethereum smart contracts. 

We conducted a case study to evaluate the potential of applying the framework in a real-world scenario. We obtained data from a higher education institution in Portugal, with a PV system of 724 kWp installed capacity. The data analysis unveils that the institution could fully charge 3213 electric vehicles in one year using the energy surplus. Regarding environmental aspects, charging the EVs using only PV energy can emit 20% less greenhouse gas (GHG) when compared with EVs charged in the electricity mix. The economic analysis demonstrates the project's economic feasibility, indicating a payback of approximately two years, a Net Present Value (NPV) of EUR 33, 485, and an Internal Rate of Return (IRR) of 61%. 

This study presents some limitations. First, the transaction rate on the blockchain is typically much lower than conventional transaction methods. In this sense, for a more extensive network of chargers, the number of transactions can grow exponentially, configuring a massive drawback in implementing a decentralised energy market based on blockchain technology. Nevertheless, research is being developed in the field to enhance the capacity of blockchain-based systems. Further, there is some controversy surrounding the energy consumption of blockchain technology. Improvements in this area are underway and are expected to continue. One method of reducing the carbon footprint of blockchain is by implementing a more energy-efficient transaction mechanism, such as the proof-of-stake. This mechanism has replaced the older proof-of-work approach, resulting in greater than 99% energy utilisation and lower emissions. 

Regarding the energy surplus, the penetration of distributed generation PV systems still needs to grow around the globe to satisfy the energy demand of charging large fleets of EVs. Due to the intermittency of RES, it is challenging to forecast generation, and a curtailment management service is required to avoid network constraints. Therefore, wasteful PV production is a global concern that calls for practical solutions to manage and optimise energy generation. For instance, China leads PV energy production globally and still faces challenges related to RES integration with the grid; at the same time, it holds the most extensive stock of EVs. Japan has limited land; however, building integrated PV can be used to mitigate this issue. Germany holds a high penetration of RES in the electric matrix and presents a "duck curve" related over-generation of solar energy. In the United States, the rapid adoption of solar PV is boosted by the low-levelized cost; however, better integration with EVs is needed. Therefore, expanding the framework proposed in this article to other energy markets might provide valuable opportunities for countries beyond Portugal. 

Lastly, there are few regulations concerning energy trading in decentralised markets today. In the future, governments could inflict taxes and fees on such markets. 

In future work, we aim to implement the mobile application in a native platform to be accessed by final users. We also want to bring other case studies to evaluate the feasibility of the framework in different conditions. For instance, we want to assess the project's feasibility concerning a heterogeneous fleet of EVs. Weather conditions could also be included since this factor impacts both the PV energy generation and EVs' charging needs. User acceptance is another topic that can be addressed in the following research. Lastly, we want to perform an in-depth lifecycle assessment analysis to understand better the environmental impacts of using a blockchain-based market in the developed system. 

Author Contributions: I. C., conceptualisation, investigation, methodology, software, data curation, and writing-original draft; J. J., conceptualisation, methodology, software, and writing-original draft; J. A. M., conceptualisation, investigation, methodology, software, visualisation, and writingoriginal draft; L. A., conceptualisation, methodology, and writing-original draft; M. P., conceptualisation, methodology, software, and writing-original draft; C. P. G., writing-review and editing; H. M., resources, funding acquisition, supervision, and writing-review and editing. All authors have read and agreed to the published version of the manuscript.
section_name: Conclusions

section_content: Data Availability Statement: Datasets and codes related to this article can be found at this GitHub repository: https://github. com/Irvylle/Surplus_Blockcharging (accessed on 10 January 2023).

section_name: Conflicts of Interest:

section_content: Funding: This work was supported by national funds through the Fundação para a Ciência e a Tecnologia (FCT), under grants UIDB/50021/2020, 2021. 04879. BD, and 2022. 13855. BD. This work received funding from the European Union's Horizon Europe research and innovation programme under grant agreement no. 101056765. However, the views and opinions expressed in this document are those of the authors only and do not necessarily reflect those of the European Union or the European Climate, Infrastructure and Environment Executive Agency (CINEA). Neither the European Union nor the grating authority can be held responsible for them.

section_content: The authors declare no conflict of interest.
section_name: Conflicts of Interest:

section_name: Nomenclature