web3dart icon indicating copy to clipboard operation
web3dart copied to clipboard

getBalance not working with Polygon chain

Open jacobokoenig opened this issue 2 years ago • 1 comments

I am using web3dart on Mumbai polygon and I'm using a web3client configured with the appropriate Alchemy link and API.

I am able to send transactions using this library, but I cannot get balance for some reason. It fails parsing the response. For clarity, this is the method I'm calling:

final balance = await _maticClient.getBalance(publicMaticAddress);

And the error is:

FormatException: Unexpected end of input (at character 1)

jacobokoenig avatar Aug 12 '22 17:08 jacobokoenig

Mumbai network may be broken or under maintenance at that time, but now it works fine using this code below

var apiUrl = "https://rpc-mumbai.maticvigil.com";

var httpClient = Client();
var ethClient = Web3Client(apiUrl, httpClient);

ethClient.getBalance(
        EthereumAddress.fromHex('0xa237a197ceACea97f55733A73B8Df7F9C2Ea9309'),
).then((value) => print(value.getValueInUnit(EtherUnit.ether)));

MahmoudKEA avatar Sep 22 '22 12:09 MahmoudKEA