Both sentences are correct and present an indirect object.

  1. The most common way to introduce an indirect object is following the pattern of the first sentence.

Subject + Transitive Verb + Indirect Object + Direct Object.

  1. The other way is also the pattern of the 2nd sentence you posted.

Subject + Transitive Verb + Indirect Object + to/for + Object of the preposition (which is also the indirect object)

NOTE: Sometimes, the indirect object will follow a preposition like to or for.