Check if an EVM address is a contract or wallet using thirdweb SDK

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.

 

How to check if a provided address is a contract address or wallet address via the thirdweb SDK (v4)

 
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
 
// instantiate the SDK with a simple chain name or chain id
const sdk = new ThirdwebSDK("polygon");
await sdk.getProvider().getCode(accountAddress)
 

The code for non-contract addresses will be 0x.

Output Scenarios:

  1. For wallet address
    1. Notion image
  1. For contract address
    1. Notion image
       

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?
😞
😐
🤩