Skip to content

Commit d8b0346

Browse files
committed
refactor: sample app get balance docs
1 parent 6b684d3 commit d8b0346

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

sample/Assets/Scripts/ZkEvmGetBalance.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,33 @@ void Start()
3030
}
3131
}
3232

33+
/// <summary>
34+
/// Gets the balance of the account for the specified address.
35+
/// The balance is obtained in hexadecimal format and then converted to decimal for display.
36+
/// </summary>
3337
public async void GetBalance()
3438
{
35-
ShowOutput($"Called GetBalance()...");
39+
ShowOutput("Getting account balance...");
3640

3741
try
3842
{
39-
string balance = await Passport.ZkEvmGetBalance(AddressInput.text);
40-
var balanceBI = BigInteger.Parse(balance.Replace("0x", "0"), NumberStyles.HexNumber);
41-
ShowOutput($"Hex: {balance}\nDec: {balanceBI}");
43+
// Retrieve the balance in hexadecimal format
44+
string balanceHex = await Passport.ZkEvmGetBalance(AddressInput.text);
45+
46+
// Convert the hexadecimal balance to a BigInteger for decimal representation
47+
var balanceDec = BigInteger.Parse(balanceHex.Replace("0x", ""), NumberStyles.HexNumber);
48+
49+
// Display both hexadecimal and decimal representations of the balance
50+
ShowOutput($"Balance:\nHex: {balanceHex}\nDec: {balanceDec}");
4251
}
4352
catch (Exception ex)
4453
{
4554
ShowOutput($"Failed to get balance: {ex.Message}");
4655
}
4756
}
4857

58+
59+
4960
/// <summary>
5061
/// Navigates back to the authenticated scene.
5162
/// </summary>

0 commit comments

Comments
 (0)