fix ens resolution to use resolver from registry (#3453)

* fix ens resolution to use resolver from registry * minor fix

Serhii committed Aug 7, 2026 at 23:19 UTC 43ae37df2076a089bfd277ea1bab74a6d91134c9
2 files changed +31 -19
lib/core/address_resolver/ens/ens_address_provider.dart
+1 -2
@@ -11,8 +11,7 @@ class EnsAddressProvider extends AddressLookupProvider {
11 AddressSource get source => AddressSource.ens;
12
13 @override
14 - List<CryptoCurrency> get supportedCurrencies =>
15 - [CryptoCurrency.xmr, CryptoCurrency.btc, CryptoCurrency.eth];
14 + List<CryptoCurrency> get supportedCurrencies => [CryptoCurrency.eth];
15
16 @override
17 bool isEnabled(SettingsStore settingsStore) => settingsStore.lookupsENS;
lib/core/address_resolver/ens/ens_record.dart
+30 -17
@@ -1,11 +1,11 @@
1 -import 'package:cake_wallet/evm/evm.dart';
2 -import 'package:cw_core/crypto_currency.dart';
3 -import 'package:cw_core/utils/proxy_wrapper.dart';
4 -import 'package:cw_core/utils/print_verbose.dart';
5 -import 'package:cw_core/wallet_base.dart';
6 -import 'package:cw_core/wallet_type.dart';
7 -import 'package:ens_dart/ens_dart.dart';
8 -import 'package:web3dart/web3dart.dart';
1 +import "package:cake_wallet/evm/evm.dart";
2 +import "package:cw_core/crypto_currency.dart";
3 +import "package:cw_core/utils/print_verbose.dart";
4 +import "package:cw_core/utils/proxy_wrapper.dart";
5 +import "package:cw_core/wallet_base.dart";
6 +import "package:cw_core/wallet_type.dart";
7 +import "package:ens_dart/ens_dart.dart";
8 +import "package:web3dart/web3dart.dart";
9
10 class EnsRecord {
11 static Future<String> fetchEnsAddress(
@@ -20,36 +20,49 @@ class EnsRecord {
20 }
21
22 _client ??= Web3Client(
23 - 'https://ethereum-rpc.publicnode.com',
23 + "https://ethereum-rpc.publicnode.com",
24 ProxyWrapper().getHttpIOClient(),
25 );
26
27 - final ens = Ens(client: _client);
27 + final registryEns = Ens(client: _client).withName(name);
28 final coinType = getEnsCoinType(cur);
29
30 if (coinType == null) {
31 - printV('Unsupported currency for ENS: $cur');
32 - return '';
31 + printV("Unsupported currency for ENS: $cur");
32 + return "";
33 }
34
35 try {
36 - if (coinType == CoinType.ETH || coinType == CoinType.MATIC) {
37 - return (await ens.withName(name).getAddress()).hex;
36 + // Check if the ENS name has its resolver set. If not, return an empty string.
37 + final resolverAddress = await registryEns.getResolverAddress(registryEns.nodeHash);
38 +
39 + if (isZeroAddress(resolverAddress)) {
40 + printV("No resolver set for ENS name: $name");
41 + return "";
42 + }
43 +
44 + final resolverEns = Ens(client: _client,address: resolverAddress).withName(name);
45 +
46 + if (coinType == CoinType.ETH) {
47 + return (await resolverEns.getAddress()).hex;
48 } else {
39 - return await ens.withName(name).getCoinAddress(coinType);
49 + return await resolverEns.getCoinAddress(coinType);
50 }
51 } catch (e) {
52 printV(e);
43 - return '';
53 + return "";
54 }
55 }
56
57 + static bool isZeroAddress(EthereumAddress address) =>
58 + address.addressBytes.every((byte) => byte == 0);
59 +
60 static CoinType? getEnsCoinType(CryptoCurrency cur) => switch (cur) {
61 CryptoCurrency.xmr => CoinType.XMR,
62 CryptoCurrency.btc => CoinType.BTC,
63 CryptoCurrency.ltc => CoinType.LTC,
64 CryptoCurrency.eth => CoinType.ETH,
52 - CryptoCurrency.matic => CoinType.MATIC,
65 + CryptoCurrency.maticpoly => CoinType.MATIC,
66 _ => null,
67 };
68 }