We analyze a novel agent-based model of a social network in which agents make contributions to others conditional upon the social distance, which we measure in terms of the "degrees of separation" between the two players. On the basis of a simple imitation model, the emerging strategy profile is characterized by high levels of cooperation with those who are directly connected to the agent and lower but positive levels of cooperation with those who are indirectly connected to the agent. Increasing maximum interaction distance decreases cooperation with close neighbors but increases cooperation with distant neighbors for a net negative effect. On the other hand, allowing agents to learn and imitate socially distant neighbors increases cooperation for all types of interaction. Combining greater interaction distance with greater learning distance leads to a positive change in the total social welfare produced by the agents' contributions.