Low level interactions on Remix IDE

enabling Fallback & Receive functions support

Aniket
Remix Project
3 min readFeb 3, 2020

--

Prologue

With Solidity v0.6.0 release, unnamed function in Solidity (usually called as fallback) has been split in two: fallback& receive .

Users were looking for a feature in remix where they can send the value directly to a smart contract to test various functionalities even before the function split.

(Read more about receive/fallback functions here)

Introduction of Low level interactions

With v0.9.3 release, Remix IDE introduced a feature to enable low level interactions with each deployed smart contract. With this feature, one can test the functionality of receive& fallbackfunctions.

Low level interactions can be made by passing calldata (which is accessed as msg.datainside smart contract) & value (which is accessed as msg.valueinside smart contract). Although these fields are not mandatory.

For value, it uses the already available value field (which is also used in normal method calls).

Value field

For calldata, a new text field is introduced corresponding to each contract.

New Calldata field

To execute low level interaction, one can fill up these fields and click on the Transact button to send a transaction.

One can see in Remix console which method is called according to filled inputs.

fallback function call
receive function call

Note: For now, low level interactions are available for the contracts which defined receive or/and fallback functions.

Use cases

  1. Only fallback() is defined
  • Not labelled as payable

Sending some ether value to it with show the error: “In order to receive Ether transfer the contract should have either ‘receive’ or payable ‘fallback’ function”

Sending some calldata will execute the functionality of fallbackfunction.

  • Labelled as payable

one can send value along with calldata.

2. Only receive() is defined

  • Not labelled as payable

it will throw error on compilation itself : TypeError: Receive ether function must be payable, but is “nonpayable”

  • Labelled as payable

only value can be sent to contract. Sending calldata will show the error: ‘Fallback’ function is not defined

3. receive() & fallback() both are defined

  • receive labelled as payable and fallbackis nonpayable,

sending value or calldata only will be fine. If value and calldata are sent together, it will throw run-time error as fallback will be called with calldata but it is not payable so cannot accept value.

  • Both labelled as payable

For only calldata fallbackis called, for only value, receive is called. For calldata and value both, fallback is called.

Thus, one can use low level interactions on Remix IDE.

Epilogue

Remix Team always works hard to provide users more features with high flexibility & less complexity.

If you still have any queries/feedback regarding low level interactions on Remix, you can open issue on our github or discuss it in our gitter channel.

--

--