In 1802 Trevithick built one of his high pressure steam engines to drive an automatic hammer at the Pen-y-Daren iron works near Merthyr in South Wales. With the assistance of Rees Jones, an employee of the iron works and under the supervision of Samuel Homfray, the proprietor, he mounted the engine on a wagon chassis and turned it into a locomotive. In 1803 Trevithick sold the patents for his railway locomotives to Samuel Homfray.
Homfray was so impressed with Trevithick's locomotive that he made a bet with another ironmaster, Richard Crawshay, for 500 guineas that Trevithick's steam locomotive could haul 10 tons of iron along the Merthyr Tramroad from Penydarren to Abercynon, a distance of 9.75 miles (16 km). Amid great interest from the public, on 21 February 1804 it successfully carried 10 tons of iron, 5 wagons and 70 men the full distance in 4 hours and 5 minutes, an average speed of nearly 5 mph. As well as Homfray, Crawshay and the passengers, other witnesses included Mr. Giddy, a respected patron of Trevithick and 'an engineer from the Government'. The engineer from the Government was probably a safety inspector and particularly interested in the boiler's ability to withstand high steam pressures.
The locomotive itself was of a very primitive design. It comprised a boiler mounted upon a four wheel frame. At one end, a cylinder was mounted partly in the boiler, and a piston rod ran out along a crosshead, an arrangement that looked like a giant trombone. As there was only one power stroke, this was coupled to a giant flywheel mounted on one side. The rotational inertia of the flywheel would even out the movement that was transmitted to a central cog wheel that was, in turn connected to the driving wheel. It again used a high pressure cylinder without a condenser, the exhaust steam being used to assist the draught via the firebox, increasing efficiency even more. These fundamental improvements in steam engine designs by Trevithick did not change for the whole of the steam era.
The bet was won. Despite many people's doubts, it had been shown that, provided that the gradient was sufficiently shallow, it was possible to successfully haul heavy carriages along smooth metal rails using a suitably heavy and powerful steam locomotive. Trevithick's locomotive was probably the first to run on rails. However the short cast iron tramway rails of the tramroad were designed for relatively light horse-drawn carriages. They broke under the weight of the locomotive and the tramroad returned to horse-power after the initial test run.
Homfray was pleased enough. He had won his bet and the locomotive was placed on blocks and returned to its original job as a stationary engine to drive the hammers. Hearing of the success in Wales, Christopher Blackett, proprietor of the Wylam colliery near Newcastle wrote to Trevithick asking for locomotive designs. These were sent to John Whitfield at Gateshead, Trevithick's agent, who built what was Trevithick's second locomotive.
Pulling close to 25 tons, it could reach the speed besides of 6 km/hs in spite of a certain slope. Alone, it reached 25 km/hs.