How do i make sure the callback function of a call to a chainlink node isn't called by anyone else?

I understand I need to make it public so the node can call it back but I want to protect it from anyone else calling it?

1 Answer 1


Here is a simple example where we limited access to the _callback() Now it can only be called by the address specified in the variable ChainlinkAddress.

Hope it helps;

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.3;

contract SmartContract {

    // Chainlink node account/address 
    address ChainlinkAddress;

    modifier onlyChainlink() {
        require(msg.sender == ChainlinkAddress);

    // It's advised to add onlyOwner modifeir to this function, so others can't modify the ChainlinkAddress;
    function setChainlinkAddress(address addr) external {
            ChainlinkAddress = addr;

    function _callback() public view onlyChainlink returns(bool sucess) {
       //do something
        sucess = true;


NOTE:To use only owner, I recommend OpenZeppelin Ownable library to implement such functionality.

  • But if I add onlyOwner then the chainlink node won't be able to call it back with the response from the get query I made Commented Dec 17, 2022 at 13:01
  • What is the address/account your chainlink node is using to call it?
    – Sky
    Commented Dec 17, 2022 at 14:00
  • Why does it matter? I'm using the chainlink testnet node for testing for now Commented Dec 17, 2022 at 18:56
  • It's possible to write a custom modified that will allow only that address (chainlink address) to call the function. For example, onlyChainlink modified.
    – Sky
    Commented Dec 17, 2022 at 20:38
  • 1
    I think I understand. So I need to add a condition that only the chainlink oracle node that I am calling can call the callback function. Do you have an example of something like this? And thank you very much for the help!! Commented Dec 17, 2022 at 21:45

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.