4

The fallback function may receive additional data (exposed in msg.data). How can I send a transaction with additional data in Remix?

4 Answers 4

3

I do not believe you can send data using Remix at this time. What you can do is use Metamask to perform the same action.

If you are calling the fallback function, then you can simply open Metamask, send a transaction to the contract, and include the data in the Hex Data field of the transaction form.

You can use other clients like MyCrypto as well, but I do not believe you can perform this action in Remix.

2

Work-around

The accepted answer from above from shane is right that you cannot send data along directly in Remix even though you can do it with most wallets.

However, what you can do as a work-around is the following: create a very small contract in Remix, with a function that accepts an address, an amount and some data, like so:

pragma solidity >=0.5.0 <0.7.0;

contract sendData {

    function transferToWithData(address payable dest, uint amount, bytes memory data) public payable {

        dest.call.value(amount)(data);
    }
}

Once you have deployed this, you can call this function from within Remix with a recipient address, an amount and the data you would like to transfer. The contract will then send the amount including the data to the recipient address.

Test that it works

To test that this works, make a receiving contract like so:

pragma solidity >=0.5.0 <0.7.0;

contract receiveData {

    bytes public data;

    function () external payable {
        data = msg.data;
    }
}

Then invoke the transferToWithData function with the 3 arguments, for example like so:

"0x72db24a976ebbf64cd2d3c14f30e6db4ea812440", 1000, "0x00112244"

where the address, of course, must be that of the receiveData contract.

Then invoke in Remix the automatically created getter data, which will give you 0: bytes: 0x00112244, meaning that the recipient got the data.

In most user wallets the recipient will be able to view it, otherwise the transaction itself on the blockchain should be consulted.

Warning about using call with value

Note that when sending value this way, the receiving account could call back on this function in ways you would not expect. It is not recommended to send value this way as described here.

2

As of 2022, you can send ether to the contract with msg.data. For this purpose, just use calldata area. calldata input area is on the left-bottom corner of the screen and whatever you enter there will be evaluated as msg.data. However, it only accepts bytes data format.

1
  • web3.eth.abi.encodeFunctionSignature() can be used to produce bytes format of the data.
    – sametcodes
    Commented Sep 7, 2022 at 12:28
0

You can use the signature icon beside your account number to sign a message.

(The VALUE input before signing the message will be included in the transaction.)

You can then copy the signed message signature in the Low-Level Interactions field.

Sign message in Remix. Entered VALUE will be included in transaction.

Enter message to sign.

Copy signature of signed message.

Enter signature

7
  • The signature part isn't necessary for this answer, using CALLDATA should be enough for this answer. Please, don't copy & paste the same answer multiple times, if the questions are similar mark them as duplicates.
    – Ismael
    Commented Apr 18, 2023 at 17:16
  • @Ismael Yes, but CALLDATA requires a hashed input, and using "Signed Message" function has been the easiest way that I've found to manually generate a transaction that interacts with the contract.
    – juil
    Commented Apr 21, 2023 at 13:25
  • @Ismael Sorry, my intention wasn't to imply that the questions are duplicates, but the answer to both of them seem to be the same to me, even if what the asker is looking to do is different.
    – juil
    Commented Apr 21, 2023 at 13:26
  • The lowlevel CALLDATA content depends on the contract being called. It could be anything, the more common is to use a function call (4 bytes function id followed by the encoded parameters).
    – Ismael
    Commented Apr 21, 2023 at 16:23
  • @Ismael Is there a way to do that in remix?
    – juil
    Commented Apr 24, 2023 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.