Hello all of you. This is my first post here, so pardon any commonplace mistakes.
First let me explain my development environment. I am using Ganache for a experimental blockchain, Jupyter Notebook to play around with the Web3py front-end code and Remix for the Solidity smart contract code.
All 3 tools are communicating through a custom RPC ( through 127.0.0.1:7545 ).
I am trying to insert some custom data ( a string ) to the Data field of the transaction.
I succeed at doing this while i am transacting between two Ethereum Accounts;
web3.eth.sendTransaction({
'from' : dummy_account_1,
'nonce': nonce,
'to': dummy_account_2,
'value': web3.toWei(1, 'ether'),
'data' : my_custom_string,
'gas': 3000000,
'gasPrice': web3.toWei('50', 'gwei'),
})
However, when i try to do the exact same thing with a smart contract,
web3.eth.sendTransaction({
'from' : dummy_account_1,
'nonce': nonce,
'to': smart_contract_address,
'value': web3.toWei(1, 'ether'),
'data' : my_custom_string,
'gas': 3000000,
'gasPrice': web3.toWei('50', 'gwei'),
})
i get the following error
'message': 'VM Exception while processing transaction: revert', 'code': -32000
This brings to mind a few observations;
I know that the data field has different uses. If a contract is being created, the data field of the corresponding transaction will contain the contract creation code. If a function from the smart contract is being called, the data field of the transaction involved will contain function invocation data. Account to account transactions simply ignore the data field as of yet.
Would it be possible to send a transaction to the contract that would not call any function in the smart contract at all ? instead the DATA field would only contain some arbitrary string.
The reason for doing what is mentioned in point 2, is to transfer some ether to the contract, while keeping some pertinent and relevant information about that transfer in the data field.
My main intention is to modify that data field by inserting some data into it myself, and to send the corresponding transaction to the Smart Contract.
Hence, if anyone could shed some light on the issue, suggest any plausible alternative methods and help me clear up any misconceptions i might have about the Ethereum protocol or maybe even Solidity itself, i would be most grateful.
Thanks for your message! Unfortunately, I do not see a way to do what you are trying to accomplish. Sending a message to a smart contract (including sending Ether) always executes the smart contract and this means that the smart contract interprets the data being sent to it as payload for its invocation. You can only send "auxiliary data" if the smart contract is prepared to deal with it.
Thanks for your message! Unfortunately, I do not see a way to do what you are trying to accomplish. Sending a message to a smart contract (including sending Ether) always executes the smart contract and this means that the smart contract interprets the data being sent to it as payload for its invocation. You can only send "auxiliary data" if the smart contract is prepared to deal with it.
First of all, thank you for the relatively prompt response, i highly appreciate that !
I feared this would be the case, that one would not be able to send any custom string in the transaction 'data' field when communicating b/w a contract and a ethereum account.
On the flip side, you did mention the possibility of "auxiliary data" .
can you please elaborate what is this "auxiliary data" ?
also, an example of some auxiliary data being handled by a smart contract, would be highly appreciated
It is not a fixed term. If you have a contract that takes a certain parameter but does not really use it, then that could be used as auxiliary data.
It is not a fixed term. If you have a contract that takes a certain parameter but does not really use it, then that could be used as auxiliary data.
understood.
can you please suggest any relevant reading resources or documentation that further describe such a case in detail ?
preferably with code examples, if possible.
i need to study this very urgently for a project.
Many thanks !
If you know the contract, you can always append more data, but this is not guaranteed to not have any other side-effects. It just strongly depends on the actual contract. I'm closing this for now, I think https://ethereum.stackexchange.com/ would be a better place for this discussion.