Decentralized technology represented by blockchain has been widely used in the field of distributed energy because of its outstanding reliability and security. Blockchain sharding technology can overcome the performance shortcomings of low throughput and low scalability of traditional blockchain systems, but most of the existing blockchain sharding systems adopt random sharding mode, without considering the difference in the capabilities of nodes in the system and the security risks of sharding. In order to solve such problems, a matching algorithm for blockchain sharding in the scenario of distributed energy trading is proposed, which fully considers the preference of nodes for the electrical distance between nodes and the number of transactions in the shard in distributed energy transactions, so as to reduce energy transmission loss and transaction costs, and considers the node reputation value to reflect its past performance in delivering committed energy, ensure the security of sharding, and abstract the problem into a many-to-one matching model with externalities to solve the problem. Finally, simulation experiments verify that the proposed blockchain sharding method is superior to the traditional sharding method and has good application value.