0

When I create a transaction like below

 App.contracts.Soccer.deployed().then(function(instance) {       
    return instance.purchaseShoes(name, age, { from: accounts[0], value: value});
 }).then(function() {
 ...

it creates an input data in transaction details from etherscan. Isn't input data only created when I passed it as a data parameter? (ex: { from: accounts[0], value: value, data: 'test data' }

When I decoded the input data by converting it to utf-8 from etherscan, although it was not totally readable, I saw one of the values were the data I passed it to purchseShoes function.

So my question is, why is it creating an input data when I didn't pass it as a data param? how can I prevent it from creating it?

1

The data you saw are exactly the data you passed as name, age. The web3, in the background packs function name, input parameters and so on in the data field of transaction so the EVM knows what function it should execute and what are the parameters for it. You can see in this asnwer how the data are created and encoded and then added to the transaction before the transaction is finally singed, you can see creation and signing of tx at the bottom.

I'm not really sure what web3 does to that data object in the last parameter, probably ignores it (my best guess). Params from that object are related to the transaction itself, like what account to use for signing, how many wei to send, gas limit, gas price etc.

  • Thanks for your answer. Have you ever used data object in the last parameter? I wonder if it can change the data I passed as name and age. – bbusdriver Apr 16 at 18:56
  • No, never tried it. There are also multiple versions of web3 out there that provide different handling of input data and transaction parameters, maybe some of them use that object...just guessing. – KwahuNashoba Apr 16 at 18:59
  • one more thing, you mentioned web3 packs... in the data field of transaction. Does that mean it is creating data object in the last parameter behind the scene although I did not explicitly added? – bbusdriver Apr 16 at 19:11
  • Never really dug into the web3 code, but there is no reason to put it there from my point of view. It's more likely that it's using all the data (function and transaction params (the {} object) you provided to create a signed transaction in a way similar or exact as in the code I've linked in my answer. – KwahuNashoba Apr 16 at 19:21

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.