I am writing solidity tests . I am using JS for testing . Is there any method in web3js library to know that a certain address is a contract's address or not ?
1 Answer
you can use getCode
function as below REFERENCE
const code = await web3.eth.getCode("0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8");
//check If the address is a contract address
const IsAContractAddress = !!(code?.length > 0)
// check If the address is an Externally owned account
const IsEOA= !(code?.length > 0)
If there is a code(length >0 ), it ensures that it is an contract address.