xclud / web3dart

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

When calling eth_call with empty params it returns 400 code #91

Open Hathoriel opened 1 year ago

Hathoriel commented 1 year ago

Hi When calling eth_call with empty params it returns 400 code, can you help please? For instance balanceOf works well, but name or decimals erc20 method calls don't works. Before call

image image

Response:

image

Thank you for any help!

4xMafole commented 1 year ago

Hi, @Hathoriel you can paste code samples here for easy visibility. We prefer seeing source code samples where the error/bug occurs than images 😁.

Hathoriel commented 1 year ago

hi @4xMafole sorry for bad format. Here are code samples: But when you see just code without variables, you can only expect what is inside :-D

  Future<Web3Client> _getEthClient() async {
    final network = await _networkService.getActiveNetwork();
    var httpClient = Client();
    return Web3Client(network['rpc_url'], httpClient);
  }

  Future<DeployedContract> getContract(String contractAddress) async {
    final abiCode = await rootBundle.loadString('assets/abi/erc20.json');
    final EthereumAddress contractAddr = EthereumAddress.fromHex(contractAddress);
    return DeployedContract(ContractAbi.fromJson(abiCode, 'Datachain'), contractAddr);
  }

  _callRpc(
    String contractAddress,
    String method,
    List<dynamic> params,
  ) async {
    final contract = await getContract(contractAddress);
    final client = await _getEthClient();
    final response = await client.call(contract: contract, function: contract.function(method), params: params);
    return response;
  }

  getDecimals(String contractAddress) async {
    final decimals = await _callRpc(contractAddress, 'decimals', []);
    return decimals[0].toString();
  }