Just four days into his "America First" administration, U.S. President Donald Trump was delivering for a foreign company — TransCanada Corporation of Calgary.

And when Trump approved the controversial Keystone XL pipeline, he ribbed TransCanada CEO Russ Girling over all the money the company had spent lobbying the previous administration to no avail.

"Russ, I know you've been waiting a long time and I hope you don't pay your consultants because they had nothing to do with it," Trump quipped a few months later in front of media cameras gathered in the Oval Office.

"In fact, you should be asking for the hundreds of millions of dollars back that you paid them because they didn't do a damn thing except give you a No vote, right?"

But the money TransCanada spent in the U.S. went well beyond the millions spent lobbying in Washington, D.C.

For years, the Canadian pipeline company also spent millions influencing local state legislatures and Indigenous communities and allying itself with so-called "dark money" groups that helped sway U.S. public opinion around the Keystone XL pipeline and ultimately install a new oil-friendly administration in Washington.

A new investigation by The Fifth Estate explores the hidden role of money and power in the battle over the Keystone XL pipeline.

For nearly a decade, TransCanada waged an expensive ground campaign to win political and public support for the pipeline.

The route for the Keystone XL pipeline passes through Nebraska farmland. (CBC)

For example, in a single legislative session in Nebraska during a key debate over Keystone XL, TransCanada dwarfed all other political spending by special interest groups in the state, dropping more than $500,000 US on lobbying state senators, according to a 2015 report from Common Cause Nebraska, a citizen watchdog group.

'Leading spenders'

Jack Gould of Common Cause Nebraska, a non-partisan group pushing for open and honest government, says: "That's the largest I've ever seen."

"We put out a chart showing who spent the most each year, and for any number of years they were the leading spenders in terms of lobbying," Gould told The Fifth Estate's Bob McKeown.

And the Nebraska legislature delivered for TransCanada — passing the controversial Bill 1161 in 2012 — initially putting the fate of the pipeline in the hands of the governor.

"I have been accused of being in the pocket of TransCanada," Bill 1161's author, Nebraska state Sen. Jim Smith, told The Fifth Estate. "I think I've received the least good out of this financially than anyone I've known."

Anti-Keystone XL activist Jane Kleeb says a group that calls itself Nebraska for Jobs and Energy Independence 'would start to blanket the airwaves with ads and with mailers and with robocalls calling our side extremists, tree huggers and hypocrites.' (CBC)

Jane Kleeb, leader of the anti-Keystone XL group BOLD Nebraska refers to Smith as "TransCanada's … poster child in our state."

"We have definitely caught Jim Smith and TransCanada in various stages of the fight where Smith is presenting a bill and he would literally tell his fellow members of the state legislature committee: 'I can't answer that question but TransCanada's lawyers can.' "

When BOLD Nebraska complained to the U.S. Federal Election Commission that politicians, including the state governor, had received illegal campaign contributions from TransCanada, the politicians returned the money.

No limits

Under U.S. law, foreign individuals and corporations are barred from making political contributions.

However, in this case the FEC accepted that the contributions were made by TransCanada's U.S. subsidiary, which is legal.

But while it may be illegal for a foreign entity to influence U.S. elections, there is nothing stopping foreign individuals or corporations from contributing money to U.S. non-profit groups.

Increasingly in the U.S., non-profit advocacy groups — acting as fronts for powerful special interests, including Big Oil — are raising hundreds of millions of dollars that are funnelled into state and federal campaigns — with no limits or oversight over where the money comes from or where it goes.

Because these non-profits operate outside of the regulated political campaign spending regime, they have become known as "dark money."

Investigative reporter Chuck Lewis says there has been 'an explosion in terms of the amount of dark money.' (CBC)

"There's been an explosion in terms of the amount of dark money," Chuck Lewis, an investigative reporter who founded the Center for Public Integrity in Washington, D.C., told The Fifth Estate. "It's gone up from a few hundred thousand dollars to 1.4 billion just since 2012."

In the U.S., when Keystone XL became a hot political issue, numerous so-called "dark money" groups backed the pipeline, paying for ad campaigns, lobbying and grassroots organizing.

The Fifth Estate looked at one prominent Keystone XL backer, the Consumer Energy Alliance — a registered non-profit in the U.S. that says it is the voice of hundreds of thousands of corporate and individual members across the country.

'We're very transparent'

"We believe strongly that the pipeline will be good for American energy consumers," the CEA's executive vice-president, Michael Whatley, told The Fifth Estate.

The Fifth Estate learned that the Consumer Energy Alliance is run out of a consulting firm in Washington, D.C .: HBW Resources, where Whatley is a partner.

"We have a master management contract where HBW does manage CEA," Whatley said.

Mike Whatley is a partner at a Washington, D.C., consulting firm that manages the Consumer Energy Alliance. (CBC)

"We put our membership on our website and we're very transparent about where those resources come from."

According to the CEA's 2016 U.S. tax filing, the organization raised more than $2 million. Of that, $1.2 million was paid to HBW. But the IRS does not require the CEA to publicly disclose any of its donors.

Whatley also sits on the board of a group calling itself Nebraska for Jobs and Energy Independence — a group that describes itself as a grassroots organization that has rallied local support for the Keystone XL pipeline.

'Do the dirty work'

But those on the ground in battleground states like Nebraska question whether it is truly a grassroots organization, or what is known as an "astroturf" group.

"They would start to blanket the airwaves with ads and with mailers and with robocalls calling our side extremists, tree huggers and hypocrites," says Kleeb. "They essentially do the dirty work of TransCanada."

In his HBW bio, Whatley discloses that he was also an adviser to the 2016 campaign for Trump and his vice-presidential running mate, Mike Pence. Whatley declined to tell The Fifth Estate exactly what his role was.

Whatley isn't the only Keystone XL backer connected to Trump.

"This is the oil and gas administration, let's just be direct here," says Lewis.

Front and center in that administration is Scott Pruitt — Trump's controversial pick to head the Environmental Protection Agency.

Environmental Protection Agency administrator Scott Pruitt was a vocal supporter of the Keystone XL pipeline when he served as Oklahoma's attorney general. (Melissa Phillip/Houston Chronicle via AP)

"Pruitt sued the Environmental Protection Agency 14 times during the time he was Oklahoma attorney general," says Oklahoma lawyer Garvin Isaacs, a longtime watchdog of the state's oil and gas industry.

And as Oklahoma attorney general, Pruitt was a vocal supporter of the Keystone XL pipeline.

But Pruitt didn't just use his office to lobby the U.S. federal government and speak at public hearings supporting the Keystone XL pipeline.

After the Obama administration killed the pipeline, Pruitt's office wrote a legal brief supporting TransCanada's lawsuit against the US government, signed on by attorneys general in five other states Keystone XL will pass through.

TransCanada declined The Fifth Estate's interview request or to answer any questions in writing.