The reaction of 6-hydrazinyl-1,3-dimethylpyrimidine-2,4-(1H,3H)-dione (1) with ethoxymethylenemalononitrile afforded 5-amino-1-(1,3-dimethyl-2,6-dioxo-1,2,3,6-tetrahydropyrimidin-6-yl)-1H-pyrazole-4-carbonitrile (2). The latter was reacted with formamide and urea affording the corresponding 4-aminopyrazolo[3,4-d]pyrimidines 3 and 4. The reaction of monosaccharide aldoses with 3 and 4 gave stereoselectively the β-N-glycosides 5a -d and 6a -d which were treated with acetic anhydride in pyridine to afford the corresponding acetylated derivatives 7a -d and 8a -d. The prepared compounds were tested for their antiviral activity against hepatitis B virus (HBV) and showed moderate to high activities.