WalletConnect constructor

WalletConnect({
  1. String bridge = '',
  2. String uri = '',
  3. WalletConnectSession? session,
  4. SessionStorage? sessionStorage,
  5. CipherBox? cipher,
  6. SocketTransport? transport,
  7. String? clientId,
  8. PeerMeta? clientMeta,
})

WalletConnect is an open source protocol for connecting decentralised applications to mobile wallets with QR code scanning or deep linking.

You should provide a bridge, uri or session object.

Implementation

factory WalletConnect({
  String bridge = '',
  String uri = '',
  WalletConnectSession? session,
  SessionStorage? sessionStorage,
  CipherBox? cipher,
  SocketTransport? transport,
  String? clientId,
  PeerMeta? clientMeta,
}) {
  if (bridge.isEmpty && uri.isEmpty && session == null) {
    throw WalletConnectException(
      'Missing one of the required parameters: bridge / uri / session',
    );
  }

  if (bridge.isNotEmpty) {
    bridge = BridgeUtils.getBridgeUrl(bridge);
  }

  if (uri.isNotEmpty) {
    session = WalletConnectSession.fromUri(uri);
  }

  session = session ??
      WalletConnectSession(
        bridge: bridge,
        accounts: [],
        clientId: clientId ?? const Uuid().v4(),
        clientMeta: clientMeta ?? const PeerMeta(),
      );

  cipher = cipher ?? WalletConnectCipher();

  transport = transport ??
      SocketTransport(
        protocol: session.protocol,
        version: session.version,
        url: session.bridge,
        subscriptions: [session.clientId],
      );

  return WalletConnect._internal(
    session: session,
    sessionStorage: sessionStorage,
    cipherBox: cipher,
    signingMethods: [...ethSigningMethods],
    transport: transport,
  );
}