There definitely is a genetic component to it. I think ive read that around 40% to 60% of one's risk of addiction stems from genetic factors. The rest of course, is environmental factors. So, throw in a little environmental trauma, and boom = drug addict (or gambler, sex addict etc -- except those are a little different, especially the second one).
Genetic factors like variations in genes that encode for dopamine receptors can affect how pleasurable or rewarding a person finds a drug, so for one person, a line of coke might just feel a bit stimulating but for another they may feel like they're on top of the world.
Genetics also impact other things, like how well your endogenous opioid system functions. For me, I can remember times when I was a kid that when looking back on it now, almost felt like I was in opioid withdrawal (despite never having taken opioids). This is likely because compared to the average person, my natural endorphin production is low or perhaps my opioid receptors are low functioning. So, when I was 16 and took morphine for the first time ever, I was like, "holy shit, where has this been my whole life?, whereas another person might just feel tired and maybe a little giddy.
I will never forget the first time I took that morphine. I was 16, and my friends dad died of cancer so there was a bottle of leftover morphine. I was like, "cool, a bottle of morphine, that seems like a badass thing to have". My friend said I could have it.
That bottle of morphine just sat on a shelf in my bathroom medicine cabinet for months. Then one night, after getting into a fight with my girlfriend, and then getting bitched out by my mom, I was really stressed out, so I said fuck it, lemme try some of this morphine.
I took just 20mg (at like 1am, I couldnt sleep), and then went to watch TV. Eventually this warm sense of peace came over me and thoughts of my girlfriend stopped bothering me, and I drifted off peacefully to sleep. That morning I woke up to a bright, beautiful sunny California day, the sun was out and shining, the was this glimmer to the air and the birds were out chirping and everything just seemed beautiful. I hadn't remembered sleeping that well since I was a tiny child. It felt like a piece of me that had been missing was suddenly filled, something that had been missing my whole life. I felt renewed, restored. Everything just seemed so perfect and beautiful that next morning, and i felt at peace. It makes my eyes water to recall it, I remember it so clearly. In essense I was instantly an addict, but unfortunately it wasn't the answer to my problems and would only serve to bring me more pain.
I never suffered much trauma in my childhood, nothing really bad happened to me. But I never quite felt comfortable, just always on edge, kind of dysphoric and cold, alot like mild opioid withdrawal. It wasn't my environment that caused this, it was genetic.
So yeah, there is a major genetic component. I believe this is particularly true with opioid addiction, as well as probably alcoholism. What I notice with primarily stimulant abusers, like those who's main drug is meth or cocaine, they seem to have suffered alot of trauma in their early life.