IU2U Gateway
The IU2U Gateway is the core contract that enables cross-chain communication and token transfers in the IU2U Protocol.
Contract Interface
interface IIU2UGateway {
// Cross-chain messaging
function callContract(
string memory destinationChain,
string memory contractAddress,
bytes memory payload
) external;
function callContractWithToken(
string memory destinationChain,
string memory contractAddress,
bytes memory payload,
string memory symbol,
uint256 amount
) external;
// Token operations
function sendToken(
string memory destinationChain,
string memory destinationAddress,
string memory symbol,
uint256 amount
) external;
// Command execution
function execute(bytes memory data) external;
// Relayer management
function isValidRelayer(address relayer) external view returns (bool);
// Chain management
function isValidChain(string memory chainName) external view returns (bool);
// Status queries
function isCommandExecuted(bytes32 commandId) external view returns (bool);
}Core Functions
callContract
Initiates a cross-chain contract call without token transfer.
Parameters:
destinationChain: Name of the target blockchain (e.g., "ethereum", "bsc")contractAddress: Address of the target contract on destination chainpayload: Encoded function call data to execute
Events Emitted:
Example:
callContractWithToken
Initiates a cross-chain contract call with token transfer.
Parameters:
destinationChain: Name of the target blockchaincontractAddress: Address of the target contractpayload: Encoded function call datasymbol: Token symbol to transfer (e.g., "IU2U")amount: Amount of tokens to transfer
Events Emitted:
Example:
sendToken
Transfers tokens to an address on another chain.
Parameters:
destinationChain: Target blockchain namedestinationAddress: Recipient address on destination chainsymbol: Token symbol to transferamount: Amount to transfer
Events Emitted:
execute
Executes approved cross-chain commands (relayer-only function).
Parameters:
data: Encoded command data including signatures and payload
Access Control: Only authorized relayers can call this function.
View Functions
isValidRelayer
Checks if an address is an authorized relayer.
Returns: true if the address is an authorized relayer
isValidChain
Checks if a chain name is supported.
Returns: true if the chain is supported
isCommandExecuted
Checks if a command has already been executed.
Returns: true if the command has been executed
Events
ContractCall
Emitted when a cross-chain contract call is initiated.
ContractCallWithToken
Emitted when a cross-chain contract call with token transfer is initiated.
TokenSent
Emitted when tokens are sent cross-chain.
Executed
Emitted when a cross-chain command is executed.
Error Codes
Gas Costs
callContract
80,000 - 150,000
Payload size, chain congestion
callContractWithToken
120,000 - 200,000
Token transfer, payload complexity
sendToken
60,000 - 100,000
Token type, destination chain
execute
100,000 - 300,000
Payload execution complexity
Integration Examples
Basic Integration
Token Transfer Integration
DeFi Integration
Security Considerations
Input Validation
Always validate inputs before calling gateway functions:
Access Control
Implement proper access control for sensitive functions:
Reentrancy Protection
Use reentrancy guards for functions that transfer tokens:
Upgradeability
The IU2U Gateway uses a proxy pattern for upgradeability:
Monitoring and Analytics
Event Monitoring
Monitor gateway events for cross-chain activity:
Transaction Tracking
Track cross-chain transactions:
Best Practices
1. Always Check Chain Support
2. Validate Contract Addresses
3. Handle Token Approvals
4. Implement Proper Error Handling
5. Use Events for Tracking
Resources
Last updated

