If the mommy was excited enough to tell you, then it's okay to go out and get a gift. It sounds like you're ready to buy out a store, so remember to pace yourself. You've got several months of preggo before you even get to meet the little bundle of joy.
If you feel you MUST exercise some restraint, wait until after they get the ultrasound that will tell the sex. Then you know whether to buy blue or pink.
And if you're asking from an ettiquette stand point, you may give anyone a gift at any time. It's typical practice to wait until the baby shower or after the baby is born to give the shower, but if you can't wait, just do it!
And congratulations to your friend on the baby.