Onchain.Wallet (onchain v0.5.4)

Copy Markdown View Source

Thin convenience layer for wallet-level queries.

Does

Does Not

Functions

FunctionPurpose
classify/2Determine if address is :eoa or :contract
classify!/2Same, raises on error
balance/2Native ETH balance in wei
balance!/2Same, raises on error

API Functions

FunctionArityDescriptionParam Kinds
balance!2Get the native ETH balance of an address in wei. Raises on error.address: value, opts: value
balance2Get the native ETH balance of an address in wei.address: value, opts: value
classify!2Classify an address as EOA or contract. Raises on error.address: value, opts: value
classify2Classify an address as EOA or contract.address: value, opts: value

Summary

Functions

Get the native ETH balance of an address in wei.

Get the native ETH balance of an address in wei. Raises on error.

Classify an address as EOA or contract.

Classify an address as EOA or contract. Raises on error.

Functions

balance(address, opts \\ [])

@spec balance(
  String.t() | binary(),
  keyword()
) :: {:ok, non_neg_integer()} | {:error, term()}

Get the native ETH balance of an address in wei.

Parameters

  • address - Account address as 0x hex string or 20-byte binary (value)
  • opts - Options: :rpc_url, :timeout, :block (default: [], value)

Returns

Balance in wei ({:ok, non_neg_integer} | {:error, term})

# descripex:contract
%{
  params: %{
    opts: %{
      default: [],
      description: "Options: :rpc_url, :timeout, :block",
      kind: :value
    },
    address: %{
      description: "Account address as 0x hex string or 20-byte binary",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, non_neg_integer} | {:error, term}",
    description: "Balance in wei"
  }
}

balance!(address, opts \\ [])

@spec balance!(
  String.t() | binary(),
  keyword()
) :: non_neg_integer()

Get the native ETH balance of an address in wei. Raises on error.

Parameters

  • address - Account address as 0x hex string or 20-byte binary (value)
  • opts - Options: :rpc_url, :timeout, :block (default: [], value)

Returns

Balance in wei (non_neg_integer)

# descripex:contract
%{
  params: %{
    opts: %{
      default: [],
      description: "Options: :rpc_url, :timeout, :block",
      kind: :value
    },
    address: %{
      description: "Account address as 0x hex string or 20-byte binary",
      kind: :value
    }
  },
  returns: %{type: :non_neg_integer, description: "Balance in wei"}
}

classify(address, opts \\ [])

@spec classify(
  String.t() | binary(),
  keyword()
) :: {:ok, :eoa | :contract} | {:error, term()}

Classify an address as EOA or contract.

Parameters

  • address - Account address as 0x hex string or 20-byte binary (value)
  • opts - Options: :rpc_url, :timeout, :block (default: [], value)

Returns

:eoa if no bytecode, :contract if bytecode exists ({:ok, :eoa | :contract} | {:error, term})

# descripex:contract
%{
  params: %{
    opts: %{
      default: [],
      description: "Options: :rpc_url, :timeout, :block",
      kind: :value
    },
    address: %{
      description: "Account address as 0x hex string or 20-byte binary",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, :eoa | :contract} | {:error, term}",
    description: ":eoa if no bytecode, :contract if bytecode exists"
  }
}

classify!(address, opts \\ [])

@spec classify!(
  String.t() | binary(),
  keyword()
) :: :eoa | :contract

Classify an address as EOA or contract. Raises on error.

Parameters

  • address - Account address as 0x hex string or 20-byte binary (value)
  • opts - Options: :rpc_url, :timeout, :block (default: [], value)

Returns

Address type atom (:eoa | :contract)

# descripex:contract
%{
  params: %{
    opts: %{
      default: [],
      description: "Options: :rpc_url, :timeout, :block",
      kind: :value
    },
    address: %{
      description: "Account address as 0x hex string or 20-byte binary",
      kind: :value
    }
  },
  returns: %{type: ":eoa | :contract", description: "Address type atom"}
}