Hello is there a command that if I shot with my carrot on a stick that the block that the beam hits will be replaced?
For this you need a data pack
There's no simple command for this. You have to write a data pack that recursively teleports an armor stand one step further until it encounters a block.
NOPEname has done something for this if you simply want a fast data pack: