ExWeb3/elixir_ethers

Address "Alternative return types" anti-pattern usage

Closed this issue · 0 comments

Alternative return types anti-pattern

Possible Solutions

  1. Remove action and always return the prepared parameters. User needs to manually call Ethers.call, Ethers.send or Ethers.estimate_gas with the result from the contract functions. The result would look like below. One downside would be losing the ability to have default actions.
iex> ERC20.balance_of("0xADDRESS_HERE") |> Ethers.call()
{:ok, [1000]}
  1. Introduce a Result struct which can hold a transaction hash and the return values at the same time.
iex> ERC20.balance_of("0xADDRESS_HERE")
{:ok, %Result{return_values: [10000], tx_hash: nil}}
  1. Move action out of the opts keyword into a separate function argument with a default action.
iex> ERC20.balance_of("0xADDRESS_HERE")
{:ok, [1000]}

iex> ERC20.balance_of("0xADDRESS_HERE", :prepare)
{:ok, %{data: "0x70a08231...", selector: %ABI.FunctionSelector{...}, to: "0xCONTRACT"}