View Source Ethers.Contracts.ERC165 behaviour (Ethers v0.4.5)

ERC-165 Standard Interface Detection

More info: https://eips.ethereum.org/EIPS/eip-165

Modules as Interface IDs

Contract modules can opt to implement EIP-165 behaviour so that their name can be used directly with the supports_interface/1 function in this module. See below example:

defmodule MyEIP165CompatibleContract do
  use Ethers.Contract, abi: ...
  @behaviour Ethers.Contracts.ERC165

  @impl true
  def erc165_interface_id, do: Ethers.Utils.hex_decode("[interface_id]")
end

Now module name can be used instead of interface_id and will have the same result.

iex> Ethers.Contracts.ERC165.supports_interface("[interface_id]") ==
  Ethers.Contracts.ERC165.supports_interface(MyEIP165CompatibleContract)
true

Summary

Functions

Default address of the contract. Returns nil if not specified.

Prepares supportsInterface(bytes4 interfaceId) call parameters on the contract.

Callbacks

@callback erc165_interface_id() :: <<_::32>>

Functions

@spec __default_address__() :: nil

Default address of the contract. Returns nil if not specified.

To specify a default address see Ethers.Contract

Link to this function

supports_interface(module_or_interface_id)

View Source
@spec supports_interface(<<_::32>> | atom()) :: Ethers.TxData.t()

Prepares supportsInterface(bytes4 interfaceId) call parameters on the contract.

This function also accepts a module that implements the ERC165 behaviour as input. Example:

iex> Ethers.Contracts.ERC165.supports_interface(Ethers.Contracts.ERC721)
#Ethers.TxData<function supportsInterface(...)>

This function should only be called for result and never in a transaction on its own. (Use Ethers.call/2)

State mutability: view

Function Parameter Types

  • interfaceId: {:bytes, 4}

Return Types (when called with Ethers.call/2)

  • :bool