The microgrid can realize the effective integration of distributed power sources and reduce the impact of intermittent fluctuations of new energy sources on the main grid. In order to better realize the optimized operation of the microgrid, a microgrid power transaction model based on blockchain and game theory was brought up. To better realize the optimized operation of the microgrid, first the overall structure of the microgrid P2P power trading system was built and the blockchain network and smart contract logic was designed. Secondly, the benefits of each user in the microgrid was analyzed to optimize the transaction process. Then the cooperative game algorithm was used to build a microgrid P2P (Peer-to-Peer) electricity price pricing model for electricity transactions. Finally, the simulation results show that the blockchain-based technology constructed in the article can effectively realize power transactions between users, which is conducive to building an open, transparent, and efficient market environment, and can ensure the maximum benefits of users.