(a) Das Huhn legt ein Ei auf dem Boden.
(b) Das Huhn legt ein Ei auf den Boden.
Are both versions correct? If so, is there any difference?
It depends on the context. Both sound strange at first to me.
If you are talking about a chicken that is sitting on the ground and then you want to express that it lays an egg, you would say "Das Huhn legt ein Ei auf dem Boden". That way it feels as if you would say "Das Huhn ist auf dem Boden und legt ein Ei".
If you want to state that the chicken is laying an egg onto the floor, you say "Das Huhn legt ein Ei auf den Boden". Still, this sounds wrong, because normally "etw. auf den Boden legen" summons a picture of a hand laying something on the ground - at least for me. So at first I picture the chicken not squeezing the egg onto the ground, but taking it and laying it there.
I think it is unusual to explicitly tell where a chicken lays an egg. It has to be on some sort of ground, otherwise it would lay a "Spiegelei". ;)
Both are unrealistic and with this I'm seconding j0hj0h: „Both sound strange at first to me.“.
I've never seen a hale authentic hen laying an egg on or onto the (bare) ground. (I agree I've never seen a chicken farm from inside but the animals there are neither hale nor authentic anyway.) Maybe that's why „legt ein Ei auf den Boden“ sounds even stranger intuitively for me as well, imagining a hand holding an egg, too.
More realistic, without the bewilderment of (b) and with different meanings then:
(1) „Das Huhn legt ein Ei im Nest.“
Compare to the plural „[Die] Hühner legen Eier in Nestern.“
(2) „Das Huhn legt ein Ei ins Nest.“
Compare to the plural „[Die] Hühner legen Eier in Nester.“
Or (1) „Mami! Guck! Das Huhn legt mir ein Ei im Nest!“ vs. (2) „Mami! Guck! Das Huhn legt mir ein Ei ins Nest!“
Using plural often makes such things clearer in general.
(3) Eier legen (when done by hens with their vagina) possibly doesn't make sense for using it with accusative as in (2). Like „Die Kinder spielen Ball in den Kindergarten.“ or „Wir schlafen ins Bett.“
See Akkusativ, Präpositionen: „Die Präpositionen, bei denen entweder Dativ oder Akkusativ stehen kann, sind: in, [...]“. This entweder ... oder ... can be understood as being exclusive (sometimes), as well: just one of it.
Eine einfache Übersetzung (simple translation):
(a) The chicken is producing an egg while being on the floor.
(b) The chicken is putting an egg on the floor.
B sounds a little weird indeed. But they are definitely both correct german.
I consider both as correct, and I'd recommend the usage of one or the other depending on what you want to emphasize, and where you want to guide your audience mentally to prepare for what's coming next.
If you want to focus your audience on the location where the egg can be found, you'd prefer (b), focusing your audience on the further fate of the egg, if you want your audience to mentally stay with the chicken you'd use (a), since the focus stays with the chicken doing something before something else happens to it.
But in fact both are very close, and an audience seeing chicken, egg and ground would be able to follow your intentions, whatever they are.
auf dem Boden (dative) is a where-indication.
auf den Boden (accusative) is a where-to-indication.
So only (b) is correct.
German distinguishes strictly between where and where to. There are languages that don't make this distinction.