enablePlugin method

Future<String> enablePlugin(
  1. String pluginAddress
)

Enables a plugin for the smart wallet.

This function checks if the smart wallet is initialized, then verifies if the plugin is already enabled. If the plugin is not enabled, it sends a transaction to enable the plugin and returns the transaction hash.

Parameters:

  • pluginAddress: The address of the plugin to be enabled.

Returns:

  • A Future

Throws:

  • Exception if the smart wallet is not initialized or if the plugin is already enabled.

Implementation

Future<String> enablePlugin(String pluginAddress) async {
  await checkIfInitialized();
  if (!isInitialized!) throw Exception("Smart wallet not initialized");
  try {
    bool isEnabled = await isPluginEnabled(pluginAddress);
    if (isEnabled) throw Exception("Plugin already enabled");
    TransactionResponse txResponse =
        await contract.send("enableModule", [pluginAddress]);
    return txResponse.hash;
  } catch (e) {
    // Print any error that occurs during the process and throw a new exception with an error message.
    print(e);
    throw Exception("Could not enable plugin");
  }
}