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

Save the sender contract address to an enviroment variable

export SENDER_ADDRESS=0x...

Deploy Receiver Contract

Now, deploy the receiver contract.

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

Save the receiver contract address to an enviroment variable

export RECEIVER_ADDRESS=0x...

Approve ERC20 token expense

👩 The Message Sender (User) requires to approve the Cross-Subnet 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.

//APPROVE OUR USER TO SPEND ERC20 
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 Subnet

cast call --rpc-url local-c RECEIVER_ADDRESS "lastMessage()(string)"
Updated:

On this page

Edit on Github