Abraham believed God and it was counted to him as righteousness. This is "imputed" righteousness granted from God 400 years before the Law and Commandments were given on Mt. Sinai. Abraham was justified by God's Grace and counted as righteousness by the mighty hand of God. Faith in God's promises connected Abraham with God. The Grace of God made Abraham righteous.
Romans 4: 1-5...What shall we say then that Abraham our father, as pertaining to the flesh, hath found? For if Abraham were justified by works, he hath whereof to glory; but not before God. For what saith the scripture? Abraham believed God, and it was counted unto him for righteousness. Now to him that worketh is the reward not reckoned of grace, but of debt. But to him that worketh not, but believeth on him that justifieth the ungodly, his faith is counted for righteousness.
Romans 4:16...Therefore it is of faith, that it might be by grace; to the end the promise might be sure to all the seed; not to that only which is of the law, but to that also which is of the faith of Abraham; who is the father of us all,
The Grace of God existed before the Law and Commandments came. Here's what God said about Abraham and Noah.
Genesis 18:3...My Lord, if now I have found favour in thy sight, pass not away, I pray thee, from thy servant:
Genesis 6:8...But Noah found grace in the eyes of the LORD.
The word Noah means "preacher of righteosness" in Hebrew. Then you had Abel who was also a righteous man of God. All pointing to the fact that faith, righteousness, and God's Grace existed and operated "before" the Law of Moses was given at Sinai. All pointing to the fact that the blessing of Abraham would come upon the Gentiles.
Galatians 3:14...That the blessing of Abraham might come on the Gentiles through Jesus Christ; that we might receive the promise of the Spirit through faith
Galatians 3:17, 18...And this I say, that the covenant, that was confirmed before of God in Christ, the law, which was four hundred and thirty years after, cannot disannul, that it should make the promise of none effect. For if the inheritance be of the law, it is no more of promise: but God gave it to Abraham by promise.
Rightly dividing God's Word.