View Source Ethers.Types (Ethers v0.5.5)
EVM types and compound type definitions
Summary
Types
Ethereum address in its hex format with 0x or in its binary format
keccak hash in its hex format with 0x
Public key either in its uncompressed format (64 bytes MAY BE prefixed with 0x04) or its compressed format (32 bytes MUST BE prefixed with 0x02 or 0x03)
Functions
Returns the default value in the given type if supported.
Checks if a given data matches a given solidity type
Returns the maximum possible value in the given type if supported.
Returns the minimum possible value in the given type if supported.
Converts EVM data types to typespecs for documentation
Validates and creates typed values to use with functions or events.
Types
@type t_address() :: <<_::336>> | <<_::160>>
Ethereum address in its hex format with 0x or in its binary format
Examples
"0xdAC17F958D2ee523a2206206994597C13D831ec7"
<<218, 193, 127, 149, 141, 46, 229, 35, 162, 32, 98, 6, 153, 69, 151, 193, 61, 131, 30, 199>>
@type t_bitsizes() ::
256
| 248
| 240
| 232
| 224
| 216
| 208
| 200
| 192
| 184
| 176
| 168
| 160
| 152
| 144
| 136
| 128
| 120
| 112
| 104
| 96
| 88
| 80
| 72
| 64
| 56
| 48
| 40
| 32
| 24
| 16
| 8
@type t_bytesizes() ::
32
| 31
| 30
| 29
| 28
| 27
| 26
| 25
| 24
| 23
| 22
| 21
| 20
| 19
| 18
| 17
| 16
| 15
| 14
| 13
| 12
| 11
| 10
| 9
| 8
| 7
| 6
| 5
| 4
| 3
| 2
| 1
@type t_evm_types() :: {:uint, t_bitsizes()} | {:int, t_bitsizes()} | {:bytes, t_bytesizes()} | :bytes | :string | :address | {:array, t_evm_types()} | {:array, t_evm_types(), non_neg_integer()} | {:tuple, [t_evm_types()]}
@type t_hash() :: <<_::528>>
keccak hash in its hex format with 0x
Examples
"0xd4288c8e733eb71a39fe2e8dd4912ce54d8d26d9874f30309b26b4b071260422"
@type t_pub_key() ::
<<_::520>> | <<_::512>> | <<_::264>> | <<_::1042>> | <<_::1026>> | <<_::530>>
Public key either in its uncompressed format (64 bytes MAY BE prefixed with 0x04) or its compressed format (32 bytes MUST BE prefixed with 0x02 or 0x03)
It can be hex encoded but only with 0x prefix.
Compressed public key MUST have a prefix.
Functions
Returns the default value in the given type if supported.
Examples
iex> Ethers.Types.default(:address)
"0x0000000000000000000000000000000000000000"
iex> Ethers.Types.default({:int, 32})
0
iex> Ethers.Types.default({:uint, 8})
0
iex> Ethers.Types.default({:int, 128})
0
iex> Ethers.Types.default(:string)
""
iex> Ethers.Types.default(:bytes)
""
iex> Ethers.Types.default({:bytes, 8})
<<0, 0, 0, 0, 0, 0, 0, 0>>
@spec matches_type?(term(), t_evm_types()) :: boolean()
Checks if a given data matches a given solidity type
Examples
iex> Ethers.Types.matches_type?(false, :bool)
true
iex> Ethers.Types.matches_type?(200, {:uint, 8})
true
iex> Ethers.Types.matches_type?(400, {:uint, 8})
false
iex> Ethers.Types.matches_type?("0xdAC17F958D2ee523a2206206994597C13D831ec7", :address)
true
Returns the maximum possible value in the given type if supported.
Examples
iex> Ethers.Types.max({:uint, 8})
255
iex> Ethers.Types.max({:int, 8})
127
iex> Ethers.Types.max({:uint, 16})
65535
iex> Ethers.Types.max({:int, 16})
32767
iex> Ethers.Types.max({:uint, 128})
340282366920938463463374607431768211455
iex> Ethers.Types.max({:int, 128})
170141183460469231731687303715884105727
Returns the minimum possible value in the given type if supported.
Examples
iex> Ethers.Types.min({:uint, 8})
0
iex> Ethers.Types.min({:int, 8})
-128
iex> Ethers.Types.min({:uint, 16})
0
iex> Ethers.Types.min({:int, 16})
-32768
iex> Ethers.Types.min({:int, 24})
-8388608
iex> Ethers.Types.min({:int, 128})
-170141183460469231731687303715884105728
Converts EVM data types to typespecs for documentation
@spec typed(term(), t_evm_types() | nil) :: {:typed, term(), term()} | no_return()
Validates and creates typed values to use with functions or events.
Typed values are useful when there are multiple overloads of same function or event and you need to specify one of them to be used.
Also raises with ArgumentError in case value does not match the given type.
Examples
iex> Ethers.Types.typed({:uint, 256}, 5)
{:typed, {:uint, 256}, 5}
iex> Ethers.Types.typed(:bytes, <<0, 1, 2>>)
{:typed, :bytes, <<0, 1, 2>>}