On 17 April 1861, five days after the Confederate attack on Fort Sumter, the legislature voted to secede from the United States and joined the Confederacy. Official action came in May, after the Confederacy promised to move its national capital to Richmond. The city was at the end of a long supply line, which made it somewhat difficult to defend, although supplies continued to reach the city by canal and wagon for years, since it was protected by the Army of Northern Virginia and arguably the Confederacy's best troops and commanders. It became the main target of Union armies, especially in the campaigns of 1862 and 1864-5.