Given an address, from a web application I'm attempting to determine if there's a contract deployed at the address. There are some ways to do this with etherscan or other block explorer APIs, but I'm curious if this is possible directly from a node (perhaps from a node with instrumentation or debugging turned on?)
You can use the
getCode API. If that call returns
0x, there is no contract at that address. If it returns anything other than
0x, there is a contract at that address.
As an example:
web3.eth.getCode("0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8") .then(console.log); > "0x600160008035811a818181146012578301005b601b6001356025565b8060005260206000f25b600060078202905091905056"