honestnft_utils.chain

honestnft_utils.chain.get_contract_abi(address, blockchain='ethereum')

Given a contract address, return the contract ABI from Etherscan. If the contract is unverified, the ABI will be partially constructed according to ERC165.

Parameters
  • address (str) – The contract address

  • blockchain (str) – The blockchain to use. Options are: - arbitrum - avalanche - binance - ethereum - fantom - optimism - polygon

Return type

list

Returns

The contract ABI

honestnft_utils.chain.get_contract(address, abi, blockchain='ethereum')

Given a contract address and ABI, return a web3 Contract object.

If the given address turns out be a proxy contract, the returned contract will be the implementation contract and the corresponding ABI.

Parameters
  • address (str) – The contract address

  • abi (list) – The contract ABI

  • blockchain (str) – The blockchain to use. Options are: - arbitrum - avalanche - binance - ethereum - fantom - optimism - polygon

Return type

Tuple[list, Contract]

Returns

A tuple of the contract ABI and the contract object

honestnft_utils.chain.get_contract_function(contract, func_name, abi)

Given a contract object, a function name and a contract ABI, return the contract function.

Parameters
  • contract (Contract) – The contract object

  • func_name (str) – The function name

  • abi (list) – The contract ABI

Returns

The contract function object

honestnft_utils.chain.get_token_uri_from_contract(contract, token_id, uri_func, abi, format_uri=False)

Given a contract, token ID, and URI function name, return the token URI. Optionally, format the URI.

Parameters
  • contract (Contract) – The contract object

  • token_id (int) – The token ID

  • uri_func (str) – The URI function name

  • abi (list) – The contract ABI

  • format_uri (bool) – Whether to format the URI

Return type

str

Returns

The token URI

honestnft_utils.chain.get_token_uri_from_contract_batch(contract, token_ids, function_signature, abi, blockchain='ethereum', format_uri=False)

Given a contract, token IDs, and function signature, return the token URIs. Optionally, format the URI.

Parameters
  • contract (Contract) – The contract object

  • token_ids (List[int]) – A list of token IDs

  • function_signature (str) – The function signature

  • abi (list) – The contract ABI

  • blockchain (str) – The blockchain to use. Options are: - ethereum - arbitrum - avalanche - binance - fantom - optimism - polygon

  • format_uri (bool) – Whether to format the URI

Return type

Dict[int, str]

Returns

A dictionary of token IDs and URIs

honestnft_utils.chain.get_lower_token_id(contract, uri_func, abi)

Given a contract, URI function name, and ABI, this function tries to infer the lowest token ID on-chain.

Parameters
  • contract (Contract) – The contract object

  • uri_func (str) – The URI function name

  • abi (list) – The contract ABI

Return type

int

Returns

The lower token ID

honestnft_utils.chain.get_base_uri(contract, abi)

Given a contract and ABI, return the base URI as found on-chain.

Parameters
  • contract (Contract) – The contract object

  • abi (list) – The contract ABI

Return type

str

Returns

The base URI

honestnft_utils.chain.get_function_signature(func_name, abi)

Given a function name and an ABI, return the function signature e.g. get_function_signature(“tokenURI”, abi) => “tokenURI(uint256)(string)”

Parameters
  • func_name (str) – The function name

  • abi (list) – The contract ABI

Return type

str

Returns

The function signature

honestnft_utils.chain.get_token_standard(contract)

Given a contract object, tries to infer the token standard on-chain. eg. get_token_standard(contract) => “ERC-721”

Parameters

contract (Contract) – The contract object

Return type

str

Returns

The ERC standard

honestnft_utils.chain.format_metadata_uri(URI)

Given a metadata URI, return the formatted IPFS URI if it is an IPFS URI, otherwise return the supplied URI.

Parameters

URI (str) – The metadata URI

Return type

str

Returns

The formatted URI