Function operators

Display()

Displays an existing field. By default, the fields from the previous output are not automatically carried over to the next step. You need to explicitly specify them.
How "Display" works

map(input, as, in)

It is used to apply one or multiple operators to every element of an array. It returns a new array with the applied results.
Input : The array that you want to apply one or multiple operators towards.
as : A name that represents each individual element of the input array. Its default value is 'this'. Most time you do not have to change that value except when using a map operator inside another function operator, you might need to give it a different name in order to avoid a potential naming conflict.
in : Where one or multiple operators can be applied to transform every element of the input array. This is where as will be used.
For example: there is an array [1, 2, 3, 4]. We want to add 5 to each element in the array. And the output should be [6, 7, 8, 9]
How "map" works
What is $this ?
$this represents the individual element of the input array. In the above example, we are telling Scout that we want to add 5 to each element of the array.

reduce(input, initial, op)

It is used to apply one or multiple operators to every element of an array and combines them into a single value.
input : The array that you want to apply operators towards.
initial : The initial value for the final result.
op : This is where one or multiple operators can be applied to every element of the input array.
For example: there is an array [a, b, c, d] and we want to combine all the characters into one string and append "initial" to the beginning of the final result.
How "reduce" works
What is $this and $value ?
$this represents the individual element of the input array.
$value represents the cumulative value of the operation that's been applied to the elements.
In the above example, the operator reduce goes through each element of the input array and use the operator strConcat to append the value of each element into one string.

filter (input, as, when)

Returns a subset array of input based on the condition specified in when.
Input : The array that needs to be filtered.
as : A name that represents each individual element of the input. Its default value is 'this'. Most time you do not have to change that value except when using a map operator inside another operator, you might need to give it a different name in order to avoid a potential naming conflict.
when : The filter condition that each element of input must meet before being added to the returned array.
From example: We have an array [1,2,3,4,5,6,7,8,9] and we only want to remove any elements which are smaller than 4.
How "filter" works

ifThenElse()

Provides a classic if-then-else function to process data that requires conditional logic. The logic goes like this: If condition0 is true, then do op0, else if condition1 is true do op1 ...and you can keep going until none of the above conditions are true, do oplast.
For example: There is a field called "a" and its value is 222. You want to x to display "correct" when "a" equals 222 and display "wrong" otherwise.
How "ifThenElse" works

tokenExchange(from, amount, to, time)

Converts a token to a different token or fiat currency.
from : Must be a valid token symbol such as ANT, LPT, COMP, WBTC, WETH and etc. It is case sensitive!
to : Must be a valid token symbol or fiat currency. (Only supports USD at this moment)
amount : The amount of token.
time : (optional) What conversion rate should be used. If it is left blank, the latest conversion rate will be applied. The pricing data is stored hourly. To use a historical conversion rate, you can specify a UTC timestamp. For example, to get a conversion rate at 4PM on August 14th, 2020, the timestamp is 1597420800.
For example:
How "tokenExchange" works

lookupContract(address)

Returns the basic information of a given contract address.
address : Must be a valid smart contract address. Checksum address (case sensitive) only.
For example:
How "lookupContract" works

lookupSymbol(symbol)

Returns an array of token contracts of a given token symbol. Most of time, the array should only include one token contract unless some tokens share the same symbols.
symbol : Token symbol such as WETH, USDC, etc. Must be in uppercase.
Last modified 11mo ago
Copy link