People feel grateful when they have benefited from someone’s costly, intentional, voluntary effort on their behalf. Experiencing gratitude motivates beneficiaries to repay their benefactors and to extend generosity to third parties. Expressions of gratitude also reinforce benefactors for their generosity. These social features distinguish gratitude from related emotions such as happiness and feelings of indebtedness. Evolutionary theories propose that gratitude is an adaptation for reciprocal altruism (the sequential exchange of costly benefits between nonrelatives) and, perhaps, upstream reciprocity (a pay-it-forward style distribution of an unearned benefit to a third party after one has received a benefit from another benefactor). Gratitude therefore may have played a unique role in human social evolution.
McCullough, M. E., Kimeldorf, M. B., & Cohen, A. D. (2008). An adaptation for altruism: The social causes, social effects, and social evolution of gratitude. Current directions in psychological science, 17(4), 281-285.
https://doi.org/10.1111/j.1467-8721.2008.00590.x