0

I have a very long list of ETH addresses and I need to determine which of them are EOA addresses and which are contracts. is there some fast method to do it? I know that etherscan api has suitable endpoints for that, but it's not so fast. Alchemy does not have isContract or similar, as far as i know. Anyone know how to make such a check faster?

2 Answers 2

1

web3.js provides a getcode function https://web3js.readthedocs.io/en/v1.2.11/web3-eth.html?highlight=getCode#getcode

I think the fastest way would be to run your own node and check if the address has a 0x bytecode or not.

const bytecode = await web3.eth.getCode(address);
  if (bytecode === '0x') {
    console.log('EOA');
  } else {
    console.log('Contract');
  }
0

I would make a Foundry test and run it on a fork, simple and efficient:

test/addresses.t.sol

pragma solidity ^0.8.19;    
import "forge-std/Test.sol";

contract AddressesTest is Test {
    address[] addresses = [
        0x7713974908Be4BEd47172370115e8b1219F4A5f0,
        0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,
        0xDa9CE944a37d218c3302F6B82a094844C6ECEb17
    ];

    function testAddresses() public view {
        for (uint i = 0; i < addresses.length; i++) {
            if (addresses[i].code.length != 0) {
                console.log(addresses[i]);
            }
        }
    }
}

Run it with:

forge test -vv -f https://eth-mainnet.g.alchemy.com/v2/[YOUR_ALCHEMY_APP_KEY]

It will print the contracts found:

Running 1 test for test/addresses.t.sol:AddressesTest
[PASS] testAddresses() (gas: 20890)
Logs:
  0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.