Two years ago, Spencer Dinwiddie was on the scrap heap, having been traded by the Pistons and subsequently relegated to the G League by the Bulls. That’s where the Nets found him, and now he is the shining example of their development program.

Dinwiddie reached an agreement Thursday on a three-year contract extension worth $34.3 million that includes a player option in the third season.

The deal first was reported by ESPN’s Adrian Wojnarowski and was confirmed to Newsday by multiple NBA sources. Shortly after it was reported, Dinwiddie posted a message on Instagram and Twitter that read: “@BrooklynNets I’m home.” He added another message on Twitter that said: “The journey is just beginning. I’m thankful that @brooklynnets believed in me enough to give me a home.”

The contract is expected to become official on Friday before the Nets face the Wizards at Barclays Center.

On Dec. 8, Dinwiddie, 25, became eligible for a maximum contract extension of four years for $47.5 million. A source close to him said he sought a shorter-term deal that reflected his belief in himself and allows him an earlier shot at free agency.

The contract starts with the 2019-20 season and includes the maximum allowed salaries of $10.6 million, $11.4 million and $12.3 million. The contract will cut into the Nets’ salary-cap space next summer, but they still should clear at least $50 million of space.

The deal was reached the day after Dinwiddie scored a career-high 39 points in a win at Philadelphia. After the game, coach Kenny Atkinson noted the impact Dinwiddie has made during the Nets’ three-game winning streak as the closing point guard at crunch time. “You can’t take him out, and he’s playing great basketball,” Atkinson said. “Obviously, he’s our engine right now.”

Injuries to point guards Jeremy Lin and D’Angelo Russell opened the way for Dinwiddie to start 58 games last season before returning to a backup role. He finished third in the voting for the Most Improved Player award.

This season, he has been widely acknowledged as a strong candidate for the Sixth Man award. He has come off the bench in 26 of the Nets’ 29 games and is averaging 16.9 points and 4.9 assists. He’s second in the NBA in points off the bench, assists off the bench and made three-pointers off the bench (51). He has scored in double figures 25 times off the bench and has five games of at least 25 points and two games of at least 30 points.

Describing Dinwiddie’s play against the 76ers, teammate Joe Harris said, “He was going off in every level, threes, mid-range, finishing at the rim, facilitating, getting guys involved . . . His ability to get downhill opens everything up.”

It was a powerful statement, and the Nets rewarded Dinwiddie for his growth with them.