If I hire myself as a contractor in my home country, do I have to pay taxes on these incomes to US gov?
If I get paid from US-based company personally (not through company), do I have to pay taxes to US gov on these incomes?
You don't pay taxes to US gov unless any of the following two things are true: (1) you are a US resident (2) your income is produced in the US.
There is a precise definition of being a US resident for tax purposes but it basically boils down to you staying in the US for the majority of the time.
The production of income is a bit more tricky. It basically says that if you use US "infrastructure" to produce your income then you have to pay taxes. The common example of this situation would be rental income from a property in the US.
An example when this does not apply would be sitting in front of a computer in another country and writing a web app.
No, I don't think so. The income is not produced by merely hosting the app in the US. Instead, you most likely develop and maintain it, provide customer support, etc., all outside of the US.
If I get paid from US-based company personally (not through company), do I have to pay taxes to US gov on these incomes?
You don't pay taxes to US gov unless any of the following two things are true: (1) you are a US resident (2) your income is produced in the US.
There is a precise definition of being a US resident for tax purposes but it basically boils down to you staying in the US for the majority of the time.
The production of income is a bit more tricky. It basically says that if you use US "infrastructure" to produce your income then you have to pay taxes. The common example of this situation would be rental income from a property in the US. An example when this does not apply would be sitting in front of a computer in another country and writing a web app.