ABI.find_and_decode
You're seeing just the function
find_and_decode
, go back to ABI module for more information.
Link to this function
find_and_decode(function_selectors, data, data_type \\ :input)
Finds and decodes the correct function from a list of ABI.FunctionSelector
s
The function is found based on the method_id
, which is generated from the
keccak hash of the function head. More information can be found here:
https://solidity.readthedocs.io/en/develop/abi-spec.html
Keep in mind, you must include the method identifier in the passed in data otherwise this won't work as expected. If you are decoding transaction input data the identifier is the first four bytes and should already be there.
To find and decode events instead of functions, see find_and_decode_event/6
Examples
iex> File.read!("priv/dog.abi.json")
...> |> Jason.decode!
...> |> ABI.parse_specification
...> |> ABI.find_and_decode("b85d0bd200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001" |> Base.decode16!(case: :lower))
{%ABI.FunctionSelector{type: :function, function: "bark", input_names: ["at", "loudly"], method_id: <<184, 93, 11, 210>>, returns: [], types: [:address, :bool]}, [<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1>>, true]}