MetaMask / metamask-docs

Developer documentation for MetaMask
https://docs.metamask.io
Apache License 2.0
656 stars 939 forks source link

Returns a string instead of a BigInteger[] #1232

Closed devon-bfs closed 5 months ago

devon-bfs commented 5 months ago

TLDR: Contract call is supposed to return an array of BigIntegers but is returning a hex string instead

I have a method on a contract that returns a uint256

The contract backing created by metamask with the contract code generator created this method for it

public Task<BigInteger[]> WalletOfOwner(EvmAddress _owner, CallOptions options = default)
        {
            var method = System.Reflection.MethodBase.GetCurrentMethod();
            return (Task<BigInteger[]>) InvokeMethod(method, new object[] { _owner, options });
        }

When called BigInterger[] result = await contract.WalletOfOwner(MetaMaskUnity.Instance.Wallet.SelectedAddress);

Unity throws the error

Error calling WalletOfOwner: Error converting value "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000a" to type 'System.Numerics.BigInteger[]'. Path 'result', line 1, position 825.
UnityEngine.Debug:LogError (object)
MetaMask.Unity.PhantomGalaxies.Metamask/<NFTWalletOfOwner>d__16:MoveNext () (at Assets/Scripts/Metamask.cs:172)
System.Reflection.MethodBase:Invoke (object,object[])
evm.net.Contract/<WaitForTaskCompleted>d__42:MoveNext ()
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<System.Numerics.BigInteger[]>:SetException (System.Exception)
evm.net.HttpProvider/<RpcRequest>d__14`1<System.Numerics.BigInteger[]>:MoveNext ()
System.Threading.Tasks.TaskCompletionSource`1<string>:SetResult (string)
MetaMask.IO.MetaMaskHttpService/<SendRequestUnity>d__10:MoveNext () (at Assets/MetaMask/Scripts/IO/MetaMaskHttpService.cs:233)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/Coroutines.cs:17)

It looks like its returning a hash string instead of a array of big integers.

When I convert the function in ContractBacking.cs to return a string and modify the calling code it doesn't return anything

alexandratran commented 5 months ago

@ecp4224 Can you confirm whether this requires a documentation update?

ecp4224 commented 5 months ago

This is a bug, no doc updates should be required @alexandratran

I've gone ahead and created a bug report here: MetaMask/metamask-sdk#791 @devon-bfs We should have this fixed in the next version.