Packages
abi
0.1.1
1.3.0
1.2.0
1.1.0
1.0.0-bravo6
1.0.0-bravo4
1.0.0-bravo3
1.0.0-bravo2
1.0.0-bravo1
1.0.0-alpha9
1.0.0-alpha8
1.0.0-alpha7
1.0.0-alpha6
1.0.0-alpha5
1.0.0-alpha4
1.0.0-alpha3
1.0.0-alpha2
1.0.0-alpha1
0.1.21
0.1.21-alpha2
0.1.21-alpha1
0.1.20
0.1.19
0.1.18
0.1.17
0.1.16
0.1.15
0.1.13
0.1.12
0.1.11
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Ethereum's ABI Interface
Current section
Files
Jump to
Current section
Files
lib/abi.ex
defmodule ABI do
@moduledoc """
Documentation for ABI, the function interface language for Solidity.
Generally, the ABI describes how to take binary Ethereum and transform
it to or from types that Solidity understands.
"""
@doc """
Encodes the given data into the function signature.
## Examples
iex> ABI.encode("baz(uint,address)", [50, <<1::160>> |> :binary.decode_unsigned])
...> |> Base.encode16(case: :lower)
"a291add600000000000000000000000000000000000000000000000000000000000000320000000000000000000000000000000000000000000000000000000000000001"
iex> ABI.encode("baz(uint8)", [9999])
** (RuntimeError) Data overflow encoding uint, data `9999` cannot fit in 8 bits
"""
def encode(function_signature, data) do
ABI.TypeEncoder.encode(
data,
ABI.FunctionSelector.decode(function_signature)
)
end
@doc """
Decodes the given data based on the function signature.
## Examples
iex> ABI.decode("baz(uint,address)", "00000000000000000000000000000000000000000000000000000000000000320000000000000000000000000000000000000000000000000000000000000001" |> Base.decode16!(case: :lower))
[50, <<1::160>>]
"""
def decode(function_signature, data) do
ABI.TypeDecoder.decode(
data,
ABI.FunctionSelector.decode(function_signature)
)
end
end