Low level interactions on Remix IDE

enabling Fallback & Receive functions support

Aniket
Aniket
Feb 3 · 3 min read

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).

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

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.

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.

Remix IDE

In browser editor for developing, debugging and deploying Solidity contracts

Thanks to Yann Levreau and GrandSchtroumpf

Aniket

Written by

Aniket

Blockchain Engineer

Remix IDE

Remix IDE

In browser editor for developing, debugging and deploying Solidity contracts

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade