init method

Future<void> init(
  1. Keyring keyring, {
  2. KeyringEVM? keyringEVM,
  3. WebViewRunner? webView,
  4. String? jsCode,
  5. Function? socketDisconnectedAction,
  6. bool isEVM = false,
})

param jsCode is customized js code of parachain, the api works without jsCode param in Kusama/Polkadot.

Implementation

Future<void> init(
  Keyring keyring, {
  KeyringEVM? keyringEVM,
  WebViewRunner? webView,
  String? jsCode,
  Function? socketDisconnectedAction,
  bool isEVM = false,
}) async {
  final c = Completer();

  await _service.init(
    keyring,
    webViewParam: webView,
    jsCode: jsCode,
    socketDisconnectedAction: socketDisconnectedAction,
    onInitiated: () {
      // inject keyPairs after webView launched
      _service.keyring.injectKeyPairsToWebView(keyring);
      // and initiate pubKeyIconsMap
      api.keyring.updatePubKeyIconsMap(keyring);

      if (keyringEVM != null) {
        _service.eth.keyring.injectKeyPairsToWebView(keyringEVM);
        api.eth.account.updateAddressIconsMap(keyringEVM);
      }

      _updateBlackList();

      if (!c.isCompleted) {
        c.complete();
      }
    },
  );

  api = PolkawalletApi(_service);
  ethers = ApiEthers(_service);
  return c.future;
}