0

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 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.