A Definitive Technology Stack for Development of Smart Contracts for Energy Applications

In recent years, there has been a growing trend in research on smart contract applications. Smart contracts potential in the energy landscape is visible in their major applications such as peer-to-peer energy trading, electric vehicle charging, energy market management, and many more. Many studies have been conducted that produced a lot of literature in this area and many startups and companies have surfaced that exhibit large scope of its application in the energy sector. However, in comparison to other domains, there is still more development required. The literature available focuses on the different technical aspects and use cases, but there is no such scientific article providing gathered details of the smart contracts development process that invites the attention of researchers in the energy domain for development or provides basic knowledge of available tools. It is therefore necessary to contribute with academic articles that summarize this information, thus opening up paths of development in this field and strengthening the community. This paper is the first step towards the implementation of this idea and that is intended to be extended in the future.


I. INTRODUCTION
D IGITIZATION technologies are, in some form or another, causing waves of disruption across several industries.While some business sectors are making tremendous progress, others are just in the preliminary phases of the move to digital technology.The energy industry is one of the most dynamic industries out there.Innovative solutions that enable dependable and tamper-proof data and energy exchange are being sought after in order to improve self-consumption in local energy communities and assist in the implementation of increasingly dispersed control systems.This is being done in order to improve local energy communities.The current tendencies toward decentralization and digitization are the primary forces behind this initiative.In a similar vein, the anticipated growth of new forms of decentralized load (such as the widespread use of electric vehicles, for example) may provide the grid with the necessary flexibility, allowing, among other things, load shifting, peak shaving, and demand-side response.The fact that the system's existing operating paradigm is unable to handle and make use of the great majority of these minuscule dispersed This work was supported by Government of Spain -Economy and Industry Minister under grant MCI-20-PID2019-111051RB-I00, by Principality of Asturias -(FICYT) under grant BP19-069 ("Severo Ochoa" Program of Pre-Doctoral Grants) assets is the source of the issue.These kinds of issues are the primary motivators for innovation and development in the electricity business.In order to improve the efficacy of their integrated operations and processes, modern power systems are beginning to use cutting-edge digitization technologies such as the Internet of Things (IoT), Artificial Intelligence (AI), and distributed ledger technology (DLT).DLT and its associated smart contract technology facilitates the creation of user-defined digital contracts that are capable of running specific functionality in accordance with predetermined terms and circumstances.With these characteristics, DLT has a significant potential to revolutionize the electricity systems and markets of the future.Additionally, smart contracts, which are significant components of the DLT ecosystem, are one of the facilitators of digital energy services and use cases.
There is a lot of ongoing research and development on smart contract decentralized energy applications, [1] and [2] contain a systematic review of more than 100 blockchain research projects and initiatives undertaken by companies and research organizations.Going through the literature review, it is observed that most of the works propose smart contractbased solutions for energy and flexibility trading (peer to peer [3], [14], peer to grid [4]), market design [5], distributed control(electric vehicle management [18], battery management [19]), grid management [20], [21], carbon audits and certifications [6].Some research papers address standardization of smart contracts within the field of energy [7] and its role in digital green transition of energy industry [8].However, it is noticed that there is no specific research publication that is dedicated to provide technical guide for development of smart contracts for energy applications.One must go through multiple platforms, blogs, or tutorials to gather information in bits and pieces required for developing smart contract energy applications.As the world is turning to open source platforms, there is also a need to add value to the academic literature to guide the use of these platforms in the creation of various energy applications.There is a need to globalize, attract and promote more smart contract developments in the energy sector and strengthen this development culture and community.This can be done by making an ultimate guideline for the developers/seekers to track the complete pathway for the development of smart contracts on different open-source platforms.This technical guide may provide ease to the developers or even beginners to decide which essential tools are required to start with or how they can contribute.The proposed research will include gathering and organizing authentic information to develop content for an ultimate resource leveraging educational and developers community, helping them to identify potential growth opportunities, to gain a specific or broad understanding of the process.In this regard, the authors already published our research work on how to simply develop and deploy a smart contract, however that was specific to the Ethereum platform [9].This paper is intended to investigate more on the technical aspects of the smart contract's development that would add significant value in the literature related to blockchain smart contracts development in the energy landscape.
The rest of this article is organized follows.Section II summarizes and discusses the applications of blockchain technology in the energy sector and identifies a number of research opportunities.Section III introduces a development stack for smart contracts energy applications.In section IV, privacy, security, and scalability concerns pertaining to smart contracts are discussed.Finally, the authors conclude this article in the last section along with future outlook.

II. BLOCKCHAIN SMART CONTRACTS IN THE ENERGY LANDSCAPE
Smart contracts communicate with the system when certain conditions are fulfilled and can automatically accomplish and manage energy trading events [10] or various other tasks.A hardware setup is utilized to handle data, verify conditions, deal with negotiations, and authenticate contracts.Smart contracts are designed to guarantee that all the energy, storage units, and network streams are automatically regulated and certify that the energy will be released/stored according to the required demand [11].In addition, smart contracts can facilitate transactive energy by adopting some of its characteristic disputes, such as security and cost.

A. Smart Contract Benefits
In comparison with traditional contracts, smart contracts have several benefits for the energy sector.Smart contracts along with blockchain technology build a more reliable, transparent, and decentralized system, moreover, increase its security, efficiency, and other competencies as well in the subsequent aspects [12]: • Transparency and accessibility: For all the blockchain members, smart contracts are accessible and transparent.Consequently, in the event of permissioned ledger a few users could be restricted, whereas in event of permissionless ledger, everyone can retrieve smart contract data.• Security: Due to the prominent cryptography and blockchain features such as tamper-proof entries, the data cannot be altered by anybody, and their accomplishment is automated.• Speed and Reliability: Smart contracts are small-sized codes, shared among the blockchain nodes that are executed under a specific situation in a well-defined, isolated environment.This characterizes high speed of response and verification.Moreover, high reliability is also ensured as code execution does not depend on a single server because of the decentralized architecture scheme.• Accuracy: Built-in rules are defined and followed by the smart contract, significantly decreasing the possibility for error, and can be validated by third parties.• Cost: Streamlined transactions will eliminate the middleman, thereby reducing the transaction cost.The smart contract owner contains the operation cost (i.e., smart contract deployed node).

B. Impact of Blockchain in Energy Sector
With the energy revolution, the blockchain application can transform the industry catalyzed by inventions comprising electric vehicles, smart metering, energy storage and heat pumps.In this context, the blockchain offers itself as the next evolving technology through its system interoperability and smart contracts to drive the energy sector growth.Moreover, distributed ledger technology enhances the efficiency of utility suppliers by following the chain of charge for grid items [1].In addition, blockchain provides distinctive solutions for renewable energy distribution as well.Legacy energy sectors such as oil and gas companies are pursuing to devote and execute blockchain to diminish harmful environmental influences, lower costs, and enhance transparency without compromising privacy.Moreover, to cope with privacy and trade concerns, the private blockchain network provides data permissioning, specific parties access, and temporary solutions before the public blockchains employ the requisite privacy access businesses demand [13].Smart contracts and decentralized software certified by blockchain can be employed to build a smooth, reliable, and well-distributed energy system capable of resolving up to 80 percent of these underlined difficulties.

C. Smart contracts Applications Areas in Energy Sector
Besides reviewing key aspects and benefits of smart contracts, and determining certain significant methods and stages needed in their execution, the authors offer a methodical evaluation of related applications in the energy field.
1) Peer-to-peer (P2P) Trading: P2P trading execution is employed by utilizing smart contracts.The smart contracts need credit from the consumer and get the bids and offers from distinct investors followed by empirical and complex methods to unite the consumer with the seller through a comparison among the amount of energy and received bids and offers [14].These methods include double auction and power flow validation, which also help to reduce the cost of the Ethereum platform.However, smart contracts enable the transaction among peers and the grid when P2P trades don't deal with all the requirements of consumers or production from the sellers.Furthermore, at run time the matching of accessible energy with consumer energy demand is made beyond the blockchain [15].
2) Demand Side Response: In terms of flexibility, the stability between the accountable partners and investors can contract ancillary assistance to accomplish the energy trade 978-1-6654-6441-3/23/$31.00 ©2023 IEEE and necessary balance.In the demand response event, a smart contract can determine and save the registered requisite and baseline profiles and utilize them to establish a contract between concerned consumers and investors [16], [17].Smart contracts can use automated billing and payments to compensate or penalize buyers who meet the targeted load profile or not respectively.
3) Electric Vehicles (EVs) Charging Managament: Smart contracts can be employed for distinct purposes in the EVs area.Different optimizing algorithms are utilized by the smart contracts while accomplishing fair profit allocation between the owners of EV charging stations to steady the distribution of EV users [18].By limiting the flexibility of EV loads, smart contracts are utilized for peak load shaving and shifting and allow P2P trading among EVs as well.
4) Battery Managament: Through smart contracts, distributed resources can be managed securely.Smart contracts can be used for battery control such as the distributed batteries' data can be collected including state of charge and health to prioritize the charging/discharging of distributed cases automatically by sending them recommendations [19].Besides, a smart contract enables the management of domestic batteries to contribute in wholesale markets.
5) Grid Managament: At present, the improvement of Internet of Things (IoT) devices results in superior control, knowledge, monitoring of the grid, and the entire power system.In this aspect, when any fault arises in the grid, the data can be securely synchronized from the Phasor Measurement Unit (PMU) by employing smart contracts [20].Furthermore, automatically managing actuators or getting control evaluations among inconsistent set point demands from various resources of the grid can easily be done through smart contracts.Considering the security features of smart contracts, they can be utilized to allow access to grid data as well [21].

III. TECHNOLOGY STACK OF SMART CONTRACTS DEVELOPMENT FOR ENERGY APPLICATIONS
As mentioned earlier, this is an initial step towards preparing an ultimate guide to help researchers and practitioners in the energy domain look for contribution opportunities in developing smart contract energy applications.Fig. 1 provides the stack of developmental stages of smart contract applications where each stage is explicitly covering essential elements, each featured with some prominent examples.This facilitates the developer to get relevant and direct information about each stage from relevant resources according to their requirements.This section briefly covers the introduction to some of the essential elements ranked in Fig. 1 that are required for the development of smart contract energy applications.

A. Development Essentials 1) Integrated Development Environments (IDEs): Smart
Contract IDEs are designed to provide a source code editor for smart contracts compilation and migration scripts that fosters fast development and simplify the deployment of smart contract applications to the relevant blockchain.Remix IDE, Truffle and Hardhat are among the most popular choices of smart contract developers to create, compile, test, and deploy smart contract applications.
Energy Web (EW) chain is the blockchain built over Ethereum, which is tailored for energy applications.EW ecosystem provides a decentralized operating system with an energy web stack for the development of smart contract energy applications that is significant for new developers in the energy field to start with 1 .
2) Languages: The programming languages commonly used for writing smart contracts are Solidity, Rust, and Vyper.Solidity and Vyper are compatible with Ethereum virtual machine (EVM) based smart contracts, while Rust is designed for non-EVM smart contracts.These languages are influenced by popular languages such as Java and Python, which helps new developers to adapt.
3) Wallets and Faucets: To identify oneself, and be able to transact, validate and authorize transactions over the blockchain network, a cryptocurrency wallet account is required.These cryptocurrency wallets stores cryptocurrency that is utilized for developing, testing, and deploying smart contracts applications over the network.Multi-signature wallets analogous to joint bank accounts are also used for more secure operations.Various platforms provide free cryptocurrency facility for the testing and development of smart contracts through their channels called faucets.
4) Libraries: Open-source smart contract libraries are available for developers that offer ready-to-use building blocks or reusable functions and implementations of various standards.For instance, OpenZeppelin is a well known standard library for Solidity and offers packages for multiple functionalities which assist developers in deploying decentralized applications by adding new functions to smart contracts.
5) Oracles: Oracles serve as bridging entities to external systems for the smart contract as they enable external inputs data ingestion, off-chain computation, and sending outputs to external systems and inter-operate across blockchains.Chain-Link is one of the widely used blockchain oracle in the development market for hybrid smart contracts.These hybrid smart contracts can enable the connection of existing energy infrastructure and data such as consumption profiles, IoT sensor output, and weather information, allowing renewable credits, ownership certifications, and much more.
6) Testing: Smart contracts are immutable in nature therefore prior to deployment, quality assessment is required to identify any errors or vulnerabilities that may cause computational complexities and costs.Therefore detailed evaluation of smart contracts is carried out with functional testing2 that is categorized into unit testing, integration testing, and system testing.
7) Security and Auditing: Along with functional testing, security analysis and audits of smart contracts are crucial before deployment over the blockchain.Security analysis is 978-1-6654-6441-3/23/$31.00 ©2023 IEEE Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.There are two types of manual testing tools3 that can be used to audit smart contracts.One is a code audit that can be automated or human-aided analysis of the code to detect poor development, security flaws, and failure points.The other type is a bug bounty program that is outsourcing audits to the wider developer community to get rewarded for catching bugs.Examples of each type are presented in Fig. 1.
8) Deployment: After compilation, testing, security analysis, and auditing, the smart contract is deployed on the blockchain network.The steps involved in deployment differs based on the platform used for development.For most EVM smart contracts, a deployment script is prepared using bytecode and ABI files generated from smart contracts compilation which is then translated by Web3 to Javascript terms which are then communicated to an Ethereum node, either by running its own local node, connecting to a public node or via an API key using a node service like Infura or Alchemy.9) Analysis and Monitoring (Block Explorer): After deploying smart contracts over the network, developers can visualize and confirm transactions on the block explorers provided by the development platforms.Block explorers may have many in-built services and distinctive features such as real-time and historical information, data related to blocks, transactions, addresses, and more.It enables the developer to monitor and analyze their smart contract performance.Etherscan is one of the biggest free block explorers of the Ethereum blockchain.Ethplorer and Etherchain are also in competition.
10) Maintenance Tools: The developer community has figured out many maintenance patterns for the deployed smart contracts.There can be maintenance issues with the smart contract that may charge developers heavily later on.Therefore, developers need to thoroughly evaluate their smart contracts to acquire such patterns and devices more so in case of advanced level.This is an evolving field therefore developers need to be updated.
11) Front-end Utilities: Developers have the opportunity to build their user interface and add advanced front-end functionalities to their smart contract applications.However, basic practice and skills in CSS, HTML, JavaScript, and frameworks such as Angular or React are mandatory.Truffle suite offers Drizzle which is a collection of libraries that simplify building application user interfaces.Moreover, JavaScript libraries such as web3.jsand ethers.jshave risen in popularity for defining front-end functionalities.

IV. PRIVACY, SECURITY AND SCALABILITY CONCERNS
The implementation of smart contracts in the energy domain leads to several challenges including privacy, security, and scalability issues.For instance, leakage of private-public keys, analysis of transaction patterns revealing user information (such as real identities, activities, assets, and energy profiles), reputation, manipulation, and service based attacks highlight some of the prominent security breaches and privacy violations.Discrepancies in a smart contract may also attract malicious attacks.Quantum attacks are another potential risk to encryption schemes.Some of the solutions that are proposed to provide immunity to these attacks include private or consortium blockchain with temporary session keys, public-key encryption with time stamps, use of lattice-based signatures, and physical layer security [23].Furthermore, in the last few years, the US and EU have made several laws and legal frameworks to govern how data is shared and kept safe.Such a legislative framework aims to safeguard private persons' data privacy.The most important data processing activities which are subject to protection are data collection, processing, storing, and deletion.With this regard, it is essential to make sure that processed energy-related data that is transacted via DLT is processed in compliance with international norms and regulations.
Moreover, higher adoption of distributed energy resources in the energy industry results in scalability issues, requiring increased storage, high computational power and throughput, low latency and secure communication to execute proportionally increased energy transactions and system operations.The incorporation of AI, 6G, and big data technologies with blockchain schemes are considered to be promising solutions to meet these requirements.Moreover, some typical methods that are identified to overcome scalability issues related to DLTs include the utilization of the payment channels, sharding technique, layer 2+ solutions, sidechains, and directed acyclic graph-based DLTs.These solutions have still not reached the level of maturity in the research as well as in practical implementation, therefore requiring further investigation.

V. CONCLUSION AND OUTLOOK
DLT-based smart contracts could radically simplify energy system operations and its decentralized capabilities would enable an entirely new energy system.This is the time to accelerate developments in this domain and to do so technical guidelines must be prepared that motivate energy experts to take interest in developing smart contract energy applications.This paper presents an illustrative technology stack for smart contract development that is a step-wise guide to help beginners and developers build energy applications.This is an initiative to promote the culture of energy smart contract applications development and to build a strong developers community working on decentralized energy applications.Further advancements are intended to be included in this work in the future that may involve a more detailed view and granular knowledge of various aspects of this technology stack.

Fig. 1 .
Fig. 1.Technology Guide Stack for Smart Contracts Development for Decentralised Energy Applications