#Error to get balance of ERC20 on zkEVM Cardona Testnet

1 messages · Page 1 of 1 (latest)

rustic sparrow
#

Getting the following error
"Web3Exception: RPC returned error for "eth_call": -32000 err: insufficient funds for gas * price + value: address 0xB65f5Ac5eAD9598f7Ec61c8C89033B970dA7B77D have 0 want 748486779400000000 (supplied gas 50000000)
ChainSafe.Gaming.Evm.Providers.RpcClientProvider.Perform[T] (System.String method, System.Object[] parameters)

Rethrow as Web3Exception: eth_call: bad result from RPC endpoint
ChainSafe.Gaming.Evm.Providers.RpcClientProvider.Perform[T] (System.String method, System.Object[] parameters)

ChainSafe.Gaming.Evm.Providers.RpcProviderExtensions.Call (ChainSafe.Gaming.Evm.Providers.IRpcProvider provider, ChainSafe.Gaming.Evm.Transactions.TransactionRequest transaction, Nethereum.RPC.Eth.DTOs.BlockParameter blockTag)

ChainSafe.Gaming.Evm.Contracts.Contract.Call (System.String method, System.Object[] parameters, ChainSafe.Gaming.Evm.Transactions.TransactionRequest overwrite)

ChainSafe.Gaming.Evm.Contracts.BuiltIn.Erc20Contract.GetBalanceOf (System.String accountAddress)"

But can check balance using Remix Ide.

public async void BalanceOf()
    {
        var balance = await Web3Accessor.Web3.Erc20.GetBalanceOf(
            "0x24383f6AC03b6B43ae95CFb83C88762Af1e142E8",
            "0xB65f5Ac5eAD9598f7Ec61c8C89033B970dA7B77D");
        Debug.Log("Balance of : "+ balance);
    }
idle sinew
#

@rustic sparrow

terse delta
#

we have an issue for this already i think

rustic sparrow
terse delta
#

are you trying to do it on webgl by any chance?

rustic sparrow
terse delta
#

ok good, solves that possiblity

#

just have to wait for the issue to be resolved in the next release

rustic sparrow
terse delta
#

i mean if it was fixed, sure

#

but it's not fixed yet unfortunately

rustic sparrow
terse delta
#

once the issue above closes with a solution you should be able to

rustic sparrow
#

Balance checking is working fine. If the required chain is set correctly in ProjectConfigData file inside resources folder.
Sometimes Server settings menu don't save if just select chain and close window without any other edit.

rustic sparrow
terse delta
#

it should auto save on any change, @robust vault

rustic sparrow
#

I am trying to switch network just by logging out, and destroying the Web3Accessor and Destroying WalletConnectDialog.
And again Calling Initialize of LoginProvider after changing the ProjectConfigData, wallet is connecting successfully, but I think chain is not changing, because new chain token balance is always shown as 0.

Is there any quick solution for this ?

robust vault
rustic sparrow
robust vault
#

You can check if the chain is correct by debug logging the webe.chainconfig.chainId

rustic sparrow
robust vault
#

Can you give me the snippet of your code, and the address to the contract, as well as the chain config, would like to test it out

rustic sparrow
# robust vault Can you give me the snippet of your code, and the address to the contract, as we...
public class WalletConnectLoginProviderDD : LoginProviderDD, IWeb3BuilderServiceAdapter
{
    [SerializeField] private WalletConnectConfigSO walletConnectConfig;
    
    [SerializeField] private Button loginButton;
    private void OnEnable()
    {
        loginButton.onClick.AddListener(Initialize);
    }

    protected override void Initialize()
    {
        base.Initialize();
        OnLoginClicked();
    }

    public Web3Builder ConfigureServices(Web3Builder web3Builder)
    {
        return web3Builder.Configure(services =>
        {
            services.UseWalletConnect(walletConnectConfig)
                .UseWalletConnectSigner()
                .UseWalletConnectTransactionExecutor();
        });
    }

    private async void OnLoginClicked()
    {
        await TryLogin();
    }
}

I am using this Custom Script for Wallet Connect Logic.
I am calling the Initialize() when Connect button will be clicked, not on start, so that it can be initialized with selected chain. LoginProviderDD class is same as LoginProvider class without the Start function.

  1. At first I am setting Binance Mainnet on ProjectConfigData (ScriptableObject) inside Resources folder.

  2. Clicking on Connect Button, it is being initialized with Binance Mainnet and connecting Wallet and Showing Balance as 0. It's okay because the token is deployed on another chain.

  3. Now I am disconnecting wallet by Calling

await Web3Accessor.TerminateAndClear(logout: true);
  1. Destroying Web3Accessor gameobject and WalletConnect Dialog in the scene.

  2. Setting ProjectConfigData again for Cardona Testnet,

  3. Clicking on connect button, so again initializing and connecting wallet.
    Debug log is showing chain as Cardona, but the balance of the token is 0 again. It should show 960.

But if we at first set as Cardona and initialize and connect, the showing correct balance.

#

My token is on Cardona Testnet (chain id 2442) and contract address is 0x24383f6AC03b6B43ae95CFb83C88762Af1e142E8

And this wallet 0xB65f5Ac5eAD9598f7Ec61c8C89033B970dA7B77D
has 960 of the above token.

rustic sparrow
#

The first selected chain balance is always showing even we change chain in ProjectConfigData resource file and Initialize again. Even not showing any error.

robust vault
#

Setting ProjectConfigData again for Cardona Testnet,
How are you setting the projectconfigdata

#

like while you are in the unity game you are directly changing your scriptable object in the editor itself?

robust vault
#

Can you send that code snippet when you actually change the chain ? If you are doing it dynamically

rustic sparrow
#

One minute

#
private void NetworkChanged(ChainDetails chainDetails)
    {
        Debug.Log("Network Changed to " + chainDetails.chainName);
        currentChainDetails = chainDetails;
        //chainConfigResource = chainDetails.chainConfig;
        chainConfigResource.Chain = chainDetails.chainConfig.Chain;
        chainConfigResource.ChainId = chainDetails.chainConfig.ChainId;
        chainConfigResource.Network = chainDetails.chainConfig.Network;
        chainConfigResource.Symbol = chainDetails.chainConfig.Symbol;
        chainConfigResource.Rpc = chainDetails.chainConfig.Rpc;

    }
#

Here is the full Script

using ChainSafe.Gaming.UnityPackage;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using UnityEngine;

public class BlockchainManager : MonoBehaviour
{
    [SerializeField] private ProjectConfigScriptableObject chainConfigResource;


    private void OnEnable()
    {
        NetworkSlider.OnNetworkChainChanged += NetworkChanged;
    }
    private void OnDisable()
    {
        NetworkSlider.OnNetworkChainChanged -= NetworkChanged;
    }


    public static BlockchainManager Instance;
    private void Awake()
    {
        if(Instance != null && Instance != this)
        {
            Destroy(gameObject);
        }
        Instance = this;
        
       
    }
    private void NetworkChanged(ChainDetails chainDetails)
    {
        Debug.Log("Network Changed to " + chainDetails.chainName);
        currentChainDetails = chainDetails;
        //chainConfigResource = chainDetails.chainConfig;
        chainConfigResource.Chain = chainDetails.chainConfig.Chain;
        chainConfigResource.ChainId = chainDetails.chainConfig.ChainId;
        chainConfigResource.Network = chainDetails.chainConfig.Network;
        chainConfigResource.Symbol = chainDetails.chainConfig.Symbol;
        chainConfigResource.Rpc = chainDetails.chainConfig.Rpc;
    }
}

[Serializable]
public class ChainDetails
{
    public ChainName chainName;
    public Sprite chainIcon;
    public ProjectConfigScriptableObject chainConfig;

}

public enum ChainName
{
    BSC_Main,
    Polygon_Main,
    Test
}

#

Here I have created ProjectConfig scriptable objects and passing for selected chain

#

chainConfigResource is the reference for ProjectConfigData inside resources folder. And this is being updated succesfully.

robust vault
#

Aha so you just use it like Resources.Load<PRojectConfigScriptableObject>("NAME");

#

Got it

rustic sparrow
robust vault
#

I will try to fix the issue for the upcoming release of the sdk in the next week

#

Since tomorrow is company-wide day off

#

So will keep you updated

rustic sparrow
rustic sparrow
robust vault
#

Can you check maybe if the rpc is also correct

rustic sparrow
robust vault
#

SEnding you a DM