logoAcademy

Interaction Flow With Fees

Go trhough the complete deployment flow and send an incentivized message.

Now we have all the Smart Contract 📜 set we can start sending incentivized cross-chain messages. Now let complete the flow

  • Deploy sender contract on C-Chain
  • Deploy receiver contract on myblockchain
  • Approve the sender contract to spend ERC20 funds from the message sender address
  • Send the message

Deploy Sender Contract

To deploy the sender contract run:

forge create --rpc-url local-c --private-key $PK contracts/interchain-messaging/incentivize-relayer/senderWithFees.sol:SenderWithFeesOnCChain
[⠊] Compiling...
[⠒] Compiling 2 files with Solc 0.8.18
[⠢] Solc 0.8.18 finished in 92.98ms
Compiler run successful!
Deployer: 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC
Deployed to: 0xa4DfF80B4a1D748BF28BC4A271eD834689Ea3407
Transaction hash: 0xb0ff20527818fcc0836944a13ddb3b336b95047d434bb52f6c064ab407950166

Save the Sender Contract Address

export SENDER_ADDRESS=0xa4DfF80B4a1D748BF28BC4A271eD834689Ea3407

Deploy Receiver Contract

Now, deploy the receiver contract.

forge create --rpc-url myblockchain --private-key $PK contracts/interchain-messaging/incentivize-relayer/receiverWithFees.sol:ReceiverOnSubnet
[⠊] Compiling...
[⠢] Compiling 1 files with Solc 0.8.18
[⠆] Solc 0.8.18 finished in 105.36ms
Compiler run successful!
Deployer: 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC
Deployed to: 0xe336d36FacA76840407e6836d26119E1EcE0A2b4
Transaction hash: 0x379f0a4b875effc9b80a33f039d9a49404514e7aabaef4490f57b56fb4818f65

Save the Receiver Contract Address

export RECEIVER_ADDRESS=0xe336d36FacA76840407e6836d26119E1EcE0A2b4

Approve ERC20 Token Expense

👩 The Message Sender (User) requires to approve the Cross-Avalanche L1 dApp as a spender on the ERC20 contract to be used as fee. To do that lets use the function "approve" on our deployed FEE contract.

cast send --rpc-url local-c --private-key $PK $ERC20_fee_address "approve(address,uint256)" $SENDER_ADDRESS 500000000000000

Send an incentivized message

cast send --rpc-url local-c --private-key $PK $SENDER_ADDRESS "sendMessage(address, string, address)" $RECEIVER_ADDRESS "Hello" $ERC20_fee_address

Verify message was received on Avalanche L1

cast call --rpc-url myblockchain $RECEIVER_ADDRESS "lastMessage()(string)"
"Hello"

Success! The message was received on the destination chain while incentivizing the Relayer.

On this page