xclud/web3dart

When calling eth_call with empty params it returns 400 code

Hathoriel opened this issue · 2 comments

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!

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

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