dAppBooster
    Preparing search index...

    Function detectAddressType

    • Determines whether the provided address is a contract or an Externally Owned Account (EOA).

      The function queries the blockchain to check if there is bytecode deployed at the given address. If bytecode exists, the address is classified as a contract. Otherwise, it's considered an EOA.

      Parameters

      • publicClient: {}

        The Viem public client instance

      • address: `0x${string}`

        The blockchain address to check

      Returns Promise<{ data: HashData; type: HashType }>

      Object containing the address type ('contract' or 'EOA') and the address itself

      // For a contract address
      const client = createPublicClientInstance(mainnet);
      const result = await detectAddressType(client, '0x6B175474E89094C44Da98b954EedeAC495271d0F');
      console.log(result); // { type: 'contract', data: '0x6B175474E89094C44Da98b954EedeAC495271d0F' }
      // For a wallet address (EOA)
      const result = await detectAddressType(client, '0x71C7656EC7ab88b098defB751B7401B5f6d8976F');
      console.log(result); // { type: 'EOA', data: '0x71C7656EC7ab88b098defB751B7401B5f6d8976F' }