Nope, it wasn't about addiction at all... he refused to fuck his brother's wife for some sort of weird ritual... or something like that.
Mostly correct. After Onan's brother Er died without an heir, their father, Judah, commanded Onan to marry and impregnate Er's widow, and to raise her child as an heir to his late brother. (Don't ask me how that was supposed to work!) Onan did the conjugal act with Mrs. Er but withdrew before ejaculating, and for that, God struck him dead. The Bible is so instructive.
"And Judah said to Onan, "Go in to your brother's wife and marry her, and raise up an heir to your brother." But Onan knew that the heir would not be his; and it came to pass, when he went in to his brother's wife, that he emitted on the ground, lest he should give an heir to his brother. And the thing which he did displeased the LORD; therefore He killed him also." Genesis 38:810.