In 1851 Hanson was appointed advocate-general of the colony, initially as a temporary replacement for the ailing William Smillie, made permanent when Smillie died. He took an active share in the passing of many important measures, such as the first Education Act, the District Councils Act of 1852, and the Act of 1856 which granted constitutional government to the colony. In 1856 he was attorney-general in the first ministry under Boyle Travers Finniss; becoming premier himself in 1857. Among the acts passed were the first patents act, an insolvency act, a partial consolidation of the criminal law, and the Torrens real property act, though he was at first opposed to this measure. He also passed an act legalizing marriage with a deceased wife's sister, the first of its kind in the Empire, but the royal assent was refused on this occasion.