Hi, as Christians we are called to share in God’s life. That is what a state of grace is. When you’re in a state of grace, God indwells your soul. This is distinct from His presence everywhere. Being in a state of grace at the moment of death is necessary to get to Heaven OR Purgatory first. Its necessary for salvation. We should try and always live in a state of grace.
To be in a state of grace all that’s required is to have no mortal sins in your soul. (However, since venial sins lead to mortal sins, and because God wants us to be saints, we should strive to fight little sins too. We should always intend not to sin especially as this intention could be malicious towards God).
There is Original sin (how we were born and lived before Baptism) and that prevents being in a state of grace. There is also personal sin, those are sins we actually commit, mortal or venial. Venial sins weaken us and mortal sins put us out of a state of grace.
Baptism takes away all the types of sin. If you were baptized as an infant, you only had original sin and it was washed away and after it you were in a state of grace. (If you were baptized as an adult then original and all personal sin was washed away)
This state lasts after baptism until the person’s first mortal sin. There are Saints and others who actually kept their baptismal innocence and only did venial sins. But let’s say a person did a mortal sin.
Then they are not in a state of grace anymore and the way to get back is through Confession.
So the simple answer is that to get in a state of grace you need for mortal sins to be forgiven, and since baptism the ordinary way of that is through Confession to a priest, ie: Sacrament of Reconciliation
(The extraordinary way is if a person has something called perfect contrition, that is being sorry ONLY out of love for God, that is a special gift and is rare, and such a person, though forgiven, actually needs to go and confess to a priest anyway, if they are able. That is because we might be mistaken about having perfect contrition and to show our repentance. Perfect contrition in Sacramental Confession is good but not necessary. Imperfect contrition, which is fear of hell is enough).
Hope that makes sense!