So I don't believe that Modbus Master/Slave library works on newer based hardware.
The UNO and the Mega2560 are about the same generation of Arduino hardware. You might have to explain what does not work and how you set things up and what code you used.
You didn't describe why you use two Arduino UNOs to provide that setup.