eth_event v0.1.1 EthEvent.Encode View Source
The available solidity types are:
:quantity
- Unsigned int without left zero padding. Also admits tags.{:array, type}
- List of values as a specifictype
.{:topic, type}
- A 32 bits left zero padded encoded value as a specifictype
.:bool
- Boolean type (1 byte).{:uint, n}
- Unsigned integer of sizen
bits, where0 < n <= 256
andInteger.mod(n, 8) == 0
.{:int, n}
- Two’s complement integer of sizen
bits, where0 < n <= 256
andInteger.mod(n, 8) == 0
:address
- Ethereum address (20 bytes).{:bytes, n}
-n
bytes where0 < n <= 32
.
Encode Elixir types to EVM types
When given a Elixir type (integer()
or binary()
), use the function
EthEvent.Encode.encode/2
to ecode it to an EVM compliant type.
> EthEvent.Decode.decode({:int, 8}, -1)
"0x81"
The result shows the transformation of -1
to the EVM’s twos complement
integer encoded value.
Solidity compliant keccak256
> data = "Transfer(address,address,uint256)"
> EthEvent.Encode.keccak256(data)
Link to this section Summary
Functions
Encodes Elixir types to EVM types. Receives a type
and a value
to encode
Solidity compliant keccak256 function over a string
Link to this section Types
Basic types
Types for encoding.
Link to this type
payload_type()
View Source
payload_type() :: :quantity | {:array, basic_type()} | {:topic, basic_type()}
Payload types
Link to this section Functions
Link to this function
encode(type, value)
View Source
encode(encode_type(), term()) :: {:ok, binary()} | {:ok, [binary()]} | {:error, term()}
Encodes Elixir types to EVM types. Receives a type
and a value
to encode.
The available solidity types are:
:quantity
- Unsigned int without left zero padding. Also admits tags.{:array, type}
- List of values as a specifictype
.{:topic, type}
- A 32 bits left zero padded encoded value as a specifictype
.:bool
- Boolean type (1 byte).{:uint, n}
- Unsigned integer of sizen
bits, where0 < n <= 256
andInteger.mod(n, 8) == 0
.{:int, n}
- Two’s complement integer of sizen
bits, where0 < n <= 256
andInteger.mod(n, 8) == 0
:address
- Ethereum address (20 bytes).{:bytes, n}
-n
bytes where0 < n <= 32
.
Solidity compliant keccak256 function over a string
.