How do I reinstall macOS to my Mac after formatting the main drive accidentally?
It isn't clear if you have one or two hard drives in your machine. Nevertheless, the only thing that comes to mind, if you can't access another Mac to make a bootable USB drive, is boot from Internet Recovery, and reinstall OSX.

To enter this mode Internet Boot Recovery, do the following: 


In the Apple menu, choose Restart or power on your Mac. 
As the computer restarts, hold down the cmd/⌘+opt/⌥+R combination immediately upon hearing the startup chime. Hold the keys until the animated globe appears on the screen.


From there follow the instructions and reinstall the original OS your Mac was delivered with. Then update to the latest macOS.