Gutenberg blocks are stored with the database in the following format. Take a look for the paragraph tag.
<!-- wp:paragraph -->
<p>Here is the paragraph content.</p>
<!-- /wp:paragraph -->
And you can use the regular expression to find out the particular block.
// Get the post_content
$post_content = get_the_content( get_the_ID() );
// Get all matches in between <!-- /wp: --> strings
preg_match_all('<!-- /wp:(.*?) -->', $post_content, $blocks);
// Post content contains a wp:heading block
if ( in_array( 'heading', $blocks[1] ) ) {
// Your codes
}
else {
// Your codes
}