Viagra acts on nerve endings in blood vessels so they release nitric oxide. This causes the walls of the blood vessels to expand, so they fill with blood to make the penis hard.