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
}
ValueDescription
InlineProvided within the Request.
RemoteHosted through a remote location that can be accessed through a provided URL.
DONHostedHosted 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;
}
FieldTypeDescription
codeLocationLocationThe location of the source code that will be executed on each node in the DON.
secretsLocationLocationThe location of secrets that will be passed into the source code. *Only Remote secrets are supported.
languageCodeLanguageThe coding language that the source code is written in.
sourcestringRaw 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.
encryptedSecretsReferencebytesEncrypted URLs for Request.secretsLocation of Location.Remote, or CBOR encoded slotid+version for Request.secretsLocation of Location.DONHosted.
argsstring[]String arguments that will be passed into the source code.
bytesArgsbytes[]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

NameTypeDescription
selfstruct FunctionsRequest.RequestThe request to encode

Return values

NameTypeDescription
[0]bytesCBOR 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

NameTypeDescription
selfstruct FunctionsRequest.RequestThe uninitialized request
codeLocationenum FunctionsRequest.LocationThe user provided source code location
languageenum FunctionsRequest.CodeLanguageThe programming language of the user code
sourcestringThe 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

NameTypeDescription
selfstruct FunctionsRequest.RequestThe uninitialized request
javaScriptSourcestringThe 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

NameTypeDescription
selfstruct FunctionsRequest.RequestThe initialized request
encryptedSecretsReferencebytesEncrypted 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

NameTypeDescription
selfstruct FunctionsRequest.RequestThe initialized request
slotIDuint8Slot ID of the user's secrets hosted on DON
versionuint64User data version (for the slotID)

setArgs

function setArgs(struct FunctionsRequest.Request self, string[] args) internal pure

Sets args for the user run function

Parameters

NameTypeDescription
selfstruct FunctionsRequest.RequestThe initialized request
argsstring[]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

NameTypeDescription
selfstruct FunctionsRequest.RequestThe initialized request
argsbytes[]The array of bytes args (must not be empty)

Get the latest Chainlink content straight to your inbox.