How to set a default color for the WordPress Customizer’s color picker?

I was actually able to get this to work with the help of kind developers on the WordPress.org forum, and I will post the answer to my question here to benefit anyone who has the same problem.

It is best to use the WP core functionality if it exists, which is the case for color controls, and to create an instance of the core WP_Customize_Color_Control class.

Here’s the corrected code:

function mytheme_customize_register( $wp_customize ) {

    $wp_customize->add_setting( 'footer_color',
    array(
        'default' => '#000000',
        'transport' => 'refresh',
        'sanitize_callback' => 'sanitize_hex_color',
    )
    );

    $wp_customize->add_control(
        new WP_Customize_Color_Control(
        $wp_customize,
        'footer_color',
        array(
          'label' => __( 'Footer Color', 'textdomain' ),
          'section' => 'colors',
          'capability' => 'edit_theme_options',
          )
        )
    );

}
add_action( 'customize_register', 'mytheme_customize_register' );

error code: 523