If by 'grammar', you mean the standard structure of the English language, then neither of those is correct. The construction you are asking about is this:
I have to go
I've got to go
The forms above are correct English. You could write or say these in any neutral or informal situation. The form with 'got' is slightly more informal and more natural in spoken language.
'Gotta' is not, strictly speaking, a 'word' - it is a transcription of the SOUND we hear when a person says 'got to' in a relaxed and fluid way. When someone says 'I've got to go', it sounds like 'I gotta go' or 'I've gotta go'.
As Peachey has told you, you shouldn't try to speak in this way unless your spoken English is fluent and reasonably native-sounding. Otherwise, it will just sound wrong - phonologically, this is advanced/near-native level English.
Also note that 'gotta' is not acceptable in written English other than in certain specific and very informal contexts when you are imitating speech.
Do not write it. When we see writing full of things like 'gotta' and 'wanna', it is a clear sign that this is a foreign learner who has misunderstood the function of these forms.