Finding out if a function exists in a contract without having abi

Hi. Can anyone assist me in figuring out a good method in finding out if a function exists in a smart contract without initially having the abi (only the contractAddress). I found a solution online using web3.js however it does not seem to work (see below).

const contractCode = await web3.eth.getCode(tokenAddress)
            console.log(contractCode)
            const contractAbi = await web3.eth.abi.decodeParameters([], contractCode)
            console.log(contractAbi)
            const myContract = new web3.eth.Contract(contractAbi, tokenAddress)

            await myContract.methods.myFunction().call()

it looks like it assume that the code is available for that contract, that also means that the abi is available for that contract

if you have an emitted event for that contract address and you can see it in a block explorer, if the event is a simple one then you could infer the abi from the emitted event

I need it to happen programmatically

I tried it with a contract that is public and it still did not work.

Also the assumption that the code is public is more than usually the assumption that it is not spam so it ends up sorting itself out

If you want to make it programmatically, and you already have the function abi, then you can try to call it with that contract address to see if you get a valid result, assuming that it is a read only function.