0

for example, I write a custom solidity interface

interface IMyInterface is IERC165{
}

Is there a way to find all smart contracts which is IMyInterface compatible deployed on the net?

It could be useful in some scenario like:

  • If I want to build a NFT marketplace, I can use this way to find all NFT collections to query all IERC721

There are some existing apis for NFT collections like

But I can not find any api which supports like non-ERC contracts

Goxy
  • 34
  • 1

2 Answers2

1

I find out that it's impossible to complete this

The code is compiled as bytecode in EVM.

The NFT marketplace listen to IERC721 Transfer event to discover NFTs

See https://stackoverflow.com/a/72430527/15527691

Goxy
  • 34
  • 1
1

Actually you can check if the contract's bytecode fulfills the interface.

  • get the opcodes from the bytecode
  • filter by PUSH4 and data - the method signatures.
  • get method signatures from your interface
  • check if all method signatures can be found in opcodes data

The implementation example from 0xWeb/evm::checkInterfaceOf and usage:

const contractAddress = `0x....`;
const bytecode = await web3.eth.getCode(contractAddress);
const evm = new EVM(bytecode);
const { ok, missing } = await evm.checkInterfaceOf([
    'upgradeTo(address)',
    'implementation()',
]);

Another question is how to get all the contracts.

  • index the transaction to find out the contract creation transactions and create2 calls from trace logs. This is the most difficult part.
  • index contracts, as you mentioned, by fetching the event logs by some specific topic.
tenbits
  • 7,568
  • 5
  • 34
  • 53