logoAcademy

Interaction Flow With Fees

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

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 myblockchain --private-key $PK src/9-incentivize-relayer/senderWithFees.sol:SenderWithFeesOnCChain

Save the Sender Contract Address

export SENDER_ADDRESS=0x...

Deploy Receiver Contract

Now, deploy the receiver contract.

forge create --rpc-url myblockchain --private-key $PK src/9-incentivize-relayer/receiverWithFees.sol:receiverWithFeesOnCChain

Save the Receiver Contract Address

export RECEIVER_ADDRESS=0x...

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 local-c RECEIVER_ADDRESS "lastMessage()(string)"
Updated:

On this page

Edit on Github