A calling contract is any smart contract that invokes the Forte Rules Engine to evaluate a policy. This is the on-chain portion of your application and is fully under your control.Documentation Index
Fetch the complete documentation index at: https://docs.forterulesengine.io/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Calling contracts serve as the entry point for policy evaluation. When a function in your calling contract is executed, it can trigger the Rules Engine to evaluate one or more rules defined in a subscribed policy.How It Works
- Your contract extends the
RulesEngineClientcontract - Your functions include modifiers that call the Rules Engine
- The Rules Engine evaluates the policy rules
- The transaction either continues or reverts based on the rule evaluation
Integration Requirements
To subscribe a smart contract to a policy, it must extend theRulesEngineClient contract included in the Forte Rules Engine.
Defining Calling Functions in Policies
When you create a policy, you must specify which smart contract functions can trigger it. These are defined in theCallingFunctions array of your policy (see Policy Templates for examples).
CallingFunction Properties
Each calling function in your policy must specify:- Name: A unique identifier for the function within the policy
- FunctionSignature: Must exactly match your smart contract’s function signature (including parameter types and order)
- EncodedValues: Parameters that will be passed to the Rules Engine for evaluation
EncodedValues: The Data Bridge
EncodedValues is one of the most important concepts in calling functions - it defines what data is sent from your contract to the Rules Engine for rule evaluation.
What Are EncodedValues?
EncodedValues specify:- Which parameters from your function signature to include
- Additional data beyond the function parameters (like balances, timestamps, etc.)
- The data types that rules can reference
Key Characteristics
Can Include More Than Function Parameters:senderBalance and receiverBalance are not in the function signature but are calculated and passed by your contract.
Names Don’t Need to Match Contract Parameters:
EncodedValues are just identifiers used within your policy - they don’t need to match your contract’s parameter names.
Referenced Throughout Your Policy:
Once defined in EncodedValues, these parameters can be used in:
- Rule conditions:
amount > 1000 - Foreign call parameters:
"ValuesToPass": "to" - Tracker keys:
TR:balances(to)
Supported Parameter Types
EncodedValues supports the following Solidity types: Primitive Types:uint256- Unsigned integersaddress- Ethereum addressesbool- Boolean valuesbytes- Byte arraysstring- String values
uint256[]address[]bool[]bytes[]string[]
Function Signature Matching
TheFunctionSignature in your policy must exactly match your contract’s function signature:
Correct:
Passing Additional Data to Rules Engine
One of the most powerful features of calling contracts is the ability to pass additional context beyond the function parameters.Common Additional Data Examples
Balance Information:Why Pass Additional Data?
Rules often need context that isn’t explicitly passed as function parameters:- Current State: Balances, allowances, ownership
- Calculated Values: Percentages, ratios, derived amounts
- Environmental Data: Block timestamps, block numbers (though Global Variables are often better for this)
- Cross-Reference Data: Data from related accounts or contracts
Function Resolution
The Rules Engine uses flexible function resolution when matching calling functions:Primary Matching
The engine first attempts to match theName field exactly as specified in the policy.
Fallback Matching
If an exact match fails, the engine performs case-insensitive matching:Best Practices
1. Keep EncodedValues Focused
Only include data that your rules actually need. Encoding and passing unnecessary data costs gas.2. Use Descriptive Names
Even though parameter names don’t affect matching, use clear names in your policy for maintainability:3. Document Additional Parameters
When passing data beyond function parameters, document what each additional value represents.4. Validate Data Before Encoding
Ensure the data you’re passing is in the correct format and type before encoding:5. Consistent Ordering
Maintain consistent parameter ordering between your policy’sEncodedValues and your contract’s encoding:
Integration Workflow
For full integration of your contract with the Forte Rules Engine:- Define your policy including CallingFunctions
- Add modifiers to your calling contract
- Register the policy with rules engine
- Deploy your contract
- Apply the policy
- Test the configuration
Related Documentation
- Guides:
- Concepts:
- Reference: Policy Syntax - CallingFunctions