Lima gained prestige after being designated capital of the Viceroyalty of Peru and site of a ''Real Audiencia'' in 1543. During the next century, it flourished as the center of an extensive trade network that integrated the Viceroyalty with the rest of the Americas, Europe and the Far East. However, the city was not free from dangers; the presence of pirates and privateers in the Pacific Ocean lead to the building of the Walls of Lima between 1684 and 1687. The 1687 Peru earthquake destroyed most of the city buildings; the earthquake marked a turning point in the city's history, as it coincided with a trade recession and growing economic competition with cities such as Buenos Aires.