forked from smartcontractkit/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into qs-dev3-sdk
- Loading branch information
Showing
91 changed files
with
3,351 additions
and
2,735 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+8.31 KB
(110%)
public/images/chainlink-functions/subscription/addConsumer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+16.6 KB
(120%)
public/images/chainlink-functions/subscription/cancelSubscription.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+9.88 KB
(120%)
public/images/chainlink-functions/subscription/createSubscription.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.04 KB
(110%)
public/images/chainlink-functions/subscription/fundSubscription.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+16.6 KB
(130%)
public/images/chainlink-functions/subscription/removeConsumer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+380 KB
...ages/chainlink-functions/tutorials/automation/automation-register-scheduler.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+78.1 KB
...c/images/chainlink-functions/tutorials/automation/cl-automation-custom-home.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+160 KB
(460%)
public/images/chainlink-functions/tutorials/automation/cl-automation-home.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+159 KB
public/images/chainlink-functions/tutorials/automation/myupkeep-details-custom.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+178 KB
(200%)
public/images/chainlink-functions/tutorials/automation/myupkeep-details.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+90.8 KB
public/images/chainlink-functions/tutorials/subscription/acceptTos.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+94.1 KB
...ages/chainlink-functions/tutorials/subscription/approve-create-subscription.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+207 KB
public/images/chainlink-functions/tutorials/subscription/create-subscription.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+287 KB
public/images/chainlink-functions/tutorials/subscription/frontend-landing.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+158 KB
...images/chainlink-functions/tutorials/subscription/sign-message-tos-metamask.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+77.2 KB
public/images/chainlink-functions/tutorials/subscription/sign-message-tos.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+232 KB
...inlink-functions/tutorials/subscription/subscription-created-add-consumer-2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+117 KB
...hainlink-functions/tutorials/subscription/subscription-created-add-consumer.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+191 KB
...s/chainlink-functions/tutorials/subscription/subscription-created-add-funds.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+154 KB
public/images/chainlink-functions/tutorials/subscription/subscription-created.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+189 KB
...inlink-functions/tutorials/subscription/subscription-details-after-creation.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+193 KB
...s/chainlink-functions/tutorials/subscription/your-subscription-add-consumer.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+93.7 KB
...mages/chainlink-functions/tutorials/subscription/your-subscription-add-fund.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+108 KB
...chainlink-functions/tutorials/subscription/your-subscription-cancel-confirm.jpg
Oops, something went wrong.
Binary file added
BIN
+156 KB
...hainlink-functions/tutorials/subscription/your-subscription-cancel-confirm2.jpg
Oops, something went wrong.
Binary file added
BIN
+207 KB
.../images/chainlink-functions/tutorials/subscription/your-subscription-cancel.jpg
Oops, something went wrong.
Binary file added
BIN
+179 KB
...images/chainlink-functions/tutorials/subscription/your-subscription-cancel2.jpg
Oops, something went wrong.
Binary file added
BIN
+158 KB
...ages/chainlink-functions/tutorials/subscription/your-subscription-cancelled.jpg
Oops, something went wrong.
Binary file added
BIN
+205 KB
...ges/chainlink-functions/tutorials/subscription/your-subscription-click-fund.jpg
Oops, something went wrong.
Binary file added
BIN
+124 KB
...chainlink-functions/tutorials/subscription/your-subscription-consumer-added.jpg
Oops, something went wrong.
Binary file added
BIN
+125 KB
...ainlink-functions/tutorials/subscription/your-subscription-consumer-removed.jpg
Oops, something went wrong.
Binary file added
BIN
+296 KB
.../chainlink-functions/tutorials/subscription/your-subscription-fill-consumer.jpg
Oops, something went wrong.
Binary file added
BIN
+147 KB
.../images/chainlink-functions/tutorials/subscription/your-subscription-funded.jpg
Oops, something went wrong.
Binary file added
BIN
+78.8 KB
...-functions/tutorials/subscription/your-subscription-remove-consumer-confirm.jpg
Oops, something went wrong.
Binary file added
BIN
+149 KB
...functions/tutorials/subscription/your-subscription-remove-consumer-confirm2.jpg
Oops, something went wrong.
Binary file added
BIN
+231 KB
...hainlink-functions/tutorials/subscription/your-subscription-remove-consumer.jpg
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
public/samples/ChainlinkFunctions/AutomatedFunctionsConsumerExample.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.19; | ||
|
||
import {FunctionsClient} from "@chainlink/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsClient.sol"; | ||
import {ConfirmedOwner} from "@chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol"; | ||
|
||
/** | ||
* @title Functions contract used for Automation. | ||
* @notice This contract is a demonstration of using Functions and Automation. | ||
* @notice NOT FOR PRODUCTION USE | ||
*/ | ||
contract AutomatedFunctionsConsumerExample is FunctionsClient, ConfirmedOwner { | ||
address public upkeepContract; | ||
bytes public request; | ||
uint64 public subscriptionId; | ||
uint32 public gasLimit; | ||
bytes32 public jobId; | ||
bytes32 public s_lastRequestId; | ||
bytes public s_lastResponse; | ||
bytes public s_lastError; | ||
|
||
error NotAllowedCaller( | ||
address caller, | ||
address owner, | ||
address automationRegistry | ||
); | ||
error UnexpectedRequestID(bytes32 requestId); | ||
|
||
event Response(bytes32 indexed requestId, bytes response, bytes err); | ||
|
||
constructor( | ||
address router | ||
) FunctionsClient(router) ConfirmedOwner(msg.sender) {} | ||
|
||
/** | ||
* @notice Reverts if called by anyone other than the contract owner or automation registry. | ||
*/ | ||
modifier onlyAllowed() { | ||
if (msg.sender != owner() && msg.sender != upkeepContract) | ||
revert NotAllowedCaller(msg.sender, owner(), upkeepContract); | ||
_; | ||
} | ||
|
||
function setAutomationCronContract( | ||
address _upkeepContract | ||
) external onlyOwner { | ||
upkeepContract = _upkeepContract; | ||
} | ||
|
||
/// @notice Update the request settings | ||
/// @dev Only callable by the owner of the contract | ||
/// @param _request The new encoded CBOR request to be set. The request is encoded off-chain | ||
/// @param _subscriptionId The new subscription ID to be set | ||
/// @param _gasLimit The new gas limit to be set | ||
/// @param _jobId The new job ID to be set | ||
function updateRequest( | ||
bytes memory _request, | ||
uint64 _subscriptionId, | ||
uint32 _gasLimit, | ||
bytes32 _jobId | ||
) external onlyOwner { | ||
request = _request; | ||
subscriptionId = _subscriptionId; | ||
gasLimit = _gasLimit; | ||
jobId = _jobId; | ||
} | ||
|
||
/** | ||
* @notice Send a pre-encoded CBOR request | ||
* @return requestId The ID of the sent request | ||
*/ | ||
function sendRequestCBOR() | ||
external | ||
onlyAllowed | ||
returns (bytes32 requestId) | ||
{ | ||
s_lastRequestId = _sendRequest( | ||
request, | ||
subscriptionId, | ||
gasLimit, | ||
jobId | ||
); | ||
return s_lastRequestId; | ||
} | ||
|
||
/** | ||
* @notice Store latest result/error | ||
* @param requestId The request ID, returned by sendRequest() | ||
* @param response Aggregated response from the user code | ||
* @param err Aggregated error from the user code or from the execution pipeline | ||
* Either response or error parameter will be set, but never both | ||
*/ | ||
function fulfillRequest( | ||
bytes32 requestId, | ||
bytes memory response, | ||
bytes memory err | ||
) internal override { | ||
if (s_lastRequestId != requestId) { | ||
revert UnexpectedRequestID(requestId); | ||
} | ||
s_lastResponse = response; | ||
s_lastError = err; | ||
emit Response(requestId, s_lastResponse, s_lastError); | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
public/samples/ChainlinkFunctions/CustomAutomatedFunctionsConsumerExample.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.19; | ||
|
||
import {FunctionsClient} from "@chainlink/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsClient.sol"; | ||
import {AutomationCompatibleInterface} from "@chainlink/contracts/src/v0.8/automation/AutomationCompatible.sol"; | ||
import {ConfirmedOwner} from "@chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol"; | ||
|
||
/** | ||
* @title Functions contract used for Automation. | ||
* @notice This contract is a demonstration of using Functions and Automation. | ||
* @notice NOT FOR PRODUCTION USE | ||
*/ | ||
contract CustomAutomatedFunctionsConsumerExample is | ||
FunctionsClient, | ||
AutomationCompatibleInterface, | ||
ConfirmedOwner | ||
{ | ||
uint256 public lastBlockNumber; | ||
bytes public request; | ||
uint64 public subscriptionId; | ||
uint32 public gasLimit; | ||
bytes32 public jobId; | ||
bytes32 public s_lastRequestId; | ||
bytes public s_lastResponse; | ||
bytes public s_lastError; | ||
|
||
error UnexpectedRequestID(bytes32 requestId); | ||
|
||
event Response(bytes32 indexed requestId, bytes response, bytes err); | ||
|
||
constructor( | ||
address router | ||
) FunctionsClient(router) ConfirmedOwner(msg.sender) {} | ||
|
||
/** | ||
* @notice Checks if upkeep is needed based on the difference between the current and the last block number. | ||
* @dev This function checks if the current block number has incremented since the last recorded block number and returns a boolean indicating if upkeep is needed. | ||
* @return upkeepNeeded A boolean indicating if upkeep is needed (true if the current block number has incremented since the last recorded block number). | ||
* @return performData An empty bytes value since no additional data is needed for the upkeep in this implementation. | ||
*/ | ||
function checkUpkeep( | ||
bytes calldata /* checkData */ | ||
) | ||
external | ||
view | ||
override | ||
returns (bool upkeepNeeded, bytes memory performData) | ||
{ | ||
upkeepNeeded = block.number - lastBlockNumber > 0; // Check if the current block number has incremented since the last recorded block number | ||
// We don't use the checkData in this example. The checkData is defined when the Upkeep was registered. | ||
return (upkeepNeeded, ""); // Return an empty bytes value for performData | ||
} | ||
|
||
/** | ||
* @notice Send a pre-encoded CBOR request if the current block number has incremented since the last recorded block number. | ||
* @dev We highly recommend revalidating the upkeep in the performUpkeep function. The performData is generated by the Automation Node's call to your checkUpkeep function and is not used in this implementation. | ||
*/ | ||
function performUpkeep(bytes calldata /* performData */) external override { | ||
//We highly recommend revalidating the upkeep in the performUpkeep function | ||
if (block.number - lastBlockNumber > 0) { | ||
s_lastRequestId = _sendRequest( | ||
request, | ||
subscriptionId, | ||
gasLimit, | ||
jobId | ||
); | ||
lastBlockNumber = block.number; | ||
} | ||
// We don't use the performData in this example. The performData is generated by the Automation Node's call to your checkUpkeep function | ||
} | ||
|
||
/// @notice Update the request settings | ||
/// @dev Only callable by the owner of the contract | ||
/// @param _request The new encoded CBOR request to be set. The request is encoded off-chain | ||
/// @param _subscriptionId The new subscription ID to be set | ||
/// @param _gasLimit The new gas limit to be set | ||
/// @param _jobId The new job ID to be set | ||
function updateRequest( | ||
bytes memory _request, | ||
uint64 _subscriptionId, | ||
uint32 _gasLimit, | ||
bytes32 _jobId | ||
) external onlyOwner { | ||
request = _request; | ||
subscriptionId = _subscriptionId; | ||
gasLimit = _gasLimit; | ||
jobId = _jobId; | ||
} | ||
|
||
/** | ||
* @notice Store latest result/error | ||
* @param requestId The request ID, returned by sendRequest() | ||
* @param response Aggregated response from the user code | ||
* @param err Aggregated error from the user code or from the execution pipeline | ||
* Either response or error parameter will be set, but never both | ||
*/ | ||
function fulfillRequest( | ||
bytes32 requestId, | ||
bytes memory response, | ||
bytes memory err | ||
) internal override { | ||
if (s_lastRequestId != requestId) { | ||
revert UnexpectedRequestID(requestId); | ||
} | ||
s_lastResponse = response; | ||
s_lastError = err; | ||
emit Response(requestId, s_lastResponse, s_lastError); | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
public/samples/ChainlinkFunctions/FunctionsConsumerExample.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.19; | ||
|
||
import {FunctionsClient} from "@chainlink/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsClient.sol"; | ||
import {ConfirmedOwner} from "@chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol"; | ||
import {FunctionsRequest} from "@chainlink/contracts/src/v0.8/functions/dev/v1_0_0/libraries/FunctionsRequest.sol"; | ||
|
||
/** | ||
* THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED VALUES FOR CLARITY. | ||
* THIS IS AN EXAMPLE CONTRACT THAT USES UN-AUDITED CODE. | ||
* DO NOT USE THIS CODE IN PRODUCTION. | ||
*/ | ||
contract FunctionsConsumerExample is FunctionsClient, ConfirmedOwner { | ||
using FunctionsRequest for FunctionsRequest.Request; | ||
|
||
bytes32 public s_lastRequestId; | ||
bytes public s_lastResponse; | ||
bytes public s_lastError; | ||
|
||
error UnexpectedRequestID(bytes32 requestId); | ||
|
||
event Response(bytes32 indexed requestId, bytes response, bytes err); | ||
|
||
constructor( | ||
address router | ||
) FunctionsClient(router) ConfirmedOwner(msg.sender) {} | ||
|
||
/** | ||
* @notice Send a simple request | ||
* @param source JavaScript source code | ||
* @param encryptedSecretsUrls Encrypted URLs where to fetch user secrets | ||
* @param donHostedSecretsSlotID Don hosted secrets slotId | ||
* @param donHostedSecretsVersion Don hosted secrets version | ||
* @param args List of arguments accessible from within the source code | ||
* @param bytesArgs Array of bytes arguments, represented as hex strings | ||
* @param subscriptionId Billing ID | ||
*/ | ||
function sendRequest( | ||
string memory source, | ||
bytes memory encryptedSecretsUrls, | ||
uint8 donHostedSecretsSlotID, | ||
uint64 donHostedSecretsVersion, | ||
string[] memory args, | ||
bytes[] memory bytesArgs, | ||
uint64 subscriptionId, | ||
uint32 gasLimit, | ||
bytes32 jobId | ||
) external onlyOwner returns (bytes32 requestId) { | ||
FunctionsRequest.Request memory req; | ||
req.initializeRequestForInlineJavaScript(source); | ||
if (encryptedSecretsUrls.length > 0) | ||
req.addSecretsReference(encryptedSecretsUrls); | ||
else if (donHostedSecretsVersion > 0) { | ||
req.addDONHostedSecrets( | ||
donHostedSecretsSlotID, | ||
donHostedSecretsVersion | ||
); | ||
} | ||
if (args.length > 0) req.setArgs(args); | ||
if (bytesArgs.length > 0) req.setBytesArgs(bytesArgs); | ||
s_lastRequestId = _sendRequest( | ||
req.encodeCBOR(), | ||
subscriptionId, | ||
gasLimit, | ||
jobId | ||
); | ||
return s_lastRequestId; | ||
} | ||
|
||
/** | ||
* @notice Send a pre-encoded CBOR request | ||
* @param request CBOR-encoded request data | ||
* @param subscriptionId Billing ID | ||
* @param gasLimit The maximum amount of gas the request can consume | ||
* @param jobId ID of the job to be invoked | ||
* @return requestId The ID of the sent request | ||
*/ | ||
function sendRequestCBOR( | ||
bytes memory request, | ||
uint64 subscriptionId, | ||
uint32 gasLimit, | ||
bytes32 jobId | ||
) external onlyOwner returns (bytes32 requestId) { | ||
s_lastRequestId = _sendRequest( | ||
request, | ||
subscriptionId, | ||
gasLimit, | ||
jobId | ||
); | ||
return s_lastRequestId; | ||
} | ||
|
||
/** | ||
* @notice Store latest result/error | ||
* @param requestId The request ID, returned by sendRequest() | ||
* @param response Aggregated response from the user code | ||
* @param err Aggregated error from the user code or from the execution pipeline | ||
* Either response or error parameter will be set, but never both | ||
*/ | ||
function fulfillRequest( | ||
bytes32 requestId, | ||
bytes memory response, | ||
bytes memory err | ||
) internal override { | ||
if (s_lastRequestId != requestId) { | ||
revert UnexpectedRequestID(requestId); | ||
} | ||
s_lastResponse = response; | ||
s_lastError = err; | ||
emit Response(requestId, s_lastResponse, s_lastError); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.