I'm facing challenges with Chainlink in my project, specifically with transaction failures and log erasure when calling APIs from a Chainlink consumer contract.
Issue: Transactions revert when using Chainlink to call APIs, erasing all logs and impeding debugging.
Specific Problem: Success with GET API calls, but POST method (payment API) returns a bad request.
Error Message: "InternalServerErrorException: execution reverted (unknown custom error) (action="estimateGas")".
Documentation Gap: Inadequate guidance on making POST requests via Chainlink Functions.
Seeking advice on resolving these issues, especially for executing POST API calls and retaining logs for debugging.
This below code snippet is where I initiate transaction
**../requestSource.js**
const apiResponse = await Functions.makeHttpRequest({
url: 'http://localhost:4000/payment/transfer',
method: 'POST',
data: {
jobProposalId: args[0],
amount: args[1],
milestoneOrder: args[2],
},
});
console.log(JSON.stringify(apiResponse));
if (apiResponse.error) {
throw Error(apiResponse.error);
}
const { data } = apiResponse;
return Functions.encodeString(data);
const source = readFileSync(
path.join(__dirname, '../requestSource.js'),
).toString();
const args = ['65ad521cfa8f23xxxxxxx', '375', '1'];
const response = await simulateScript({
source: source,
args: args,
bytesArgs: [], // bytesArgs - arguments can be encoded off-chain to bytes.
secrets: {}, // no secrets in this example
});
Simulating this with POST request throws a BadRequest.
Even if the simulation response is successful or not the contract method invocation fails with the error - "InternalServerErrorException: execution reverted (unknown custom error) (action="estimateGas")"
const tx = await contract.markMilestoneCompleted(
updateContractDto.contractAddress,
updateContractDto.milestoneId,
subscriptionId,
donId,
source,
args,
gasLimit,
);
await tx.wait();
Expected behaviour is marking the milestone completed updating the contract and initiation of the payment that should not return any errors.
By the error message, the problem is from interacting with the deployed contract. It seems related to the CALL_EXCEPTION in estimateGas, but hard to confirm as Chainlink doesn't return the complete error message.
If it was a CALL_EXCEPTION in estimateGas, see this for resolution.