>

>

3. The hasCode Secret

Wallet or Contract? 🕵️

Last step! Sometimes you have an address, but you don't know if it’s a person or a program 🤖

In VeChainThor, every address has a hasCode flag. If it’s true, it holds bytecode—meaning it’s a smart contract!.

If hasCode is false, it’s just an EOA (Externally Owned Account) controlled by a human with a private key.

Think of it like checking a door: if there's a machine inside (code), it's a factory (contract). If it's empty, it's just a house (wallet) 🏠

// Pull the full state of the address [4]
const account = await thor.accounts.getAccount('0x...');

if (account.hasCode) {
  console.log("It's a smart contract!"); [5]
} else {
  console.log("It's a user wallet!"); [5]
}
// Pull the full state of the address [4]
const account = await thor.accounts.getAccount('0x...');

if (account.hasCode) {
  console.log("It's a smart contract!"); [5]
} else {
  console.log("It's a user wallet!"); [5]
}
// Pull the full state of the address [4]
const account = await thor.accounts.getAccount('0x...');

if (account.hasCode) {
  console.log("It's a smart contract!"); [5]
} else {
  console.log("It's a user wallet!"); [5]
}

You’re getting it! You can even scan whole blocks and check hasCode for every transaction to discover new contracts in bulk.


Common pitfalls to avoid:
Confusing txOrigin with gasPayer: In fee delegation, the address paying for gas might not be the actual deployer.
Assuming every address is a contract: Always check the hasCode flag before trying to filter for deployment logs.