One way to understand this is that salvation is always by grace thru faith in every time period.
Grace came from God, faith is how men should respond in obedience.
So for Cain, when God told him how to approach him, by offering the correct sacrifice, Cain chose not to respond in obedience, while Abel did, as
Hebrews 11:4 indicated. That response in obedience to what God commanded is seen as faith.
For Abraham, God commanded him to leave the place he was living in and move to a new land. Abraham obeyed God, not knowing whether that place is habitable or not, and
Hebrews 11:8 likewise recognized that as faith.
Later on
Hebrews 11:17 also note that Abraham obeyed God and offered Issac as a sacrifice, God saw that as faith in him too.
By the time Mount Sinai arrived, God commanded the nation Israel to follow the Law of Moses, while providing a system of animal sacrifices whenever they fail to follow it perfectly. As long as the nation kept offering burnt sacrifices and try to keep the Law, God sees that as faith in him too.
That instruction continue to apply to the nation Israel, when Jesus was with them in the 4 gospels.
But now, the current time period we are living in, God commanded the Apostle Paul to tell all of us, Jews and Gentiles,
Romans 4:5.
"But to him that worketh not, but believeth on him that justifieth the ungodly, his faith is counted for righteousness."
This verse is the clearest in telling us who are living in the but now time period,
how should we respond in faith, to God's grace
That is to cease from all works and trust in Christ's finished work on the cross, for our salvation.
The moment we obey God's instructions there, he sees that as us putting faith in him, and he declares us righteous because we obeyed in faith.