Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Balance from providers not working #43

Open
princepspolycap opened this issue Feb 23, 2022 · 2 comments
Open

Get Balance from providers not working #43

princepspolycap opened this issue Feb 23, 2022 · 2 comments

Comments

@princepspolycap
Copy link

princepspolycap commented Feb 23, 2022

I have been trying to get the balance from an account that is on the Gnosis Chain. I tried to get the balance on the Ethereum chain too and I haven't been able to. All the providers I have tried return null.

WalletConnectProvider walletConnectProvider = WalletConnectProvider.fromRpc(
   {100: 'https://rpc.gnosischain.com/'},
   chainId: 100,
   network: 'xdai',
 );

 final rpcProvider = JsonRpcProvider('https://rpc.gnosischain.com/');

 Future<BigInt> getBalanceOf(String tokenAddress, String address) async {
   final contract = ContractERC20(tokenAddress, provider);
   return contract.balanceOf(address);
 }

 Future<BigInt> getNativeTokenBalanceOf(String address) async {
   try {
//      return await getBalanceOf(stakeTokenAddress, testAccountAddress);
//      return await provider!.getSigner().getBalance(ethTokenAddress);

   } catch (error) {
     _error = "${error.toString()} $rpcProvider";
     return BigInt.zero;
   }
 }

Can anyone let me know what I'm doing wrong?

@patzu
Copy link

patzu commented Aug 13, 2022

Could you find a solution for this?

@4xMafole
Copy link

Did you add this to the below script in your web/index.html file?
<script src="https://cdn.ethers.io/lib/ethers-5.2.umd.min.js" type="application/javascript"></script>
I was facing a different issue of writing to the blockchain since I was missing the line. So, give it a try and hope it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants