0

i am working on trying to get some data encoded/inserted into an ethereum transaction.

Let me describe my environment first, i am using Web3py, Ganache and Remix IDE. I am able to successfully communicate between the three as i can write python code in Jupyter Notebook which successfully interacts with the contract deployed on Remix. And i can see each and every transaction in Ganache.

Now, my task is to store some data on the Ethereum Blockchain ( not necessarily the mainnet, if it can be done on a local RPC or even a test net, it will be enough. )

I am trying to send the following Raw transaction

tx = {
    'nonce': nonce,
    'to': address,
    'value': web3.toWei(1, 'ether'),
    'gas': 2000000,
    'gasPrice': web3.toWei('10', 'wei'),
}

to my smart-contract, using

web3.eth.sendRawTransaction

however, i get the following error in web3py ( this is a huge error, but this is the part that seems pertinent, i will post whole error if you need me to. )

'message': 'VM Exception while processing transaction: revert', 'code': -32000

Then is tried to use this command

web3.eth.sendTransaction({
    'nonce': nonce,
    'to': address_of_contract,
    'value': web3.toWei(1, 'ether'),
    'gas': 2000000,
    'data' : '7b224e616d65223a202',
    'gasPrice': web3.toWei('10', 'wei'),
})

Whether i include the data field or exclude it in this command, it gives the same error;

'message': 'VM Exception while processing transaction: revert', 'code': -32000

Please help me out.

I just want to find a way to send data(some hexadecimal string or hex bytes) in a transaction.

Let me know what possibilities exist for any such functionality in Ethereum.

Thank You.

EDIT : Contract Code as requested by @iamdefinitelyhuman

pragma solidity ^0.4.17;

contract Inbox {
    string public message;
    string[] hex_storage;
    address owner;

     event printHex(string x);

    function Inbox(string initialMessage) public payable {
        owner = msg.sender;
        message = initialMessage;
    }

    modifier isOwner {
        require(msg.sender == owner);
        _;
    }

    function setMessage(string newMessage) public 
    {
        message = newMessage;
    }
        function getMessage() public view returns (string) 
        {
            return message;
        }

    function storeMember(string hex_data) public 
    {
        hex_storage.push(hex_data);
    }

    function showMember() public 
    {
        for (uint i=0; i<hex_storage.length; i++)
        {
            printHex(hex_storage[i]);
        }
    }

    function cleanOutBalance() isOwner public  
    {
        uint bal = address(this).balance;
        address(owner).transfer(bal);
    }

    function displayBalance() public view returns (uint)
    {
        uint bal = address(this).balance;
        return bal;
    }


}

So i know the Contract code is not perfect, but most functions perform rudmentary stuff ( get, set, pushing data into array )

i would like to target the storeMember function with my transaction. But, from what i have learned on Solidity, is that when you invoke a smart contract function from a front-end, the transaction contains some data of the targeted function in it's data field, hence it is impossible to alter that field if i am calling a Smart Contract function from the front-end. ( please correct me if i am wrong with this concept )

Therefore, i am trying to send a custom transaction (not a raw transaction), without invoking any function, to the contract. In the hopes that it may allow me to modify the Data field without any restrictions. ( I have also tried raw transactions, but they show the same error as listed above )

Please let me know if i can take any additional steps or precautions to allow me to encode data in the Data field of the transaction.

  • Try to specify from field as described in the doc github.com/ethereum/wiki/wiki/… – Badr Bellaj Aug 5 at 12:07
  • 1
    It would also be useful to see the code of the smart contract you are attempting to interact with. – iamdefinitelyahuman Aug 5 at 12:11
  • @BadrBellaj hey there. I have seen this wiki, but what i don't understand in that documentation is " a byte string containing the associated data of the message " what message is the wiki talking about ? is it the custom data i am trying to insert ? or is it something specified by the Ethereum protocol ? Also, Byte String ? i am sorry, but as far as i understand, a string should work, no ? or should i do some sort of manipulation or conversion in the hex data i am trying to encode in the transaction ? convert to bytes maybe ? if you can clear this up, it will help me tremendously ! – Muhammad Yasir Aug 6 at 17:45
  • @iamdefinitelyahuman i will display the code in my OP tomorrow, i don't have it right now. Thank you. – Muhammad Yasir Aug 6 at 17:56
  • @iamdefinitelyahuman please take a look at the edited OP – Muhammad Yasir Aug 7 at 17:56

Your Answer

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

Browse other questions tagged or ask your own question.