logoAcademy

Introduction

Learn how to call another contract function after send tokens to another L1s.

In addition to supporting basic token transfers, the token transferrer contracts offer a sendAndCall interface for bridging tokens and using them in a smart contract interaction all within a single Interchain Messaging message. If the call to the recipient smart contract fails, the transferred tokens are sent to a fallback recipient address on the destination chain of the transfer. The sendAndCall interface enables the direct use of transferred tokens in dApps on other chains, such as performing swaps, using the tokens to pay for fees when invoking services, etc.

Teleporter Messenger has the ability to receive cross-chain messages on the destination chain and casts related messages to the TeleporterMessage struct. It then sends these messages to the Home/Remote Transferrer contract, and handles them as SEND or CALL, as implemented in TokenHome.sol or TokenRemote.sol.

In this section we will cover the usage of the CALL message type with an example implementation.

When sendAndCall function is triggered, the following actions are taken;

  • The Transferrer Contract grants an allowance to spend tokens on the destination contract.
  • The Transferrer Contract encodes the received message as parameters for the receiveToken function, as defined in the IERC20SendAndCallReceiver or INativeSendAndCallReceiver interface.
  • The Transferrer Contract checks whether the destination contract's function execution is successfull.
  • The Transferrer Contract retrieves the remaining allowance to check if there are any unspent tokens exists.
  • The Transferrer Contract removes the allowance for the destination contract.
  • The Transferrer Contract sends the remaining tokens to the fallback recipient. If the destination contract fails to execute the function, the full amount will be sent to the fallback recipient.

Prerequisites

The following prerequisites were covered in previous sections, so you should have already deployed the following contracts before starting this chapter:

  • Base ERC20 Token on L1
  • Home Transferrer Contract on L1
  • Remote Transferrer Contract on Fuji
  • A Running AWM-relayer from your L1 to Fuji

On this page