The extension of emerging renewable energy sources such as wind and water turbines, solar panels, and the increasing usage of electric vehicles requires the supply and distribution of energy in a small device on local scale and it has created new methods of supplying and selling electricity. Middle buyers and end users can obtain the local energy with the peer-to-peer trading method in this large and hierarchical market. This method enables market to manage and exchange the electricity between major suppliers and medium and local levels. Blockchain technology is developing in peer-to-peer exchange of electricity and acts as a reliable, efficient and safe technology in the electricity trading market. In this method, while preserving the privacy of electricity users, by using smart contracts and by removing intermediaries in the energy supply and demand market, direct commercial interactions between energy suppliers and consumers are done. The Blockchain technology, while creating trust between the parties in the energy market, reduces the cost of electricity trading and increases its scalability with using the intermediate energy aggregators. In this research, the blockchain-based model, is presented for distribution and peer-to-peer transactions in the energy market. The suggested model provides the possibility of registration low-cost instant transactions at the power grid in any specific period of time. The above method, unlike periodic payments, provides immediate access to bills and small payments. Since the transactions outside the blockchain chain are not recorded, this system guarantees its honest and independent operation without fraud and failure. The smart contract method based on blockchain, reduces the transaction fees and speeds up electricity trading.