Performing a Smart Deposit

A Smart Deposit is a deposit that moves funds from L1 to L2 and then triggers subsequent actions. For example, a user can deposit funds and transfer those funds to another recipient, such as an exchange.

The depositWithMessage function enables a Smart Deposit. depositWithMessage is similar to the deposit function, with an additional 256-bit message, which can contain instructions for executing additional actions.

Upon completion, the depositWithMessage function triggers a call to a callback function, named on_receive, on the L2 contract that receives the deposit. The on_receive function receives the deposit message as input.

on_receive must return true for the deposit to succeed. If on_receive returns false, or if the recipient contract does not include the on_receive function, the depositWithMessage function’s L1 handler fails. The user can recover their funds using the depositWithMessageCancelRequest function.

To enable Smart Deposits in your application:
  1. Implement the on_receive function in the L2 contract that should receive deposits.

  2. Use the depositWithMessage function to transfer funds from L1 to L2.

Additional resources