When you expect something, it's because it seems to you that you know that something is supposed to happen that way. For example you know that if you help someone they should be nice to you. It seems like you know for sure this is how it works, and based on this knowledge you set your expectation. But this knowledge may be wrong. Maybe the person has different goals, or he has some other problems that keep him distracted. Because of being distracted he doesn't notice that he is not being nice. If your knowledge is incomplete then your expectations can be wrong. So before you expect something you should say to yourself: "my knowledge about this may be wrong. Maybe it will happen this way and maybe it won't". If you think like this, your expectation will remain flexible. And when it doesn't go the way you wanted, you can adjust quickly.
In general every one of us only sees part of the picture. The other person sees a different part. Based on the part that you see each of you create your expectations, your actions, and your judgements. Then these expectations, actions, and judgments clash against each other. It's not your fault or his fault, it is the nature of the world, each person only sees one small part and acts based on that.
But what you can do when you know this principle, you can talk to each other and combine your parts, get them together and create one common picture, then you will be on the same page and there will be no conflict of mismatched expectations anymore.
The second problem is greedy nature, like you said. Sometimes when we are helping someone we begin to imagine the nice things we will get in return. As we keep thinking about these nice things, our mind gets excited. It wants to get something nice and it gets used to that imaginary future in which it already has those nice things. Again the problem is, the mind imagines something (in this case getting nice things in the future) and then it gets attached to that idea.
In general, the mind creates all kinds of pictures based on some information, but these pictures are only guesses. What you should learn is to never confuse these pictures as actual reality. Mind-made models are only models, and reality is reality.
If you are always aware that everything in your mind is a model, and that troubles and suffering arises when this model is wrong (and it is often wrong because it is simplified or partial) - then you can keep your mind open for new information, and when something different happens that is not in your model, you can re-adjust and get in sync with reality quickly without getting upset or angry.
If you learn to stay open (keep all your models open without conclusively completing them based on guesses) and learn to adjust your model within several milliseconds of receiving new information, then you will never be out of sync with reality - and never in trouble.