I have an api which requires verification of transaction hash and input parameters and while working on it, I found that my abi file does not contain function signature. If i create contract instance and then try it works to decode input parameters
(async()=>{
/*
Todo: TransactionHash is 64-character hexadecimal starting with 0x while wallet and contract adddress are 40-character starting with 0x
Todo: If getTransactionHash give null i.e either transaction hash does not exist or it is in pending state
Todo: the blockNumber field is null, it means that the transaction has not been included in a block and is still pending.
If the blockNumber field is a number, it indicates that the transaction has been confirmed and has been included in a block at that block height.
*/
const WEB3 = require('web3')
const Contract_ABI = require('./config/palm/abi-ethereum-ERC1155')
const web3 = new WEB3(new WEB3.providers.HttpProvider('https://goerli.infura.io/v3/xxxxxxxxxxxx'))
const contract = new web3.eth.Contract(Contract_ABI.abi, '0x7484Af0C27905eaa8ef4f7f1ffB67224bEF5046c');
const transactionHash = '0x766aaab5b0d0d0550ca056deabbf2bdc407c86174bf03a21c1e50dfee64ac22d'
const transaction = await web3.eth.getTransaction(transactionHash)
console.log({transaction})
if (transaction===null || transaction.blockNumber === null){
throw new Error('Invalid Transaction Hash')
}
const inputData = transaction.input;
const contractABI = Contract_ABI.abi; // ABI of the contract being called
const functionSignature = inputData.substr(0, 10);
const functionArguments = inputData.substr(10);
const inputsArray = contractABI.find(abi => abi.signature === functionSignature);
const decodedArguments = web3.eth.abi.decodeParameters(inputsArray.inputs, functionArguments);
console.log({decodedArguments})
})()
The above code works only if i create contract instance
const contract = new web3.eth.Contract(Contract_ABI.abi, '0x7484Af0C27905eaa8ef4f7f1ffB67224bEF5046c');
My question is how to configure hardhat or any plugin we have to generate abi containing function signuature also
usually npx hardhat compile
gives you the contract abi with function signture