NEW

Attend SmartCon 2023 to explore the future of Web3. Sign up now.

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

NameTypeDescription
selfstruct Functions.RequestThe request to encode

Return Values

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

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

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

NameTypeDescription
selfstruct Functions.RequestThe initialized request
secretsbytesThe 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

NameTypeDescription
selfstruct Functions.RequestThe initialized request
encryptedSecretsURLsbytesEncrypted 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

NameTypeDescription
selfstruct Functions.RequestThe initialized request
argsstring[]The array of args (must not be empty)

Stay updated on the latest Chainlink news