var img = document.createElement('img'); img.src = "https://terradocs.matomo.cloud//piwik.php?idsite=3&rec=1&url=https://docs.warp.money" + location.pathname; img.style = "border:0"; img.alt = "tracker"; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(img,s);
Skip to main content

Variables

Variables are placeholders for arbitrary data that can be inserted into Warp jobs and conditions. To make creating jobs easier, variables can be specified and input into job or query templates. After creating variables, you can add them to messages using their reference value in the form of $warp.variable.variable-name.

You can use variables with templates to create complex reusable jobs.

Variables created in the Warp app are stored in your browser and are not written to the blockchain until they are inserted into templates.

VariableKind

The following are the different variable input types that can be used.

variable.rs

_11
pub enum VariableKind {
_11
String,
_11
Uint,
_11
Int,
_11
Decimal,
_11
Timestamp,
_11
Bool,
_11
Amount,
_11
Asset,
_11
Json,
_11
}

Static variables

Static variables are the simplest form of variable and are created with a value. Static variable values can be updated in loops using an UpdateFn.

variable.rs

_10
#[cw_serde]
_10
pub struct StaticVariable {
_10
pub kind: VariableKind,
_10
pub name: String,
_10
pub value: String,
_10
pub update_fn: Option<UpdateFn>,
_10
}

Query variables

Query variables allow you to select a value from the response of a specified query. Queries require a query message and a selector, which is used to select the correct portion of the query response. When looping, query variables can be updated or specified to be reinitialized.

variable.rs

_13
pub struct QueryVariable {
_13
pub kind: VariableKind,
_13
pub name: String,
_13
pub init_fn: QueryExpr,
_13
pub reinitialize: bool,
_13
pub value: Option<String>, //none if uninitialized
_13
pub update_fn: Option<UpdateFn>,
_13
}
_13
_13
pub struct QueryExpr {
_13
pub selector: String,
_13
pub query: QueryRequest<String>,
_13
}

Update functions and loops

Variables can be updated using an update function, which can change the value of the variable upon the success or failure of a job. By specifying whether a variable should update after completion, jobs can be looped. You can specify how a value should be updated upon success or failure, and you can use an update function to update the value. Update functions can include a NumValue and an operator to update the value. A NumValue can also reference an expression or variable such as a query, allowing for further looping and update capability. Update functions and loops can only be applied if recurring is set to true in the job message.

variable.rs

_15
_15
pub enum UpdateFnValue {
_15
Uint(NumValue<Uint256, NumExprOp, IntFnOp>),
_15
Int(NumValue<i128, NumExprOp, IntFnOp>),
_15
Decimal(NumValue<Decimal256, NumExprOp, DecimalFnOp>),
_15
Timestamp(NumValue<i128, NumExprOp, IntFnOp>),
_15
BlockHeight(NumValue<i128, NumExprOp, IntFnOp>),
_15
Bool(String), //ref
_15
}
_15
_15
_15
pub struct UpdateFn {
_15
pub on_success: Option<UpdateFnValue>,
_15
pub on_error: Option<UpdateFnValue>,
_15
}

Reinitialize

Expression and Query variables contain a reinitialize boolean, which specifies whether the query or external variable should be fetched again. If this boolean is set to true, the job will be run again after completion (on success or failure) and the data will be fetched again upon each subsequent job. Variables cannot be updated using an UpdateFn if the reinitialize boolean is set to true and if recurring is set to true in the job message.

Nesting variables

Variables can be nested or referenced, allowing a reference of a result of one variable to appear in a different variable. However, you can only nest or reference previous variables in a sequence. For example, in the following code, { vars: [var0, var1, var2, var3,] }, var2 can only contain the variables that came before it, and cannot reference var3.

External Variables

External variables are fetched from external sources such as APIs. They require an external reference input, which includes a URL, a method (Get, Post, Push, Pass, Delete), a header, a body, and a JSON selector. External variables can be updated or specified to be reinitialized.

variable.rs

_17
pub struct ExternalVariable {
_17
pub kind: VariableKind,
_17
pub name: String,
_17
pub init_fn: ExternalExpr,
_17
pub reinitialize: bool,
_17
pub value: Option<String>, //none if uninitialized
_17
pub update_fn: Option<UpdateFn>,
_17
}
_17
_17
_17
pub struct ExternalExpr {
_17
pub url: String,
_17
pub method: Option<Method>,
_17
pub headers: Option<HashMap<String, String>>,
_17
pub body: Option<String>,
_17
pub selector: String,
_17
}