Cross-Chain Calls

Execute smart contract functions across different blockchain networks using DI Gateway's secure cross-chain communication protocol.

Call Types

Simple Contract Call

Execute a function on a destination chain without token transfers:

await di.gateway.callContract({
  destinationChainId: 56, // BSC
  destinationContract: '0x742d35Cc6634C0532925a3b8D400E4C0C0b8C8e0',
  payload: encodedFunctionCall,
  gasToken: 'DUSD',
  gasLimit: 200000
});

Contract Call with Token Transfer

Send tokens along with the contract call:

await di.gateway.callContractWithToken({
  destinationChainId: 137, // Polygon
  destinationContract: '0x742d35Cc6634C0532925a3b8D400E4C0C0b8C8e0',
  payload: encodedFunctionCall,
  symbol: 'DUSD',
  amount: ethers.parseEther('1000'),
  gasToken: 'DUSD',
  gasLimit: 300000
});

Function Encoding

Basic Function Call

Complex Function Call

Execution Flow

Message Creation

Message Execution

Gas Management

Gas Estimation

Gas Token Options

Advanced Features

Batch Calls

Conditional Execution

Error Handling

Common Errors

Retry Mechanism

Monitoring & Tracking

Message Status

Event Monitoring

Best Practices

Security

  1. Validate Inputs: Always validate function parameters

  2. Access Control: Implement proper access controls on target contracts

  3. Reentrancy Protection: Use reentrancy guards

  4. Gas Limits: Set appropriate gas limits

Efficiency

  1. Batch Operations: Group multiple calls when possible

  2. Gas Optimization: Use efficient encoding

  3. Minimal Data: Send only necessary data

  4. Caching: Cache frequently used data

Reliability

  1. Error Handling: Implement comprehensive error handling

  2. Retry Logic: Add retry mechanisms for failed calls

  3. Monitoring: Monitor call status and results

  4. Fallback: Have fallback mechanisms for critical operations

Integration Examples

DeFi Protocol Integration

NFT Cross-Chain Transfer

Governance Cross-Chain Execution

Last updated