web3dart icon indicating copy to clipboard operation
web3dart copied to clipboard

When calling eth_call with empty params it returns 400 code

Open Hathoriel opened this issue 2 years ago • 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!

Hathoriel avatar Feb 03 '23 21:02 Hathoriel

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

4xMafole avatar Feb 04 '23 08:02 4xMafole

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

Hathoriel avatar Feb 04 '23 12:02 Hathoriel