Skip to content

Commit 7112341

Browse files
committedJun 12, 2023
Balance fallback
1 parent 046645b commit 7112341

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed
 

‎Assets/Thirdweb/Core/Scripts/Wallet.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,16 @@ public async Task<CurrencyValue> GetBalance(string currencyAddress = Utils.Nativ
214214
}
215215
else
216216
{
217-
var balance = await new Web3(ThirdwebManager.Instance.SDK.session.RPC).Eth.GetBalance.SendRequestAsync(await GetAddress());
217+
HexBigInteger balance = null;
218+
string address = await GetAddress();
219+
try
220+
{
221+
balance = await ThirdwebManager.Instance.SDK.session.Web3.Eth.GetBalance.SendRequestAsync(address);
222+
}
223+
catch
224+
{
225+
balance = await new Web3(ThirdwebManager.Instance.SDK.session.RPC).Eth.GetBalance.SendRequestAsync(address);
226+
}
218227
var nativeCurrency = ThirdwebManager.Instance.SDK.session.CurrentChainData.nativeCurrency;
219228
return new CurrencyValue(nativeCurrency.name, nativeCurrency.symbol, nativeCurrency.decimals.ToString(), balance.Value.ToString(), balance.Value.ToString().ToEth());
220229
}

‎Assets/Thirdweb/Examples/Scripts/Prefabs/Prefab_ConnectWallet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ async void OnConnected()
211211
}
212212
catch (Exception e)
213213
{
214-
Debug.LogWarning($"Error Fetching Native Balance: {e.Message}");
214+
Debug.LogWarning($"Error Fetching Native Balance: {e}");
215215
}
216216
}
217217

0 commit comments

Comments
 (0)
Please sign in to comment.