FunctionsRequest library API Reference
Consumer contract developers use the FunctionsRequest library to build their requests.
Types and Constants
REQUEST_DATA_VERSION
uint16 REQUEST_DATA_VERSION
DEFAULT_BUFFER_SIZE
uint256 DEFAULT_BUFFER_SIZE
Location
enum Location {
Inline,
Remote,
DONHosted
}
| Value | Description |
|---|---|
Inline | Provided within the Request. |
Remote | Hosted through a remote location that can be accessed through a provided URL. |
DONHosted | Hosted on the DON's storage. |
CodeLanguage
enum CodeLanguage {
JavaScript
}
Request
struct Request {
enum FunctionsRequest.Location codeLocation;
enum FunctionsRequest.Location secretsLocation;
enum FunctionsRequest.CodeLanguage language;
string source;
bytes encryptedSecretsReference;
string[] args;
bytes[] bytesArgs;
}
| Field | Type | Description |
|---|---|---|
codeLocation | Location | The location of the source code that will be executed on each node in the DON. |
secretsLocation | Location | The location of secrets that will be passed into the source code. *Only Remote secrets are supported. |
language | CodeLanguage | The coding language that the source code is written in. |
source | string | Raw source code for Request.codeLocation of Location.Inline, URL for Request.codeLocation of Location.Remote, or slot decimal number for Request.codeLocation of Location.DONHosted. |
encryptedSecretsReference | bytes | Encrypted URLs for Request.secretsLocation of Location.Remote, or CBOR encoded slotid+version for Request.secretsLocation of Location.DONHosted. |
args | string[] | String arguments that will be passed into the source code. |
bytesArgs | bytes[] | Bytes arguments that will be passed into the source code. |
Errors
EmptySource
error EmptySource()
EmptySecrets
error EmptySecrets()
EmptyArgs
error EmptyArgs()
NoInlineSecrets
error NoInlineSecrets()
Functions
encodeCBOR
function encodeCBOR(struct FunctionsRequest.Request self) internal pure returns (bytes)
Encodes a Request to CBOR encoded bytes
Parameters
| Name | Type | Description |
|---|---|---|
| self | struct FunctionsRequest.Request | The request to encode |
Return values
| Name | Type | Description |
|---|---|---|
| [0] | bytes | CBOR encoded bytes |
initializeRequest
function initializeRequest(struct FunctionsRequest.Request self, enum FunctionsRequest.Location codeLocation, enum FunctionsRequest.CodeLanguage language, string source) internal pure
Initializes a Chainlink Functions Request
Sets the codeLocation and code on the request
Parameters
| Name | Type | Description |
|---|---|---|
| self | struct FunctionsRequest.Request | The uninitialized request |
| codeLocation | enum FunctionsRequest.Location | The user provided source code location |
| language | enum FunctionsRequest.CodeLanguage | The programming language of the user code |
| source | string | The user provided source code or a url |
initializeRequestForInlineJavaScript
function initializeRequestForInlineJavaScript(struct FunctionsRequest.Request self, string javaScriptSource) internal pure
Initializes a Chainlink Functions Request
Simplified version of initializeRequest for PoC
Parameters
| Name | Type | Description |
|---|---|---|
| self | struct FunctionsRequest.Request | The uninitialized request |
| javaScriptSource | string | The user provided JS code (must not be empty) |
addSecretsReference
function addSecretsReference(struct FunctionsRequest.Request self, bytes encryptedSecretsReference) internal pure
Adds Remote user encrypted secrets to a Request
Parameters
| Name | Type | Description |
|---|---|---|
| self | struct FunctionsRequest.Request | The initialized request |
| encryptedSecretsReference | bytes | Encrypted comma-separated string of URLs pointing to offchain secrets |
addDONHostedSecrets
function addDONHostedSecrets(struct FunctionsRequest.Request self, uint8 slotID, uint64 version) internal pure
Adds DON-hosted secrets reference to a Request
Parameters
| Name | Type | Description |
|---|---|---|
| self | struct FunctionsRequest.Request | The initialized request |
| slotID | uint8 | Slot ID of the user's secrets hosted on DON |
| version | uint64 | User data version (for the slotID) |
setArgs
function setArgs(struct FunctionsRequest.Request self, string[] args) internal pure
Sets args for the user run function
Parameters
| Name | Type | Description |
|---|---|---|
| self | struct FunctionsRequest.Request | The initialized request |
| args | string[] | The array of string args (must not be empty) |
setBytesArgs
function setBytesArgs(struct FunctionsRequest.Request self, bytes[] args) internal pure
Sets bytes args for the user run function
Parameters
| Name | Type | Description |
|---|---|---|
| self | struct FunctionsRequest.Request | The initialized request |
| args | bytes[] | The array of bytes args (must not be empty) |