Any person who shall hold any contract from the state through the board of university and school lands, or otherwise, for the purchase of any real property within the state, may maintain any action for injuries done to the same, or an action to recover possession thereof, in the same manner as though the person possessed the fee simple title to such lands. However, in any action or proceeding by or against a railway company with reference to right of way or otherwise, the court, in any judgment which it may enter, shall protect the interest of the state in and to such real property to the extent that the value of such lands taken, at the price agreed to be paid per acre to the state therefor, shall be directed to be paid to the proper officials of the state, and, upon such payment, any claim of the state or any of its boards to such part of said property as shall be taken by the railway company shall be at an end.
N.D.C.C. § 32-17-21