Section 7. If it is necessary to acquire land for the purposes of a state highway outside the limits of an existing public way, the department may take the same by eminent domain on behalf of the commonwealth under chapter seventy-nine. When injury has been caused to the real estate of any person by the laying out or alteration of a state highway, he may recover compensation therefor from the commonwealth under chapter seventy-nine. The mayor, if so authorized by the aldermen, or the selectmen, if so authorized by the town, may stipulate in writing in behalf of the city or town to indemnify and save harmless the commonwealth against all claims and demands for damages which may be sustained by any persons whose property has been taken for, or has been injured by the laying out or alteration of, any highway which the department proposes to lay out and construct or alter as a state highway, and thereupon such city or town shall be liable ultimately for the amount of any verdict against the commonwealth for such damages, and for costs, and the amount thereof may be recovered by the commonwealth in contract.