Overview
The Incrementor contract demonstrates cross-chain messaging by incrementing a counter on a destination chain from a source chain. It showcases the BridgeAppBase pattern for building cross-chain applications. Contract Location:contracts/examples/Incrementor.sol
How It Works
Contract Code
Incrementor.sol
Deployment Steps
1. Deploy Contracts
Deploy on Testnet
2. Configure Addresses
Updateexamples/src/incrementorScripts/constants.ts with deployed addresses:
constants.ts
3. Link Contracts
Link Contracts
Sending a Message
Send Cross-Chain Message
- Call
send()on BSC testnet - Emit a
Sentevent with submissionId - Oracles observe and sign the message
- Message is executed on Kovan
claimedTimesis incremented
Tracking the Transaction
Use the deBridge explorer to track your cross-chain transaction:- Testnet: https://testnet-explorer.debridge.finance/
- Mainnet: https://mainnet-explorer.debridge.finance/
Verifying the Result
Check Counter Value
claimedTimes value has increased.
Key Concepts
BridgeAppBase Pattern
The Incrementor extendsBridgeAppBase, which provides:
- Access Control: Only authorized cross-chain addresses can call functions
- Chain Mapping: Track which addresses on which chains are allowed
- Pausability: Emergency pause functionality
onlyControllingAddress Modifier
Security Pattern
Using the Live Example
There’s a deployed Incrementor contract on BSC testnet:- Address:
0x375675FD702DAeeD35AEBc4fe613D3b088571644 - BSCscan: https://testnet.bscscan.com/address/0x375675FD702DAeeD35AEBc4fe613D3b088571644
send() function directly from BSCscan to see cross-chain messaging in action.
Common Issues
Message not executed on destination
Message not executed on destination
Possible causes:
- Insufficient execution fee
- Contracts not properly linked
- Destination chain not supported
- Check submissionId in explorer
- Verify contract configuration with
getContractAddressOnChainId() - Manually claim if execution fee was 0
Transaction reverts
Transaction reverts
Possible causes:
onBridgedMessagenot public/external- Missing
onlyControllingAddressmodifier - Insufficient gas limit
- Review contract implementation
- Check function visibility
- Increase execution fee for more gas
Related Examples
Sending ETH
Transfer native tokens cross-chain
Cross-Chain Calls
Advanced cross-chain patterns