Show the site name in a custom block
Get the site name from config and add the config as cacheable dependency so that the block gets updated when you change the site name.
public function build() {
  $config = \Drupal::config('system.site');

  $build = [
    '#markup' =&gt; $config-&gt;get('name'),
  ];

  $renderer = \Drupal::service('renderer');
  $renderer-&gt;addCacheableDependency($build, $config);

  return $build;
}