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 specific type.
  • {:topic, type} - A 32 bits left zero padded encoded value as a specific type.
  • :bool - Boolean type (1 byte).
  • {:uint, n} - Unsigned integer of size n bits, where 0 < n <= 256 and Integer.mod(n, 8) == 0.
  • {:int, n} - Two’s complement integer of size n bits, where 0 < n <= 256 and Integer.mod(n, 8) == 0
  • :address - Ethereum address (20 bytes).
  • {:bytes, n} - n bytes where 0 < 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

Types

Basic types

Types for encoding

Payload types

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

Link to this type basic_type() View Source
basic_type() ::
  :bool
  | :address
  | {:uint, integer()}
  | {:int, integer()}
  | {:bytes, integer()}

Basic types

Link to this type encode_type() View Source
encode_type() :: basic_type() | payload_type()

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 specific type.
  • {:topic, type} - A 32 bits left zero padded encoded value as a specific type.
  • :bool - Boolean type (1 byte).
  • {:uint, n} - Unsigned integer of size n bits, where 0 < n <= 256 and Integer.mod(n, 8) == 0.
  • {:int, n} - Two’s complement integer of size n bits, where 0 < n <= 256 and Integer.mod(n, 8) == 0
  • :address - Ethereum address (20 bytes).
  • {:bytes, n} - n bytes where 0 < n <= 32.
Link to this function keccak256(string) View Source
keccak256(binary()) :: binary()

Solidity compliant keccak256 function over a string.