In 1491, James determined to address the many attacks on Scottish shipping in the vicinity of the Firth of Forth from the English and other pirates. He erected fortresses at Largo and Inchgarvie, and made extensive repairs to Dunbar Castle, to defend the firth from hostile attacks.Macdougall, Norman, James IV, p. 227. James also remonstrated with King Manuel I of Portugal against the piracy practised by the Portuguese against Scottish shipping, and granted letters of marque to Andrew Barton, authorizing him to attack Portuguese ships. The forfeiture of the Lordship of the Isles in 1493 was followed by James's naval expeditions to Argyll and the Hebrides in 1492-5 and 1498, and in May 1502 James sent a fleet of five ships and 2,000 troops to Denmark to aid his uncle, John, King of Denmark, who had appealed to James for aid against a rising in Sweden and Norway.Macdougall, Norman, James IV, p. 229. The Danish expedition seems to have concentrated James IV's mind on naval expansion: shipwrights and craftsmen were recruited from across Scotland, and from France, Flanders, Denmark and Spain; timber for shipbuilding was felled in Lanarkshire and the Highlands and imported from Norway and France. James was also responsible for the founding of new dockyards on the Forth at Newhaven in 1504, and Pool of Airth in 1506. The king also wore the insignia of an Admiral - a whistle and a chain of gold.Dawson, Jane, Scotland Re-formed: 1488-1587, p. 76.
