Within energy communities, the prosumers can engage in peer-to-peer trading, fostering local collaborations and increasing awareness about energy usage and flexible consumption. However, even under these favorable technological and organizational mechanisms, prosumer engagement levels remain low, requiring trading mechanisms that are aligned with their social values and expectations. In this paper, we introduce an innovative hedonic game coordination and cooperation model for peer-to-peer (P2P) energy trading among prosumers which considers the social relationships within an energy community to create energy coalitions and facilitate energy transactions among them. A heuristic is defined to optimize the prosumers' coalitions, considering their social and price preferences while balancing the energy demand and supply within the community. The proposed hedonic game model was integrated into a state-of-the-art blockchain-based P2P energy flexibility market and evaluated its performance within an energy community of prosumers. The evaluation results demonstrate the effectiveness of considering social factors when creating coalitions, resulting in a 5% increase in the total amount of energy transacted in a market session compared to other game theory-based solutions and a degree of satisfaction varying between 91-96%. The results underscore the importance of the social dimensions of P2P energy trading, the positive social dynamics within the energy community leading to an even greater increase in energy transacted around 30%, potentially generating daily savings between $34 and $47 and additional carbon savings of approximately 15.4 kgCO2eq.INDEX TERMS hedonic games, peer-to-peer energy trading, social factors, social dynamic, prosumers, energy community.