xclud / web3dart

Ethereum library, written in Dart.
https://pub.dev/packages/web3dart
MIT License
170 stars 94 forks source link

getBalance not working with Polygon chain #61

Open jacobokoenig opened 1 year ago

jacobokoenig commented 1 year ago

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)

MahmoudKEA commented 1 year ago

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)));