Contract Calls
Overview
Architecture
Implementation Patterns
1. Simple Function Call
contract CrossChainNotifier {
IIXFIGateway public gateway;
function notifyOnChain(string memory targetChain, address targetContract) external {
bytes memory payload = abi.encodeWithSignature("notify()");
gateway.callContract(
targetChain,
Strings.toHexString(uint160(targetContract), 20),
payload
);
}
}
contract NotificationReceiver is IXFIExecutable {
event NotificationReceived(string sourceChain, address sourceContract);
function execute(
bytes32 commandId,
string memory sourceChain,
string memory sourceAddress,
bytes memory payload
) external override onlyGateway {
// Decode the function selector
bytes4 selector = bytes4(payload);
if (selector == this.notify.selector) {
notify();
emit NotificationReceived(sourceChain, _parseAddress(sourceAddress));
}
}
function notify() public {
// Notification logic here
}
}2. Parameterized Function Call
3. Conditional Execution
4. Multi-Step Workflow
Advanced Patterns
Callback Mechanism
State Synchronization
Cross-Chain Governance
Error Handling
Robust Error Recovery
Circuit Breaker Pattern
Security Considerations
Input Validation
Reentrancy Protection
Gas Optimization
Batch Contract Calls
Optimized Payload Encoding
Testing
Mock Contracts for Testing
Integration Tests
Best Practices
1. Design for Failure
2. Validate Inputs
3. Use Access Control
4. Optimize Gas Usage
5. Test Thoroughly
6. Monitor Operations
Resources
Last updated