There isn’t anything overly difficult about writing a cover letter when you have been referred by someone else, but the most important thing to know is where you should bring up the referral.
Generally speaking, it is always best to mention your referral in the opening paragraph, because it acts as an attention grabber for the hiring manager.
You’re hoping they’ll think to themselves something along the lines of, “Oh, this person was referred by Jim. I like Jim…he’s a straight shooter. If this person is good enough for Jim, he’s good enough for me. I’m going to bring him in for an interview…”