diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/contract.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/contract.ex index 0f1cec0cd4..2ca335c076 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/contract.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/contract.ex @@ -32,14 +32,21 @@ defmodule EthereumJSONRPC.Contract do abi |> ABI.parse_specification() - functions = Enum.into(parsed_abi, %{}, &{&1.function, &1}) + functions = Enum.into(parsed_abi, %{}, &{&1.method_id, &1}) requests_with_index = Enum.with_index(requests) + [{%{function_name: function_name}, _}] = requests_with_index + indexed_responses = requests_with_index |> Enum.map(fn {%{contract_address: contract_address, function_name: function_name, args: args} = request, index} -> - functions[function_name] + {_, function} = + Enum.find(functions, fn {method_id, func} -> + func.function == function_name && Enum.count(func.input_names) == Enum.count(args) + end) + + function |> Encoder.encode_function_call(args) |> eth_call_request(contract_address, index, Map.get(request, :block_number), Map.get(request, :from)) end)