Builder API Methods
This reference outlines the methods that are exposed to contract authors for building a GatewayRequest
to read data from other chains.
Internally these methods utilize OP codes (opens in a new tab) that our Virtual Machine can interpret and execute.
Targets
These methods modifies the target contract for operations that follow.Sets the target contract to the specified address. | |
Javascript | Solidity |
---|---|
setTarget(x: HexString) | setTarget(address a) |
Sets the target contract to the top item on the stack. | |
Javascript | Solidity |
---|---|
target() | target() |
Slot Manipulation
These methods manipulate the slot from which data will be read when a read command is executed.Sets the current slot to x. | |
Javascript | Solidity |
---|---|
setSlot(x: BigNumberish) | setSlot(uint256 x) |
Sets the current slot to the value at the top of the stack. | |
Javascript | Solidity |
---|---|
slot() | slot() |
Increments the current slot by x. | |
Javascript | Solidity |
---|---|
offset(x: BigNumberish) | offset(uint256 dx) |
Increments the current slot by the value at the top of the stack. | |
Javascript | Solidity |
---|---|
addSlot() | addSlot() |
Updates the slot based on a key defined at the top of the stack. | |
Javascript | Solidity |
---|---|
follow() | follow() |
Javascript | Solidity |
---|---|
followIndex() | followIndex() |
Reading Values
These commands read data from the target contract.Reads the value of n slots starting from the current VM slot. | |
Javascript | Solidity |
---|---|
read(n = 1) | read() / read(uint256 n) |
Reads the bytes value at the current storage slot. | |
Javascript | Solidity |
---|---|
readBytes() | readBytes() |
Javascript | Solidity |
---|---|
readHashedBytes() | readHashedBytes() |
Reads an array value at the current storage slot. | |
Javascript | Solidity |
---|---|
readArray(step: number) | readArray(uint256 step) |
Outputs
These commands set outputs that will be returned to the callback in the implementing contract.Sets the output at index i to the item at the HEAD of the stack. | |
Javascript | Solidity |
---|---|
setOutput(i: number) | setOutput(uint8 i) |
Sets the output at the index defined at the HEAD of the stack to the value found at HEAD-1 | |
Javascript | Solidity |
---|---|
output() | output() |
Nested Requests
These commands allow you to evaluate nested requests.!! Advanced functionality - more documentation coming.
Will evaluate an encoded request that has been pushed onto the HEAD of the stack. | |
Javascript | Solidity |
---|---|
eval() | eval() |
Will evaluate an encoded request that has been pushed onto the HEAD of the stack IF the previous operation resolves to true. | |
Javascript | Solidity |
---|---|
evalIf() | evalIf() |
Will evaluate an encoded request that has been pushed onto the HEAD of the stack against the specified number of items on the stack. Execution results are conditional on passed flags which in Javascript are passed as booleans on object properties, whilst in Solidity they are passed as a uint8. | |
Javascript | Solidity |
---|---|
evalLoop(opts: {success?: boolean; failure?: boolean; acquire?: boolean; keep?: boolean; count?: number;} = {}) | evalLoop(uint8 flags)/evalLoop(uint8 flags,uint256 count) |
The available evaluation flags are enumerated here: Typescript (opens in a new tab) and Solidity (opens in a new tab). They are:
STOP_ON_SUCCESS
STOP_ON_FAILURE
ACQUIRE_STATE
KEEP_ARGS
Exiting
These commands handle assertions, requirements, and graceful request exits.Exit with the specified exit code. | |
Javascript | Solidity |
---|---|
exit(exitCode: number) | exit(uint8 exitCode) |
Exit with the specified exit code if the item at the top of the stack is not zero. | |
Javascript | Solidity |
---|---|
assertNonzero(exitCode: number) | assertNonzero(uint8 exitCode) |
Exit with the specified exit code if the current target is not a contract. | |
Javascript | Solidity |
---|---|
requireContract(exitCode = 1) | requireContract(uint8 exitCode) |
Exit with the specified exit code if the item at the top of the stack is not zero. Leaves the item on the stack | |
Javascript | Solidity |
---|---|
requireNonzero(exitCode = 1) | requireNonzero(uint8 exitCode) |
Stack Manipulation
These commands manipulate the data on the Virtual Machine's internal stack.Javascript | Solidity |
---|---|
pop() | pop() |
Javascript | Solidity |
---|---|
dup(back = 0) | dup() / dup(uint256 back) |
Javascript | Solidity |
---|---|
swap(back = 1) | swap() / swap(uint256 back) |
Javascript | Solidity |
---|---|
pushOutput(i: number) | pushOutput(uint256 i) |
Javascript | Solidity |
---|---|
pushStack(i: number) | pushStack(uint256 i) |
Javascript | Solidity |
---|---|
push(x: BigNumberish | boolean) | N/A |
Javascript | Solidity |
---|---|
pushStr(s: string) | N/A |
Javascript | Solidity |
---|---|
pushBytes(v: BytesLike) | N/A |
Javascript | Solidity |
---|---|
pushProgram(program: GatewayProgram) | N/A |
Pushes the current slot onto the stack. | |
Javascript | Solidity |
---|---|
getSlot() | getSlot() |
Pushes the current target onto the stack. | |
Javascript | Solidity |
---|---|
getTarget() | getTarget() |
Pushes the current stack size onto the stack. | |
Javascript | Solidity |
---|---|
stackSize() | stackCount() |
Pushes onto the stack if the current target is a contract. | |
Javascript | Solidity |
---|---|
isContract() | isContract() |
Data Manipulation
These commands manipulate data on the stack.Replaces the top two items on the stack with their concatentation. | |
Javascript | Solidity |
---|---|
concat() | concat() |
Replaces the top item on the stack with its keccak256 representation. | |
Javascript | Solidity |
---|---|
keccak() | keccak() |
Slices n/len bytes from the value at the HEAD of the stack starting at position x/pos | |
Javascript | Solidity |
---|---|
slice(x: number, n: number) | slice(uint256 pos, uint256 len) |
Replaces the value at the head of the stack with its length. | |
Javascript | Solidity |
---|---|
length() | length() |
Replaces the two items at the top of the stack with their summation. | |
Javascript | Solidity |
---|---|
plus() | plus() |
Replaces the two items at the head of the stack with the result of subtracting the value at HEAD from the value at HEAD - 1. | |
Javascript | Solidity |
---|---|
subtract() | subtract() |
Replaces the value at the top of the stack with its twos complement. | |
Javascript | Solidity |
---|---|
twosComplement() | twosComplement() |
Multiplies the two values at the head of the stack and replaces them with the result. | |
Javascript | Solidity |
---|---|
times() | times() |
Divides the value at HEAD-1 of the stack by the value at HEAD and replaces them with the result. | |
Javascript | Solidity |
---|---|
divide() | divide() |
Calculates the value at HEAD-1 modulo the value at HEAD and replaces them with the result. | |
Javascript | Solidity |
---|---|
mod() | mod() |
Replaces the two items at the head of the stack with the result of the value at HEAD-1 being raised to the power of the value at HEAD. | |
Javascript | Solidity |
---|---|
pow() | pow() |
Replaces the two values at the top of the stack with their Bitwise AND | |
Javascript | Solidity |
---|---|
and() | and() |
Replaces the two values at the top of the stack with their Bitwise OR | |
Javascript | Solidity |
---|---|
or() | or() |
Replaces the two values at the top of the stack with their Bitwise XOR | |
Javascript | Solidity |
---|---|
xor() | xor() |
Replaces the value at the top of the stack with its Bitwise NOT | |
Javascript | Solidity |
---|---|
not() | not() |
Bitwise shifts the value at the top of the stack by `shift` bits to the left. | |
Javascript | Solidity |
---|---|
shl(shift: BigNumberish) | shl(uint8 shift) |
Bitwise shifts the value at the top of the stack by `shift` bits to the right. | |
Javascript | Solidity |
---|---|
shr(shift: BigNumberish) | shr(uint8 shift) |
Comparison Operations
These commands perform comparison operations on stack data.Replaces the value at the top of the stack with a boolean indicating if it is zero. | |
Javascript | Solidity |
---|---|
isZero() | isZero() |
Replaces the top two items on the stack with a boolean indicating if they are equal. | |
Javascript | Solidity |
---|---|
eq() | eq() |
Replaces the top two items on the stack with a boolean indicating if they are not equal. | |
Javascript | Solidity |
---|---|
neq() | neq() |
Replaces the top two items on the stack with a boolean indicating of the value at HEAD-1 is greater than the value at the HEAD. | |
Javascript | Solidity |
---|---|
gt() | gt() |
Replaces the top two items on the stack with a boolean indicating of the value at HEAD-1 is less than the value at the HEAD. | |
Javascript | Solidity |
---|---|
lt() | lt() |
Replaces the top two items on the stack with a boolean indicating of the value at HEAD-1 is less than or equal the value at the HEAD. | |
Javascript | Solidity |
---|---|
lte() | lte() |
Replaces the top two items on the stack with a boolean indicating of the value at HEAD-1 is greater than or equal to the value at the HEAD. | |
Javascript | Solidity |
---|---|
gte() | gte() |
Duplicate the top two items on the stack. | |
Javascript | Solidity |
---|---|
dup2() | dup2() |
Puts the minimum value out of the last two values on the stack at the HEAD. | |
Javascript | Solidity |
---|---|
min() | min() |
Puts the maximum value out of the last two values on the stack at the HEAD. | |
Javascript | Solidity |
---|---|
max() | max() |
Debug
These commands aid in debugging your requests.Used for debugging. Outputs the machine state to the console. Available only in JavaScript. | |
Javascript | Solidity |
---|---|
debug(label = '') | N/A |