View Source Ethers.Utils (Ethers v0.0.1-dev)

Utilities for interacting with ethereum blockchain

Link to this section Summary

Functions

Convert WEI to ETH

Decode from hex with (or without) 0x prefix.

Encode to hex with 0x prefix.

Converts a hexadecimal integer to integer form

Converts integer to its hexadecimal form

Adds gas limit estimation to the parameters if not already exists

Converts ETH to WEI

Link to this section Functions

@spec from_wei(non_neg_integer()) :: float()

Convert WEI to ETH

examples

Examples

iex> Ethers.Utils.from_wei(1000000000000000000)
1.0

iex> Ethers.Utils.from_wei(3140000000000000000)
3.14
@spec hex_decode(String.t()) :: {:ok, binary()}

Decode from hex with (or without) 0x prefix.

examples

Examples

iex> Ethers.Utils.hex_decode("0x6574686572735f6578")
{:ok, "ethers_ex"}

iex> Ethers.Utils.hex_decode("6574686572735f6578")
{:ok, "ethers_ex"}
Link to this function

hex_encode(bin, include_prefix \\ true)

View Source

Encode to hex with 0x prefix.

examples

Examples

iex> Ethers.Utils.hex_encode("ethers_ex")
"0x6574686572735f6578"
@spec hex_to_integer(String.t()) :: {:ok, integer()} | {:error, :invalid_hex}

Converts a hexadecimal integer to integer form

examples

Examples

iex> Ethers.Utils.hex_to_integer("0x11111")
{:ok, 69905}
@spec integer_to_hex(integer()) :: String.t()

Converts integer to its hexadecimal form

examples

Examples

iex> Ethers.Utils.integer_to_hex(69905)
"0x11111"
Link to this function

maybe_add_gas_limit(params, opts \\ [])

View Source

Adds gas limit estimation to the parameters if not already exists

@spec to_wei(number()) :: non_neg_integer()

Converts ETH to WEI

examples

Examples

iex> Ethers.Utils.to_wei(1)
1000000000000000000

iex> Ethers.Utils.to_wei(3.14)
3140000000000000000