WHEN his neighbour discovered gold in a Californian river in 1848, Sam Brannan could have kept quiet about it. Instead, he filled a jar with gold dust and rushed around the streets of San Francisco shouting “Gold! Gold! Gold!” He had good reason to incite a gold rush: he owned a shop nearby. He became California’s first millionaire by selling picks, shovels, beans and bacon to the horde of prospectors who heeded his call.

Gold fever spread fast. The lure of buried treasure “sucked nearly every free hand and available arm to the gold mines”, observes H.W. Brands in “The Age of Gold”, a brilliant history of the period. “They tore themselves from warm hearths and good homes, promising to return; they fled from cold hearts and bad debts, vowing never to return.” The Alta California, a local paper, reported that “The whole country…resounds to the sordid cry of gold! GOLD!! GOLD!!!” It added that this would be the last issue for a while, since all its staff were heading for the gold fields.

America’s current shale-energy boom has plenty in common with the gold rush, and might prove as momentous. It has created a gusher of wealth in remote places. It has lured young men to wild frontier towns, such as Williston, North Dakota. Jim Cramer, a television host, sounded just like Brannan when he reported from North Dakota in 2011. “This new black gold rush is just getting started!” he bellowed, against a backdrop of nodding donkeys. “Listen, people in this country who need a job, get up here!”

Unlike the Alta California, not all of The Economist’s writers have headed for the frontier. But one correspondent, intrigued by the parallels between the two booms, put on stout boots, packed a copy of “The Age of Gold” and set off for Williston.

For the ’49ers—as the men who hurried west in that year became known—the trek to California was arduous. “Mules old enough to travel well were unavailable at any price,” writes Brands. Prospectors who made their way overland went “at the pace of the slowest oxen [pulling their wagons], no more than two miles [3.2km] per hour”. Many succumbed to cholera, thirst or Indian arrows. One group, on escaping from the most godforsaken tract of the Mojave desert, doffed their hats, turned back and said: “Goodbye, Death Valley!” “The name stuck,” notes Brands.

The journey to North Dakota today is more straightforward. Still, when your correspondent tried to reserve a rental car at Bismarck airport, they were sold out. He eventually found a pickup truck. Driving it through the Badlands was hairy: hundreds of huge oil lorries kept thundering in the opposite direction along narrow country roads. The pickup went much faster than an ox wagon, except in the traffic jam outside Williston, which looked like a long, motionless steel snake festooned with lights. A sign offered a cheerful welcome to “Boomtown, USA”.

Men behaving badly

The communities formed by the two groups of migrants have some striking similarities. For gold miners in California, life was almost as rough as the journey west had been. San Francisco in the summer of 1849 looked like “the bivouac of an army on the move”, writes Brands; most of the buildings “were actually tents”. The miners smelled awful. No one “could be bothered to wash dirty underwear, only to wash gold”. Workers in Williston today generally have it easier—though newcomers sometimes sleep in their cars, which is not advisable in the winter, when temperatures often drop below minus 20°C. Places to stay are scarce and expensive. Many oil workers live in “man camps”, which look like college dormitories that have been built in a hurry. The companies that run them, such as Target Logistics of Texas, prefer the term “crew camps” to man camps; it sounds less burly and tattooed. But who are they kidding? When The Economist visited Tioga Lodge, one of Target’s camps, 99% of the 930 residents were male. It is a bare-bones place for men who work long, sweaty hours to sleep and eat. Happily the food is free and unlimited. The kitchens chop up vast quantities of meat into portions just small enough to fit on a plate. “They eat a lot,” says the chief cook, Jeff Ball, who used to cater for troops in Afghanistan. Some workers heap their trays with meat and potatoes in the dining room, then walk over to the cafeteria to load up with burgers, hot dogs and pizza. Your correspondent, at the salad bar, felt lonely. Mr Ball gives the oilmen whatever they want. If they crave blackened catfish and prawn gumbo like mom used to make in Louisiana, they can have it. Likewise if a crew from Mexico wants tamales. The only thing they can’t have—in the man camp, at least—is alcohol. Oil firms prefer that dangerous machinery be handled by men with clear heads.

Too drunk to frack

Life in the gold fields was often violent. Miners drank and gambled and fought. Thieves and ruffians preyed on the weak and unwary. Justice was rough. Brannan, the shop-owner, led a committee of vigilantes. In June 1851 his men caught a gangster stealing a safe. After a two-hour “trial”, they hanged him from a beam in a public square.

Life in the gold fields was often violent. Miners drank and gambled and fought

Williston, too, has developed a bareknuckle reputation. “The theft up here is unbelievable,” says a private detective hired by an insurer to investigate the disappearance of 15 truckloads of oil. “A lot of people here are trying to get a piece of the action without working.” And, with so few women in the neighbourhood, many men are frustrated.

“You put a bunch of guys together, working 12 hours a day, and they’re going to get into fights,” shrugs Josh Wipf, a mechanic from Montana who moved to Williston last year. Mr Wipf, who says the ratio of men to women in Williston “sucks”, admits to having been in a bar fight himself. “It was about a girl, I think. I don’t really remember. I was, you know…” he trails off.

“They get rowdy when they get drunk,” says Alice Trottier, a student at Williston State College. “I would never go out jogging alone at night now,” she laments. Like many young females in Williston, she finds it annoying to be stared at all the time. On the plus side, scarcity gives women power. Men “treat you like a princess. They pay for everything,” says Ms Trottier. On a good night waiting tables at a pizza joint she can make $200.

In California during the gold rush, many men could only find female company if they paid for it. Life for boomtown prostitutes was rough and risky; some Chinese women, speaking no English, were in effect slaves to their pimps. But others made a lot of money. “At a time when a Paris streetwalker might make the equivalent of $2 a night, some of the Frenchwomen in San Francisco made $400,” writes Brands. Belle Cora’s brothel on Dupont Street was renowned for fine wine and music as well as sex. “Men with lust in their hearts…and gold in their pockets beat a path through the muddy streets to her door, where she made sure they wiped their feet before entering.”

The same trade exists today in Williston, but with fewer chandeliers and violins. Most paid hookups are probably arranged online: the oil workers all have smartphones. Some practise the oldest profession the old-fashioned way, but this can annoy bystanders. One of the staff at Bubba’s Bubbles, a laundry shop, says she “had to kick out” a woman with a pink wig who was accosting male customers in the parking lot.

Striking it lucky

The California gold rush was a low-tech affair. “No capital is required to obtain this gold, as the labouring man wants nothing but his pick, shovel and tin pan,” wrote William Sherman, later a civil-war general, in a missive to President James Polk in 1848. It seemed to offer ordinary people a chance to get rich quick: one man, sifting through the dirt at the bottom of a stream, might conceivably find enough gold to retire on. Not a good chance, mind: only a lucky few prospectors struck the mother lode. The rest typically struggled to find enough ore to cover their expenses; some died poor and sorry, or quit panning to find a steadier job.

Fracking, by contrast, requires capital and expertise. Oil giants such as Statoil and Schlumberger are flocking to North Dakota. They bring pricey, high-tech equipment, from microseismic sensors to drilling rigs that walk, like something out of “Star Wars”. From little frack pads in the middle of vast wheat fields, they can drill four miles down, more than a mile to the side, and, thanks to satellite technology, hit a target three feet across. Then they shoot thousands of gallons of water, sand and chemicals into the shale formation, creating hairline fractures in the rock—hence the procedure’s proper name, “hydraulic fracturing”. The sand stops those fractures from closing up when the pressure is turned off.

The lure is not a slender chance of becoming rich, but the near-certainty of finding a blue-collar job that pays middle-class wages

But North Dakota rewards ordinary folk, too. The lure is not a slender chance of becoming rich, but the near-certainty of finding a blue-collar job that pays middle-class wages. A roughneck or truck driver can easily make $100,000 a year. (Why did Mr Wipf make the trek from Montana? “Good money.”) Anyone who can pass a drug test can find work.

And just as the gold rush made shopkeepers and shovelmakers rich, so the spoils of gas are widely spread. A whole economy has sprung up to support the frackers. Someone has to build man camps, roads and schools. North Dakota Developments, a property developer, is trucking ready-made six-room housing units over from Minnesota and erecting them in what used to be a cornfield. Rob Gavin, the boss, says demand is so strong that he expects to recoup the development costs in a single year.

The place is growing so fast that, even at boomtown wages, finding workers can be hard. Paul Coppinger, a boss at Weir-SPM, a firm that makes oil and gas pumps, says that only a couple of his 63 staff in Williston are native North Dakotans. The Walmart in town is the messiest your correspondent has ever seen; there are too few hands to tidy the shelves. Workers quit and take better jobs faster than you can say “frack”.

Theron Amos, the manager of the local Pizza Hut, says he has lost a fifth of his staff—in the past week. “I have 20. I need 30,” he sighs, as he wrestles with the cash register and passes the shrieking phone to a colleague. “Oh, man, I’ve got more grey hairs than when I started this job.” Would Mr Amos turn any applicant away? “Well, one woman came in and ordered a pitcher of beer before the job interview. I didn’t hire her.”

Sitting on a gold mine

The locals in 19th-century California were not consulted about the gold rush. Many Native Americans, who in previous decades had reached accommodations with Spanish and Mexican settlers, were murdered or infected with unfamiliar diseases. Scorched-earth offensives starved them off their land: since hunting them down was too time-consuming, one white soldier wrote, “It was therefore decided that the best policy was to destroy their huts and stores, with a view of starving them out.” Their descendants live in reservations. Williston’s natives are faring rather better.

Because they can drill sideways, frackers can suck out the oil and gas under a huge farm while disturbing only a tiny part of it. So the farmer carries on rearing cows as before. The fracking takes place so far underground that he never notices it. But he notices the royalties that the energy firms pay.

“Most farms round here have mineral income,” says Tom Rolfstad of the Williston Economic Development office. A farmer with two square miles of land will get a signing bonus of $2.5m and nearly 20% of the gross value of the oil and gas pumped from it, he estimates. A good well can keep producing for 30 years and yield 500,000 barrels of oil. At $100 a barrel, that’s $10m for the farmer. Even small landowners benefit. Mr Rolfstad gets regular little cheques for the oil and gas extracted below his modest home.

Many of the ancestors of today’s North Dakotans arrived at Ellis Island in the 19th century. “If you were Norwegian, they’d send you to North Dakota. If you didn’t speak English, they’d give you a card round your neck asking people to help you find the right train,” explains Mr Rolfstad. Under the Homestead Act of 1862, if the immigrants staked out 160 acres and farmed it for five years, they owned it—and their descendants own the mineral rights. In Europe, where such rights typically belong to the state, people resent the disruption fracking might cause. Americans, by contrast, tend to be delighted if a firm wants to frack under their land.

And for landowners, the fracking itself is not the only money-spinner. A farmer with land near Williston will have no trouble renting it out. The town is desperate for more offices, homes, shops and hotels. In one small field your correspondent counted 50 mobile homes.

One occupant, Cindy Martin, says the farmer charges her $1,000 a month to park there, with no electricity or water. “It’s a terrible price,” she complains. But the boom means labour is scarce and wages are high; Ms Martin makes twice as much as she would elsewhere, working at Bubba’s Bubbles. She and her husband drove up 2,000 miles from Arizona. She seems content: “We came here to work. We refuse to lay back and let the government take care of us. We’re too American for that.”

For all their good fortune, some locals fret about the crowding, pollution and change that accompany the new wealth. “It was a quiet, small town,” laments Gary Daniel, a middle-aged Willistonian, as he eats fried chicken at Gramma Sharon’s family restaurant. He has seen oil booms before, “but not like this one.” People used to know each other in Williston, he recalls: “Now everyone’s in a hurry to go nowhere.” Prices have soared. Mr Daniel knows of old people whose rent quadrupled so they had to leave their homes. “It’s flat-out greed,” he spits. The schools are packed; their walls are “just bulging out”. The traffic is “insane”. Overall, “whether it’s good or bad, I haven’t made my mind up.”

Mr Rolfstad has fewer doubts. Growth is being carefully planned, he says. “We decided to double the size of the town. Then we decided to quadruple it.”

After the flood

The gold rush of 1848-55 not only transformed the lives of those who found fortunes in the dirt (and those who failed to); it also changed America. It rapidly populated the new territory of California, which America had just seized from Mexico, and hastened the day that the Golden State became a state. It led to the construction of railroads to bind the settled eastern states to the Wild West. Its legacy includes San Francisco and America’s thriving Chinese population (which exploded during the gold rush, as boatloads of Chinese prospectors arrived).

Brands, the historian, goes further, arguing that gold transformed the American dream. Whereas the Puritans dreamed of accumulating modest fortunes “a little at a time, year by year”, through “sobriety, thrift and steady toil”, the ‘49ers dreamed of “instant wealth, won in a twinkling by audacity and good luck”. Among the early settlers, failure “connoted weakness of will or defect of soul”. In the gold fields, by contrast, “a person was expected to gamble, and to fail, and to gamble again”. And “[w]here failure was so common, it lost its stigma.” This idea—that failure is a socially acceptable stepping stone to success—is one reason why American capitalism is so dynamic.

The fracking boom could be every bit as important as the gold rush. It is about to turn America into the world’s largest oil and gas producer, outstripping Russia and Saudi Arabia. It could add almost $700 billion to the economy by 2020 (about 4% of GDP), predicts McKinsey, a consultancy. By then it will have created up to 1.7m jobs—far more than the car industry provides. The sudden abundance of natural gas has drastically reduced American energy bills while curbing greenhouse-gas emissions, since gas is cleaner than coal.

The longer term effects of a boom are unpredictable. For instance, the gold rush arguably led to the creation of Silicon Valley. It spurred the laying of the railroads, making Leland Stanford rich. He founded Stanford University, which trained the engineers who started the tech firms, from Hewlett-Packard to Google, which made the Valley the envy of the world.

In North Dakota fracking has poured money into schools. Some of those Norwegian immigrants used to set aside a portion of their farmland income to support the village school. That rule lives on, in places, and the land now generates mineral royalties. No one expects to see a great university emerge in the Great Plains just yet. But you never know. Who in 1849 could have predicted that the empty hills around San Francisco would one day sprout an Apple?