Web3Auth Flutter throws PlatformException on initialization

  • SDK Version: 3.22.3
  • Platform: Android Studio
    -web3auth_flutter : ^5.0.3
  • Browser Console Screenshots:
  • If the issue is related to Custom Authentication, please include the following information (optional):
    • Verifier Name:
    • JWKS Endpoint:
    • Sample idToken (JWT):

web_3_auth_initialization_bloc.dart :

import 'package:bloc/bloc.dart' show Bloc, Emitter;
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:sky_ways/core/errors/failures/auth_failure.dart'
    show Web3AuthInitializationFailure;
import 'package:sky_ways/features/auth/domain/repositories/auth_repository.dart';

part 'web_3_auth_initialization_event.dart';

part 'web_3_auth_initialization_state.dart';

part 'web_3_auth_initialization_bloc.freezed.dart';

class Web3AuthInitializationBloc
    extends Bloc<Web3AuthInitializationEvent, Web3AuthInitializationState> {
  Web3AuthInitializationBloc(
    AuthRepository authRepository,
  )   : _authRepository = authRepository,
        super(
          const Web3AuthInitializationState.initial(),
        ) {
    on<_Initialize>(
      _initialize,
    );
  }

  final AuthRepository _authRepository;

  Future<void> _initialize(
    _Initialize _,
    Emitter<Web3AuthInitializationState> emit,
  ) async {
    emit(
      const Web3AuthInitializationState.initializing(),
    );

    final result = await _authRepository.initializeWeb3Auth();

    result.fold(
      (web3AuthInitializationFailure) => emit(
        Web3AuthInitializationState.failedToInitialize(
          web3AuthInitializationFailure: web3AuthInitializationFailure,
        ),
      ),
      (_) => emit(
        const Web3AuthInitializationState.initialized(),
      ),
    );
  }
}

web_3_auth_initialization_state.dart :

part of 'web_3_auth_initialization_bloc.dart';

@freezed
class Web3AuthInitializationState with _$Web3AuthInitializationState {
  const factory Web3AuthInitializationState.initial() = _Initial;

  const factory Web3AuthInitializationState.initializing() = _Initializing;

  const factory Web3AuthInitializationState.initialized() = _Initialized;

  const factory Web3AuthInitializationState.failedToInitialize({
    required Web3AuthInitializationFailure web3AuthInitializationFailure,
  }) = _FailedToInitialize;
}

web_3_auth_initialization_event.dart :

part of 'web_3_auth_initialization_bloc.dart';

@freezed
class Web3AuthInitializationEvent with _$Web3AuthInitializationEvent {
  const factory Web3AuthInitializationEvent.initialize() = _Initialize;
}

While running the app, it freezes on the splash screen and the logs shows that the web3auth initialization failed. I have attached the screenshot of the logs for reference.

Hello Mayan,

Thank you for reaching out! I see you’re having trouble with the Web3Auth Flutter SDK throwing a PlatformException during initialization. Here are the details you’ve provided that I’ll pass along to our support team:

  • SDK Details: PnP Flutter SDK
  • Issue: Web3Auth Flutter throws PlatformException on initialization
  • SDK Version: 3.22.3
  • Platform: Android Studio
  • web3auth_flutter Version: ^5.0.3
  • Browser Console Screenshots: (not provided)
  • Screen Recording: Attached

From your description, it sounds like the app is freezing on the splash screen due to the initialization failure. If possible, please share any console logs related to the error when running the app. That might help us identify the issue more quickly.

Our support team will review this information and get back to you as soon as possible! In the meantime, you might consider checking if your authentication configurations (like clients or keys) are set up correctly.

If you have any other questions or need further assistance, feel free to ask. We’re here to help!

Note: This response was generated by an AI bot and may require further verification. The Web3Auth support team has tracked this issue and will be responding as soon as possible.

Do you have a try and catch for the initialise function. The initialize function checks whether there is any active session present or not, and if the session is present it initialises the SDK with the active session, or else it’ll throw the error. So, you can handle the error in catch, and swallow it, it won’t create any issues.

Well, the docs says it initializes the Web3Auth Flutter. So, slightly confusing to what you are stating.

Hm, thanks for pointing out. We’ll update the code documentation. To init the SDK, you need to use the init method. The initialize method will help with the session management.

My issue is still not resolved. I think i have initialized it properly. Also, it was working fine before. All of a sudden, it started showing the error in the logs and got stuck on the splash screen that too only on the Android emulator. Can you explain in a little detailed way?

Hey, we did debug, the fetch config project API was failing. We have fixed it, the hotfix will be available soon.

The API has been fixed, please check now.