addNetwork method
Future<void>
addNetwork(
- String chain,
- String accountAddress,
- NetworkConfiguration network
override
Adds an EVM network using EIP-3085. Other chains throw NetworkAddingUnavailableError.
Implementation
@override
Future<void> addNetwork(String chain, String accountAddress, NetworkConfiguration network) async {
Future<void> instrumentationOperation() async {
final operationScope = _state.flowScope.capture(replace: false);
await operationScope.ready();
final walletConnectProjectId = _state.projectSettings?.sdk?.walletConnect?.projectId;
if (walletConnectProjectId == null) {
throw DynamicStateException("This environment has no WalletConnect projectId — enable WalletConnect for it in the Dynamic dashboard");
}
operationScope.check();
await _externalWalletProvider.initialize(walletConnectProjectId, _config.appName, _config.appLogoUrl, _config.nativeLink, _config.universalLink);
operationScope.check();
if (chain != "EVM") {
throw DynamicStateException("this wallet provider does not support adding a network for this chain");
}
_state.externalWalletActionRequested.emit(ExternalWalletActionRequest(action: "addNetwork", walletName: (_externalWalletState.externalWalletAccounts == null ? null : firstWhereOrNull<ExternalWalletAccount>(_externalWalletState.externalWalletAccounts!, (item) => item.address == accountAddress))?.displayName, address: accountAddress, chain: chain));
operationScope.check();
await _externalWalletProvider.addNetwork(chain, accountAddress, network);
operationScope.check();
}
return await _api.instrumentation.runAsync("externalWallet.addNetwork", instrumentationOperation);
}