I am working on a project that includes Chainlink Functions (for off-chain API calls) and CCIP (to transfer tokens cross-chain).

My project includes 3 main contracts:

  1. FunctionConsumer.sol: Chainlink Functions contract
  2. Router.sol: CCIP contract to transfer tokens
  3. CCHarvest.sol: A vault for users to deposit tokens.

I want that whenever I call the sendRequest() in FunctionConsumer contract it should make the API call get the data and callback fulfillRequest(). Till now everything works fine as expected.

The fulfillRequest() then should call the CCHarvest contract with a function called routerWithdraw() which will transfer 80% of it's token to the Router contract. After that control will comeback to FunctionConsumer contract and call the Router contract's transferTokensPayNative() which will transfer the tokens from one network to another network.

I have tested that the CCHarvest contract is working as expected with the Router contract when called manually but it doesn't work when the FunctionConsumer contract calls the Router's fulfillRequest() as you can see in the internal transactions here. It shows it ran out of gas even though I have already funded the Router contract with enough Matic tokens.

I have been stuck with this issue for a day now and I am not getting why this is not working. Why FunctionConsumer contract is not able to call the Router contract successfully?

I have gone through the official docs of the chainlink but am still not able to find an appropriate solution. Does anyone here know what I am doing wrong? It will be of great help.


1 Answer 1


Chainlink puts a maximum amount of gas that can be spent in the fulfill request function. This link shows its 300000 gas. So I believe your function fails because of that.

You should use the fulfill request only to save data about the request. Then you need to make another transaction that picks up these data and calls CCHarvest.

It shows it ran out of gas even though I have already funded the Router contract with enough Matic tokens.

Gas payments don't come from the contract, but they come from the wallet that started the transaction. So you shouldn't add Matic to a contract to pay for gas.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.