Functions library API Reference
Consumer contract developers use the Functions library to build their requests.
Types and Constants
DEFAULT_BUFFER_SIZE
uint256 DEFAULT_BUFFER_SIZE
Location
enum Location {
Inline,
Remote
}
CodeLanguage
enum CodeLanguage {
JavaScript
}
Request
struct Request {
enum Functions.Location codeLocation;
enum Functions.Location secretsLocation;
enum Functions.CodeLanguage language;
string source;
bytes secrets;
string[] args;
}
Errors
EmptySource
error EmptySource()
EmptyUrl
error EmptyUrl()
EmptySecrets
error EmptySecrets()
EmptyArgs
error EmptyArgs()
Functions
encodeCBOR
function encodeCBOR(struct Functions.Request self) internal pure returns (bytes)
Encodes a Request to CBOR encoded bytes
Parameters
Name | Type | Description |
---|---|---|
self | struct Functions.Request | The request to encode |
Return Values
Name | Type | Description |
---|---|---|
[0] | bytes | CBOR encoded bytes |
initializeRequest
function initializeRequest(struct Functions.Request self, enum Functions.Location location, enum Functions.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 Functions.Request | The uninitialized request |
location | enum Functions.Location | The user provided source code location |
language | enum Functions.CodeLanguage | The programming language of the user code |
source | string | The user provided source code or a url |
initializeRequestForInlineJavaScript
function initializeRequestForInlineJavaScript(struct Functions.Request self, string javaScriptSource) internal pure
Initializes a Chainlink Functions Request
Simplified version of initializeRequest for PoC
Parameters
Name | Type | Description |
---|---|---|
self | struct Functions.Request | The uninitialized request |
javaScriptSource | string | The user provided JS code (must not be empty) |
addInlineSecrets
function addInlineSecrets(struct Functions.Request self, bytes secrets) internal pure
Adds Inline user encrypted secrets to a Request
Parameters
Name | Type | Description |
---|---|---|
self | struct Functions.Request | The initialized request |
secrets | bytes | The user encrypted secrets (must not be empty) |
addRemoteSecrets
function addRemoteSecrets(struct Functions.Request self, bytes encryptedSecretsURLs) internal pure
Adds Remote user encrypted secrets to a Request
Parameters
Name | Type | Description |
---|---|---|
self | struct Functions.Request | The initialized request |
encryptedSecretsURLs | bytes | Encrypted comma-separated string of URLs pointing to off-chain secrets |
addArgs
function addArgs(struct Functions.Request self, string[] args) internal pure
Adds args for the user run function
Parameters
Name | Type | Description |
---|---|---|
self | struct Functions.Request | The initialized request |
args | string[] | The array of args (must not be empty) |