Accounts are how we identify who owns or controls assets on a blockchain. There are two main types: Externally Owned Accounts (EOA) controlled by people, and Contract Accounts controlled by code.
Accounts (EOA vs contract accounts) in Blockchain / Solidity
EOA: Controlled by a private key, can send transactions. Contract Account: Has code, executes functions when called.
EOAs require a private key to sign transactions.
Contract accounts cannot initiate transactions themselves; they respond to calls.
// Example of an EOA sending Ether
web3.eth.sendTransaction({from: eoaAddress, to: recipientAddress, value: amount});// Deploying a contract account
const contract = new web3.eth.Contract(abi);
contract.deploy({data: bytecode}).send({from: eoaAddress});// Calling a function on a contract account
contract.methods.myFunction().send({from: eoaAddress});This program connects to the Ethereum blockchain, checks the balance of an EOA, and detects if a contract account exists at another address by checking for code.
// Simple example in JavaScript using web3.js async function example() { const Web3 = require('web3'); const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_PROJECT_ID'); // EOA address example const eoaAddress = '0xYourEOAAddress'; // Contract account address example const contractAddress = '0xYourContractAddress'; // Check balance of EOA const eoaBalance = await web3.eth.getBalance(eoaAddress); console.log(`EOA balance: ${web3.utils.fromWei(eoaBalance, 'ether')} ETH`); // Check if contract code exists at contract address const code = await web3.eth.getCode(contractAddress); if (code === '0x' || code === '0x0') { console.log('No contract found at this address.'); } else { console.log('Contract account detected at this address.'); } } example();
EOAs are controlled by private keys and can send transactions directly.
Contract accounts contain code and can only act when triggered by transactions from EOAs or other contracts.
Checking if an address is a contract can be done by checking if code exists at that address.
There are two main account types: EOAs (people) and contract accounts (code).
EOAs send transactions; contract accounts run code when called.
Understanding the difference helps you interact correctly with blockchain applications.