ChainSafe / web3.unity

🕹 Unity SDK for building games that interact with blockchains.
GNU Lesser General Public License v3.0
922 stars 237 forks source link

ERC-1155 BalanceOf sample not working without a wallet connected #1234

Open juans-chainsafe opened 1 day ago

juans-chainsafe commented 1 day ago

Describe the bug Sample BalanceOf located in ERC-1155 section is throwing a error when you click on it and the wallet is not connected. But we shouldn't need a wallet connected for this sample

Steps Steps to reproduce the behavior:

  1. Disconnect the wallet if is connected
  2. Click on BalanceOf sample in ERC-1155

Expected behavior Balance will be displayed in the console

Console errors

Web3Exception: Can’t get player address. No Signer was provided during construction.
ChainSafe.Gaming.Evm.Contracts.BuiltIn.Erc1155Contract.EnsureSigner () (at <63d609a930d44707afd0223af6093800>:0)
ChainSafe.Gaming.Evm.Contracts.BuiltIn.Erc1155Contract.GetBalanceOf (System.String tokenId) (at <63d609a930d44707afd0223af6093800>:0)
ChainSafe.Gaming.Evm.Contracts.BuiltIn.Erc1155Service.GetBalanceOf (System.String contractAddress, System.String tokenId) (at <63d609a930d44707afd0223af6093800>:0)
Erc1155Sample.BalanceOf () (at Assets/Samples/web3.unity SDK/3.0.6/Web3.Unity Samples/Scripts/Samples/Erc1155Sample.cs:88)
Samples.TryExecute (System.Reflection.MethodInfo method, ChainSafe.Gaming.ISample instance) (at ./Library/PackageCache/io.chainsafe.web3-unity@a14c17e17d/Runtime/Scripts/Samples/Samples.cs:92)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <606c2e0a56af495988c860a4ac613e74>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/UnitySynchronizationContext.cs:153)
UnityEngine.UnitySynchronizationContext.Exec () (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/UnitySynchronizationContext.cs:83)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/UnitySynchronizationContext.cs:107)

Desktop (please complete the following information):

Additional context BalanceOf of ERC-721 works as expected.

creeppak commented 1 day ago

This is expected as the sample requests balance for the current user, which means we need wallet to be connected in order to read the wallet address.

The sample should be reworked however to fetch the balance of the predefined wallet address instead of the balance of the connected wallet.