Foreign contracts allow your policy to call any external contract from the Rules Engine. This makes the Forte Rules Engine composable and extensible.

Foreign contracts can be used in two ways:

  • Foreign data – As part of expressions in rules or trackers
  • Foreign effects – As actions triggered by rules

Configuring Foreign Calls

To call a foreign contract from the Rules Engine, you will need to specify everything needed to call that function, in particular:

  • the foreign contract’s address
  • the method signature to be called
  • expected return type, if applicable
  • the arguments to the method (captured in the “encodedIndices” tag)

Example:

    "address": "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
    "signature": "accessLevel(address)",
    "returnType": "uint256",
    "parameterTypes": "address",
    "encodedIndices": "0"

For more details, see the syntax guide.

Using Foreign Calls

Once you have a foreign call configured as part of your policy, you can use it in any expression. For example, you could use it in a rule that calls an external oracle to verify if an address is on the OFAC sanctions list, and reverts the transaction if it is. Or you could use a foreign call to an AMM price feed, to update a tracker that measures volatility or some other aggregate metric related to price.

You can also use foreign calls as an effect, an outcome of a rule. For example, you might update a foreign oracle based on activity with a token that is subscribed to your policy.

Foreign calls used in expressions must return immediately usable values—only read/view functions are supported.