How to check if a provided address is a contract address or wallet address

Understanding addresses is vital for efficient navigation within the ecosystem. Contract addresses signify deployed smart contracts, containing executable code for dApps, while wallet addresses represent accounts controlled by external entities. Distinguishing between these types is crucial for security, transaction processing, and smart contract development. The thirdweb SDK provides a simple solution for identifying address types, ensuring secure transactions and smooth interactions across the blockchain.

 
import { getBytecode, getContract } from "thirdweb/contract";
import { ethereum } from "thirdweb/chains";
import { createThirdwebClient } from "thirdweb";

const evmAddressToCheck = "0x...";
const chainOfYourChoice = ethereum; // we use ethereum as the chain in this example
export const client = createThirdwebClient({
  clientId: "your-client-id",
});
const contract = getContract({
  address: evmAddressToCheck,
  chain: chainOfYourChoice,
  client: client,
});
...
const bytecode = await getByteCode(contract);

console.log(bytecode); // either "0x" or "0x......abcxyz....."

const isWalletAddress = bytecode === "0x";
const isContractAddress = bytecode !== "0x";
 

That's it! It's that simple to check if an address is a wallet or contract address using the thirdweb SDK.

 

 

Can’t get this working? If you’ve followed the above and still have issues, contact our support team for help.

Did this answer your question?
😞
😐
🤩