logoAcademy

Incentivize an AWM relayer

Add incentives to the basic send-receive contracts.

Add Incentives to our Sender Contract

Now that we have an ERC20 token deployed and some of those tokens in our account to incentivize our relayer, let's include the incentive in our Sender contract.

In the following contract, make sure to update destinationBlockchainID with your current deployment

src/9-incentivize-relayer/senderWithFees.sol
// (c) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
 
// SPDX-License-Identifier: Ecosystem
 
pragma solidity ^0.8.18;
 
import "@teleporter/ITeleporterMessenger.sol";
import {IERC20} from "@openzeppelin/contracts@4/token/ERC20/IERC20.sol"; 
 
contract SenderWithFeesOnCChain {
    ITeleporterMessenger public immutable messenger = ITeleporterMessenger(0x253b2784c75e510dD0fF1da844684a1aC0aa5fcf);
    /**
     * @dev Sends a message to another chain.
     */
    function sendMessage(address destinationAddress, string calldata message, address feeAddress) external {
        IERC20 feeContract = IERC20(feeAddress); 
        uint256 feeAmount = 500000000000000; 
        feeContract.transferFrom(msg.sender, address(this), feeAmount);
        feeContract.approve(address(teleporterMessenger),feeAmount); 
 
        messenger.sendCrossChainMessage(
            TeleporterMessageInput({
                // Replace with blockchainID of your L1 (see instructions in Readme)
                destinationBlockchainID: 0x108ce15038973062d8628fd20c8c657effe993dd8324297353e350dfc05dacad,
                destinationAddress: destinationAddress,
                feeInfo: TeleporterFeeInfo({feeTokenAddress: feeAddress, amount: feeAmount}), 
                requiredGasLimit: 100000,
                allowedRelayerAddresses: new address[](0),
                message: abi.encode(message)
            })
        );
    }
}

Notice, our contract implementing Fees now needs to include the functionality we described in the fee flow section:

  • Import IERC20 and create the fee contract interface instance
  • 📜The Cross-Avalanche L1 dApp transfers the ERC20 fee amount to the control of the Cross-Chain dApp contract.
  • 📜Cross-Avalanche L1 dApp needs to implement the approval for the Interchain Messaging contract of these ERC20 tokens.
  • Include the TeleporterFeeInfo struct in the message.

On this page