2

How can I append some (extra) data to a transaction that calls a contract method (with given parameters)? The transaction has only one 'data' field which is used to serialize the method call.

If I would simply append more data at the end of the method call (expecting it to be ignored by the EVM, but useful for off-chain purposes), would that work or would it result in the transaction being rejected by the EVM?

This would be useful, for instance, in assigning an invoice-id to an ERC-20 transfer.

1

The EVM will pass your data unchanged to the contract. It will not make any assumption about it.

Solidity abi specification will ignore extra data. It is up to the contract to determine what to do with it. For example some contracts enforce the data to be of certain length to match the parameters it is expecting (search for short address attack for a vulnerability related to that).

If the contracts are yours then you should have no problem. If you want to be absolutely safe you have to define your own function with an extra parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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