Closed Hajto closed 1 year ago
iex(9)> ABI.parse_specification([
...(9)> %{
...(9)> "inputs" => [],
...(9)> "name" => "getSeaportMetadata",
...(9)> "outputs" => [
...(9)> %{"internalType" => "string", "name" => "name", "type" => "string"},
...(9)> %{
...(9)> "components" => [
...(9)> %{
...(9)> "internalType" => "uint256",
...(9)> "name" => "id",
...(9)> "type" => "uint256"
...(9)> },
...(9)> %{
...(9)> "internalType" => "bytes",
...(9)> "name" => "metadata",
...(9)> "type" => "bytes"
...(9)> }
...(9)> ],
...(9)> "internalType" => "struct Schema[]",
...(9)> "name" => "schemas",
...(9)> "type" => "tuple[]"
...(9)> }
...(9)> ],
...(9)> "stateMutability" => "view",
...(9)> "type" => "function"
...(9)> }
...(9)> ]
...(9)> )
[
%ABI.FunctionSelector{
function: "getSeaportMetadata",
method_id: <<46, 119, 142, 252>>,
type: :function,
inputs_indexed: nil,
state_mutability: :view,
input_names: [],
types: [],
returns: [:string, {:array, {:tuple, [{:uint, 256}, :bytes]}}]
}
]
iex(16)> data
<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 84, 101, 115, 116,
90, 111, 110, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,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0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>>
iex(17)> sig
%ABI.FunctionSelector{
function: "getSeaportMetadata",
method_id: <<46, 119, 142, 252>>,
type: :function,
inputs_indexed: nil,
state_mutability: :view,
input_names: [],
types: [],
returns: [:string, {:array, {:tuple, [{:uint, 256}, :bytes]}}]
}
iex(18)> ABI.decode(sig, data)
** (MatchError) no match of right hand side value: {:ok, <<0, 0, 0, 0>>, <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...>>}
(ex_abi 0.6.0) lib/abi/type_decoder.ex:143: ABI.TypeDecoder.decode/3
iex:18: (file)
@Hajto worked for me if I specify 3rd param as :output
, e.g.
iex(13)> ABI.decode(abi |> Enum.at(0), data, :output)
[
"TestZone",
[
{7,
<<121, 75, 4, 142, 43, 203, 171, 33, 92, 123, 98, 107, 71, 192, 185, 125,
12, 120, 178, 163, 202, 157, 164, 125, 43, 48, 148, 174, 153, 176, 203,
55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...>>}
]
]
@atapin. thank you
Library version:
0.6.0