NEW

Join us at SmartCon 2023—where Web3 gets real. Get your ticket.

FunctionsClient API Reference

Consumer contract developers inherit FunctionsClient to create Chainlink Functions requests.

Events

RequestSent

event RequestSent(bytes32 id)

RequestFulfilled

event RequestFulfilled(bytes32 id)

Errors

SenderIsNotRegistry

error SenderIsNotRegistry()

RequestIsAlreadyPending

error RequestIsAlreadyPending()

RequestIsNotPending

error RequestIsNotPending()

Methods

constructor

constructor(address oracle)

getDONPublicKey

function getDONPublicKey() external view returns (bytes)

Returns the DON's secp256k1 public key used to encrypt secrets

All Oracles nodes have the corresponding private key needed to decrypt the secrets encrypted with the public key

Return Values

NameTypeDescription
[0]bytespublicKey DON's public key

estimateCost

function estimateCost(struct Functions.Request req, uint64 subscriptionId, uint32 gasLimit, uint256 gasPrice) public view returns (uint96)

Estimate the total cost that will be charged to a subscription to make a request: gas re-imbursement, plus DON fee, plus Registry fee

Parameters

NameTypeDescription
reqstruct Functions.RequestThe initialized Functions.Request
subscriptionIduint64The subscription ID
gasLimituint32gas limit for the fulfillment callback
gasPriceuint256

Return Values

NameTypeDescription
[0]uint96billedCost Cost in Juels (1e18) of LINK

sendRequest

function sendRequest(struct Functions.Request req, uint64 subscriptionId, uint32 gasLimit) internal returns (bytes32)

Sends a Chainlink Functions request to the stored oracle address

Parameters

NameTypeDescription
reqstruct Functions.RequestThe initialized Functions.Request
subscriptionIduint64The subscription ID
gasLimituint32gas limit for the fulfillment callback

Return Values

NameTypeDescription
[0]bytes32requestId The generated request ID

fulfillRequest

function fulfillRequest(bytes32 requestId, bytes response, bytes err) internal virtual

User defined function to handle a response

Parameters

NameTypeDescription
requestIdbytes32The request ID, returned by sendRequest()
responsebytesAggregated response from the user code
errbytesAggregated error from the user code or from the execution pipeline Either response or error parameter will be set, but never both

handleOracleFulfillment

function handleOracleFulfillment(bytes32 requestId, bytes response, bytes err) external

Chainlink Functions response handler called by the designated transmitter node in an OCR round.

Parameters

NameTypeDescription
requestIdbytes32The requestId returned by FunctionsClient.sendRequest().
responsebytesAggregated response from the user code.
errbytesAggregated error either from the user code or from the execution pipeline. Either response or error parameter will be set, but never both.

setOracle

function setOracle(address oracle) internal

Sets the stored Oracle address

Parameters

NameTypeDescription
oracleaddressThe address of Functions Oracle contract

getChainlinkOracleAddress

function getChainlinkOracleAddress() internal view returns (address)

Gets the stored address of the oracle contract

Return Values

NameTypeDescription
[0]addressThe address of the oracle contract

addExternalRequest

function addExternalRequest(address oracleAddress, bytes32 requestId) internal

Allows for a request which was created on another contract to be fulfilled on this contract

Parameters

NameTypeDescription
oracleAddressaddressThe address of the oracle contract that will fulfill the request
requestIdbytes32The request ID used for the response

Modifiers

recordChainlinkFulfillment

modifier recordChainlinkFulfillment(bytes32 requestId)

Reverts if the sender is not the oracle that serviced the request. Emits RequestFulfilled event.

Parameters

NameTypeDescription
requestIdbytes32The request ID for fulfillment

notPendingRequest

modifier notPendingRequest(bytes32 requestId)

Reverts if the request is already pending

Parameters

NameTypeDescription
requestIdbytes32The request ID for fulfillment

Stay updated on the latest Chainlink news