web3dart
web3dart copied to clipboard
getBalance not working with Polygon chain
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)
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)));