Skip to content

Runtime Variables

One of the main difficulties associated with issuing a single Cross-Chain UserOperation is the need to define inputs for all of its steps.

There are multiple scenarios where this is not possible. For example, consider an operation that consists of swapping ETH for USDC on Optimism and then bridging the USDC to Arbitrum. The user knows the amount of ETH swapped but does not know the amount of USDC that was received, and so appears to be unable to define the second action without waiting and observing the first one.

The EIL SDK solves this issue by introducing "Runtime Variables". This feature allows users to define UserOperations with parameters that are resolved during the execution of UserOperation.

Specifying a Runtime Variable

The Runtime Variable can be used in the EIL SDK everywhere one can expect to use a value type such as number.

const abi = parseAbi([
  'function getCurrentValue() external returns(uint256)',
])

const builder = sdk
  .createBuilder()
  .startBatch(chainId0)
  .addAction(new SetVarAction({
    target: targetAddress,
    functionName: 'getCurrentValue',
    args: [],
    abi: abi,
    setVar: 'myFirstRuntimeVariable',
  }))
  .addVoucherRequest({
    destinationChainId: chainId1,
    tokens: [{
      token: usdc,
      amount: runtimeVar('myFirstRuntimeVariable')
    }]
  })

As you can see, the actual value of the myFirstRuntimeVariable is not known to the application. It will be queried from the targetAddress contract and can be used in consequent EIL SDK actions.