The settlements were established following the defeat of the Qing army by the British in the First Opium War (18391842). Under the terms of the Treaty of Nanking, the five treaty ports including Shanghai were opened to foreign merchants, overturning the monopoly then held by the southern port of Canton (Guangzhou) under the Canton System. The British also established a base on Hong Kong. American and French involvement followed closely on the heels of the British and their enclaves were established north and south, respectively, of the British area.