The world’s electricity production is increasing day by day and on the other side, the electricity demand is also increasing because of the larger penetration of Electric vehicles, DERs, and smart devices. The effective utilization of renewable energy is required to meet the demand. To maximize the usage of these renewable energy resources, peer-to-peer technology will help trade excessive energy between prosumers without any intermediaries. The traditional centralized grid structure is no longer viable to control a large number of prosumers. Moreover, the energy companies and authorities will impose high costs for the usage of electricity. In this context, Blockchain technology with the features of automation, immutability, public ledger facility, irreversibility, decentralization, consensus, and security has been adopted to solve the prevailing problems.This research intends to develop a smart contract based on blockchain technology by considering a smart city, which enables complex automated data interchange, demand response management, peer-to-peer (P2P) energy trading, etc. The absence of a third party can result in reduced cost and improved operational and market efficiencies. The decentralized, anonymity, transparency, and tamper-proof characteristics of the blockchain can be utilized in the design of the next generation of distributed energy solutions.