Rapper Tekashi 6ix9ine, whose real name is Daniel Hernandez, testified on Tuesday against two alleged members of the Brooklyn street gang Nine Trey Gangsta Bloods in Manhattan’s Thurgood Marshall Courthouse.

In court, 6ix9ine described how he discovered a formula for success with the crew before betraying it by becoming a prosecution witness.

The rapper told the court that his role in the Nine Trey Gangsta Bloods was to “just keep making hits and be the financial support for the gang … so they could buy guns and stuff like that.”

RELATED: Tekashi 6ix9ine’s ex-girlfriend claims rapper viciously beat her

The 23-year-old testified that in return, he received “my career. I got the street credibility. The videos, the music, the protection — all of the above.”

During the testimony, 6ix9ine told the jury he decided to co-operate only a day after his arrest last year on a racketeering indictment that named him as a member of the gang — a move that has reportedly put him at risk behind bars and prompted many people in the rap community, including Snoop Dogg, to label him a “snitch” and a “rat.”

View this post on Instagram

🐀 👮‍♀️ 🚔 👨‍⚖️

A post shared by snoopdogg (@snoopdogg) on

On trial are Aljermiah Mack and Anthony Ellison, described by prosecutors as two high-ranking members of a gang that terrorized city streets with drug-dealing and gunfire. Prosecutors allege that after a falling out with 6ix9ine, Ellison took revenge by abducting and robbing the rapper.

Mack and Ellison denied the charges, with Ellison’s lawyer arguing the alleged kidnapping was a “publicity stunt.”

WATCH: What is racketeering? Rapper 6ix9ine pleads not guilty to RICO charges

View link »

6ix9ine testified on Tuesday that he was a high-school dropout and deli worker when he launched his rap career.

He said he began inviting gang members to be extras in his music videos, including Gummo and other songs, because he “wanted the esthetic to be full of Nine Trey.”

RELATED: Tekashi 6ix9ine pleads guilty to 9 criminal counts, is co-operating with police

Prosecutors showed the jury portions of the music videos so that 6ix9ine could identify various gang members.

Some of the Trey Nine members seen on tape were flashing guns and hand signs. 6ix9ine explained in court the lyrics to songs he said were often meant to taunt “somebody I didn’t get along with.”

6ix9ine told court Gummo was aimed at Trippie Redd, who the rapper identified as a member of the Five Nine Brims set of the Bloods.

“Me and Trippie Redd were signed to the same label,” 6ix9ine told court. “There was a lot of jealousy involved.”

(Warning: This video contains explicit language.)

When the music video blew up on the internet, “I knew I had a formula,” he testified.

In court, it was pointed out that 6ix9ine often shouts the slogan “Treyway” in his music.

“Treyway was more of a sophisticated way to name the gang — something that we could market,” 6ix9ine said.

RELATED: Tekashi 6ix9ine pleads not guilty to racketeering, firearms charges

In January 2019, 6ix9ine began co-operating with federal prosecutors after pleading guilty to nine crimes and saying he had joined a violent New York City gang and helped others try to kill a rival gang member.

6ix9ine had publicly identified himself as a member of a street gang in his music, but he’s also admitted it in a courtroom.

During the plea, 6ix9ine said he joined the Nine Trey Blood Gang in the fall of 2017 and helped gang members try to kill a rival last March.

“I did this to maintain or increase my own standing in Nine Trey,” he told Judge Paul A. Engelmayer. He said he also “knew that another member of Nine Trey had a gun and discharged that gun.”

The Stoopid rapper said he also helped other gang members rob people at gunpoint as part of a pledge by new gang members to commit at least two crimes.

With his deal with prosecutors, 6ix9ine can gain leniency at sentencing on an otherwise mandatory minimum of 47 years in prison if he admits to all crimes and testifies truthfully. The rapper’s sentencing is set for Jan. 23, 2020.

6ix9ine is set to return to the witness stand on Sept. 18.

— With files from the Associated Press