Low level interactions on Remix IDE – Remix IDE
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.
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
- Only fallback() is defined
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.
one can send value along with calldata.
2. Only receive() is defined
it will throw error on compilation itself : TypeError: Receive ether function must be payable, but is “nonpayable”
only value can be sent to contract. Sending calldata will show the error: ‘Fallback’ function is not defined
3. receive() & fallback() both are defined
receivelabelled aspayableandfallbackisnonpayable,
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.
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.
Published at Mon, 03 Feb 2020 12:28:05 +0000
{flickr|100|campaign}
