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
Name | Type | Description |
---|---|---|
[0] | bytes | publicKey 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
Name | Type | Description |
---|---|---|
req | struct Functions.Request | The initialized Functions.Request |
subscriptionId | uint64 | The subscription ID |
gasLimit | uint32 | gas limit for the fulfillment callback |
gasPrice | uint256 |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint96 | billedCost 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
Name | Type | Description |
---|---|---|
req | struct Functions.Request | The initialized Functions.Request |
subscriptionId | uint64 | The subscription ID |
gasLimit | uint32 | gas limit for the fulfillment callback |
Return Values
Name | Type | Description |
---|---|---|
[0] | bytes32 | requestId The generated request ID |
fulfillRequest
function fulfillRequest(bytes32 requestId, bytes response, bytes err) internal virtual
User defined function to handle a response
Parameters
Name | Type | Description |
---|---|---|
requestId | bytes32 | The request ID, returned by sendRequest() |
response | bytes | Aggregated response from the user code |
err | bytes | Aggregated 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
Name | Type | Description |
---|---|---|
requestId | bytes32 | The requestId returned by FunctionsClient.sendRequest(). |
response | bytes | Aggregated response from the user code. |
err | bytes | Aggregated 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
Name | Type | Description |
---|---|---|
oracle | address | The address of Functions Oracle contract |
getChainlinkOracleAddress
function getChainlinkOracleAddress() internal view returns (address)
Gets the stored address of the oracle contract
Return Values
Name | Type | Description |
---|---|---|
[0] | address | The 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
Name | Type | Description |
---|---|---|
oracleAddress | address | The address of the oracle contract that will fulfill the request |
requestId | bytes32 | The 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
Name | Type | Description |
---|---|---|
requestId | bytes32 | The request ID for fulfillment |
notPendingRequest
modifier notPendingRequest(bytes32 requestId)
Reverts if the request is already pending
Parameters
Name | Type | Description |
---|---|---|
requestId | bytes32 | The request ID for fulfillment |