one of methods is a search method in Contract code:
For realizte this its need ABI
const ABIERC721 = [
{
inputs: [
{
internalType: "uint256",
name: "tokenId",
type: "uint256",
},
],
name: "tokenURI",
outputs: [
{
internalType: "string",
name: "",
type: "string",
},
],
stateMutability: "view",
type: "function",
},
];
/*
part of code of contract
0x608060405234801561001057600080fd5b50600436106102e25760003560e
01c806370a0823111610188578063ad2d0ddd116100e4578063d5a06d4c1161
0092578063d5a06d4c14610668578063e00aab4b146106af578063e92a89f61
46106c2578063e985e9c5146106d5578063f0cdc499146106e8578063f2fde3
8b146106fb578063fe2e1f581461070e57600080fd5b8063ad2d0ddd1461060
f578063b0fe87c914610622578063b88d4fde14610635578063b9c4d9fb1461
0648578063bb3bafd614610668578063***c87b56dd***14610689578063...
--------
*/
const contractCode = await web3.eth.getCode(contractAddress);
/*
{
tokenURI: [Function: bound _createTxObject],
'0xc87b56dd': [Function: bound _createTxObject],
'tokenURI(uint256)': [Function: bound _createTxObject]
}
*/
const contract = new web3.eth.Contract(ABIERC721, contractAddress);
//return array with hexed names like ['0xc87b56dd']
const getHexName = Object.keys(contract.methods).filter((item) =>
/0x/gim.test(item)
);
//create regexp removing '0x' and find it on contract code
const isExistMethod = new RegExp(
getHexName.join("|").replace("0x", ""),
"gim"
).test(contractCode);
Or without ABI:
const methodSha = web3.utils.sha3("tokenURI(uint256)");
const methodToCheck = methodSha.substring(2,10); //c87b56dd
const contractCode = await web3.eth.getCode(contractAddress);
//create regexp removing '0x' and find it on contract code
const isExistMethod = new RegExp(methodToCheck,"gim").test(contractCode);
Regads