Craig Dimelow, 28, appeared at Edinburgh High Court and pled guilty to being concerned in the supply of the drugs on Thursday 3 October.
Ian Newlands, 54, pleaded guilty to possessing a stun gun after it was also found at the same address.
Officers operating from Police Scotland’s Organised Crime and Counter Terrorism Unit raided the flat on Captains Drive on November 21, 2018.
They discovered 1.9kg of heroin, a large quantity of cutting agent and the stun gun inside the property.
A related search of an address in Leving Place, Livingston was then carried out later that day where approximately £11,000 in cash was found.
Detective Inspector Grant Hendry, from the East OCCTU, said: “This was a significant recovery of heroin which we believe would’ve been sold across Edinburgh, Fife and East Lothian. Intelligence gathered from our officers ensured this couldn’t be sold within our communities. The success of this operation couldn’t have been achieved without the support of local communities.
“The condition we found the flat in showed a haphazard and flippant approach to dealing with a drug that has such a devastating effect on people.
“Tackling organised crime, which includes drug offences, remains one of Police Scotland’s top priorities which this enforcement activity demonstrates. Any intelligence we receive relating to crimes of this nature will be acted upon.”