β Tasks References
This guide outlines different task types.
βAnyβ task
Returns a random value from the set of inputs passed in.
Parameters
None.
Inputs
Can be anything.
Outputs
A randomly-selected value from the set of inputs.
Example
pick_any
will return either the result of fetch1
, fetch2
, or fetch3
.
Base64 Decode task
Accepts a base64 encoded string and returns decoded bytes.
Parameters
input
: a base64 encoded string.
Outputs
Decoded bytes.
Example
Given the input SGVsbG8sIHBsYXlncm91bmQ=
, the task will return Hello, playground
(as ASCII bytes).
Base64 Encode task
Encodes bytes/string into a Base64 string.
Parameters
input
: Byte array or string to be encoded.
Outputs
String with Base64 encoding of input.
Example
Given the input string βHello, playgroundβ, the task will return βSGVsbG8sIHBsYXlncm91bmQ=β.
Bridge task
Bridge tasks make HTTP POST requests to pre-configured URLs. Bridges can be configured via the UI or the CLI, and are referred to by a simple user-specified name. This is the way that most jobs interact with External Adapters.
Parameters
name
: an arbitrary name given to the bridge by the node operator.requestData
(optional): a statically-defined payload to be sent to the external adapter.cacheTTL
(optional): a duration-formatted string indicating the maximum acceptable staleness for cached bridge responses in case of intermittent failures. This is disabled by default.headers
(optional): an array of strings. The number of strings must be even. Example:foo [type="bridge" name="foo" headers="[\\"X-Header-1\\", \\"value1\\", \\"X-Header-2\\", \\"value2\\"]"]
Outputs
A string containing the response body.
Example
CBOR Parse task
CBOR Parse tasks parse a CBOR payload, typically as part of a OnchainRequest workflow. In OnchainRequest, a user makes an on-chain request using a Client
contract, which encodes the request parameters as CBOR. See below for an example.
Parameters
data
: A byte array containing the CBOR payload.mode
: An optional parameter that specifies how to parse the incoming CBOR. The default mode isdiet
, which expects the input to be a map. Set the mode tostandard
to pass literal values through βas-isβ. Empty inputs return nil.
Outputs
A map containing the request parameters. Parameters can be individually accessed using $(dot.accessors)
.
Example
See the Direct Request page for a more comprehensive example.
Divide task
Divides the provided input
by the divisor
and returns the result with a number of decimal places defined in the precision
value.
Parameters
input
: The value to be dividednumber
stringified number
bytes-ified number
$(variable)
divisor
: The value by which to divide theinput
number
stringified number
bytes-ified number
$(variable)
precision
: The number of decimal places to retain in the resultnumber
stringified number
bytes-ified number
$(variable)
Outputs
The result of the division.
Example
Given the input 10
, this example returns 3.33
.
ETH ABI Decode Log task
Decodes a log emitted by an ETH contract.
Parameters
abi
: a canonical ETH log event definition. Should be formatted exactly as in Solidity. Each argument must be named. Examples:NewRound(uint256 indexed roundId, address indexed startedBy, uint256 startedAt)
AuthorizedSendersChanged(address[] senders)
data
: the ABI-encoded log data. Can be:a byte array
a hex-encoded string beginning with
0x
β¦ but generally should just be set to
$(jobRun.logData)
(see the Direct Request page)
topics
: the ABI-encoded log topics (i.e., theindexed
parameters)an array of bytes32 values
an array of hex-encoded bytes32 values beginning with
0x
β¦ but generally should just be set to
$(jobRun.logTopics)
(see the Direct Request page)
Outputs
A map containing the decoded values.
Example
This task will return a map with the following schema:
ETH ABI Decode task
Decodes a ETH ABI-encoded payload, typically the result of an ETH Call task.
Parameters
abi
: a canonical ETH ABI argument string. Should be formatted exactly as in Solidity. Each argument must be named. Examples:uint256 foo, bytes32 bar, address[] baz
address a, uint80[3][] u, bytes b, bytes32 b32
data
: the ABI-encoded payload to decode. Can be:a byte array
a hex-encoded string beginning with
0x
Outputs
A map containing the decoded values.
Example
This task will return a map with the following schema:
ETH ABI Encode task
Encodes a bytes payload according to ETH ABI encoding, typically in order to perform an ETH Call or an ETH Tx.
Parameters
abi
: a canonical ETH ABI argument string. Should be formatted exactly as in Solidity. Each argument must be named. If a method name is provided, the 4-byte method signature is prepended to the result. Examples:uint256 foo, bytes32 bar, address[] baz
fulfillRequest(bytes32 requestID, uint256 answer)
data
: a map of the values to be encoded. The task will make a best effort at converting values to the appropriate types.
Outputs
A byte array.
Example
ETH Call task
Makes a non-mutating contract call to the specified contract with the specified data payload.
Parameters
contract
: the address of the contract to call.data
: the data to attach to the call (including the function selector).gas
: the amount of gas to attach to the transaction.from
: The from address with which the call should be made. Defaults to zero address.gasPrice
: The gasPrice for the call. Defaults to zero.gasTipCap
: The gasTipCap (EIP-1559) for the call. Defaults to zero.gasFeeCap
: The gasFeeCap (EIP-1559) for the call. Defaults to zero.gasUnlimited
: A boolean indicating if unlimited gas should be provided for the call. If set to true, do not pass thegas
parameter.
Outputs
An ABI-encoded byte array containing the return value of the contract function.
Example
ETH Tx task
Makes a mutating transaction to the specified contract with the specified data payload. The transaction is guaranteed to succeed eventually.
Parameters
from
: one or more addresses of the externally-owned account from which to send the transaction. If left blank, it will select a random address on every send for the given chain ID.to
: the address of the contract to make a transaction to.data
: the data to attach to the call (including the function selector). Most likely, this will be the output of anethabiencode
task.gasLimit
: the amount of gas to attach to the transaction.txMeta
: a map of metadata that is saved into the database for debugging.minConfirmations
: minimum number of confirmations required before this task will continue. Set to zero to continue immediately. Note that this does not affect transaction inclusion. All transactions will always be included in the chain up to the configured finality depth.evmChainID
: set this optional parameter to transmit on the given chain. You must have the chain configured with RPC nodes for this to work. If left blank, it will use the default chain.failOnRevert
: an optional parameter, a boolean, that allows a operatorβs UI to display and color the status of the task within a jobβs pipeline depending on a transaction status. default: false.
Outputs
The hash of the transaction attempt that eventually succeeds (after potentially going through a gas bumping process to ensure confirmation).
Example
Hex Decode task
Accepts a hexadecimal encoded string and returns decoded bytes.
Parameters
input
: a hexadecimal encoded string, must have prefix0x
.
Outputs
Decoded bytes.
Example
Given the input 0x12345678
, the task will return [0x12, 0x34, 0x56, 0x78]
.
Hex Encode task
Encodes bytes/string/integer into a hexadecimal string.
Parameters
input
: Byte array, string or integer to be encoded.
Outputs
Hexadecimal string prefixed with β0xβ (or empty string if input was empty).
Example
Given the input string βxyzβ, the task will return β0x78797aβ, which are the ascii values of characters in the string.
HTTP task
HTTP tasks make HTTP requests to arbitrary URLs.
Parameters
method
: the HTTP method that the request should use.url
: the URL to make the HTTP request to.requestData
(optional): a statically-defined payload to be sent to the external adapter.allowUnrestrictedNetworkAccess
(optional): permits the task to access a URL atlocalhost
, which could present a security risk. Note that Bridge tasks allow this by default.headers
(optional): an array of strings. The number of strings must be even. Example:foo [type=http headers="[\\"X-Header-1\\", \\"value1\\", \\"X-Header-2\\", \\"value2\\"]"]
Outputs
A string containing the response body.
Example
JSON Parse task
JSON Parse tasks parse a JSON payload and extract a value at a given keypath.
Parameters
data
: the JSON string. Can be:string
byte array
path
: the keypath to extract. Must be a comma-delimited list of keys, or specify a customseparator
alternative.separator
: (optional) custompath
key separator. Defaults to comma (,
).lax
(optional): if false (or omitted), and the keypath doesnβt exist, the task will error. If true, the task will returnnil
to the next task.
Outputs
The value at the provided keypath.
Example
This task returns 123.45
(float64) when given the following example data
value:
Length task
Returns the length of a byte array or string.
Parameters
input
: Byte array, or string to get the length for.
Outputs
The length of the byte array or string.
Note: For strings containing multi-byte unicode characters, the output is the length in bytes and not number of characters.
Example
Given the input string βxyzβ, the task will return 3, length of the string.
Less Than task
Returns a boolean, result of computing left < right
.
Parameters
left
: the left hand side of comparison. Possible values:number
stringified number
bytes-ified number
$(variable)
right
: the right hand side of comparison. Possible values:number
stringified number
bytes-ified number
$(variable)
Outputs
The result of less than comparison.
Example
the task will return true which is the result of 3 < 10
Lowercase task
Accepts a string and returns a lowercase string.
Parameters
input
: a string.
Outputs
Lowercase string.
Example
Given the input Hello World!
, the task will return hello world!
.
Mean task
Accepts multiple numerical inputs and returns the mean (average) of them.
Parameters
values
: an array of values to be averaged.allowedFaults
(optional): the maximum number of input tasks that can error without the Mean task erroring. If not specified, this value defaults toN - 1
, whereN
is the number of inputs.precision
: the number of decimal places in the result.
Outputs
The average of the values in the values
array.
Example
Given the inputs 2
, 5
, and 20
, the task will return 9
.
Median task
Accepts multiple numerical inputs and returns the median of them.
Parameters
values
: an array of values from which to select a median.allowedFaults
(optional): the maximum number of input tasks that can error without the Median task erroring. If not specified, this value defaults toN - 1
, whereN
is the number of inputs.
Outputs
The median of the values in the values
array.
Example
Given the inputs 2
, 5
, and 20
, the task will return 5
.
Mode task
Accepts multiple numerical inputs and returns the mode (most common) of them. If more than one value occur the maximum number of times, it returns all of them.
Parameters
values
: an array of values from which to select a mode.allowedFaults
(optional): the maximum number of input tasks that can error without the Mode task erroring. If not specified, this value defaults toN - 1
, whereN
is the number of inputs.
Outputs
A map containing two keys:
Example
Given a values
array containing [ 2, 5, 2, "foo", "foo" "bar", "foo", 2 ]
, the task will return:
Multiply task
Multiplies the provided input
and times
values.
Parameters
input
: the value to be multipled. Possible values:number
stringified number
bytes-ified number
$(variable)
times
: the value to multiply the input with.number
stringified number
bytes-ified number
$(variable)
Outputs
The result of the multiplication.
Example
Given the input 10
, the task will return 30
.
Sum Task
Accepts multiple numerical inputs and returns the sum of them.
Parameters
values
: an array of values to sum.allowedFaults
(optional): the maximum number of input tasks that can error without the Sum task erroring. If not specified, this value defaults toN - 1
, whereN
is the number of inputs.
Outputs
The sum of the values in the values
array.
Example
Given the inputs 2
, 5
, and 20
, the task will return 27
.
Uppercase task
Accepts a string and returns an uppercase string.
Parameters
input
: a string.
Outputs
Uppercase string.
Example
Given the input Hello World!
, the task will return HELLO WORLD!
.
Last updated