This paper develops a structural model of demand for illegal drug varieties and studies how consumers substitute between different types of drugs in response to government policies. We use a unique longitudinal dataset on prices, quantities, and individual decisions that we obtained by scraping a darknet marketplace that covered the majority of the retail illegal drug trade in Russia. Our estimation procedure exploits a novel set of micro-level moment conditions to identify correlations in preferences for specific drug types and the degree of attachment to them. We find that the median own-price elasticity of demand for illegal drugs is -3.6, and that there is high substitution within two classes of drugs, medium-risk stimulants and cannabis. We validate our estimates using exogenous variation in the price of hashish caused by increased policing. The estimated model is used to evaluate counterfactual drug policies. We find that the legalization of cannabis has the benefit of decreasing the use of riskier drugs while increasing cannabis use. For every 4 additional doses of cannabis consumed, 1 less dose of another drug is consumed. Our estimates show that the recent introduction of a new family of synthetic drugs has increased total drug demand in the country by 40%, suggesting that governments should allocate resources to prevent the introduction of new drug products. Finally, our model helps identify the optimal drugs to target for interdiction, specifically those without close substitutes, such as Alpha-PVP.