FunctionsRequest library API Reference
Consumer contract developers use the FunctionsRequest library to build their requests.
Types and Constants
REQUEST_DATA_VERSION
uint16 REQUEST_DATA_VERSIONDEFAULT_BUFFER_SIZE
uint256 DEFAULT_BUFFER_SIZELocation
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.codeLocationofLocation.Inline, URL forRequest.codeLocationofLocation.Remote, or slot decimal number forRequest.codeLocationofLocation.DONHosted. | 
| encryptedSecretsReference | bytes | Encrypted URLs for Request.secretsLocationofLocation.Remote, or CBOR encodedslotid+versionforRequest.secretsLocationofLocation.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 pureInitializes 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 pureInitializes 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 pureAdds 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 off-chain secrets | 
addDONHostedSecrets
function addDONHostedSecrets(struct FunctionsRequest.Request self, uint8 slotID, uint64 version) internal pureAdds 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 pureSets 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 pureSets 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) |