8

I have initiated and mined a transaction between two accounts. I also included a data field in this transaction. This is just random hex data. Here is the command:

eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:web3.toWei(1,"ether"),data:"4e4f"})

Now, from the transaction hash, I can get this data (It's in the input field):

eth.getTransaction("<transaction hash>")
{
  blockHash: "0xfa62730b0f9e310cd07d615b78857e338e845b9098c26f861e2713c5f690497d",
  blockNumber: 15,
  from: "0x37e5a459dbd48d4d9874e13cc334dab30373cece",
  gas: 90000,
  gasPrice: 20000000000,
  hash: "0x2beef248d7d690d95cd1da22c8bf12937d323b197430e5a384cf4259db290bef",
  input: "0x4e4f",
  nonce: 2,
  to: "0xe1e09a6f9504d42e2e63e1b21447f4410159cf24",
  transactionIndex: 0,
  value: 1000000000000000000
}

But, I want to retrieve this data using the recipient account address

0xe1e09a6f9504d42e2e63e1b21447f4410159cf24

We can get the balance of this account using eth.getBalance(account_address). Along with the ether, I am also sending the data to this account (Is this not how it works?). So, is there an eth.getData/eth.getInput function similar to this to find the data received by an account?
Where is this data actually being stored in my private blockchain?

1 Answer 1

7

The data you're sending is part of the transaction, but it is not "added" to the account. There is storage associated with accounts (accessed via eth.getStorageAt(address,location)) but it will be empty unless a contract stores data there.

Since the data is associated only with the transaction, not with the account, the best way to access it is to use filters

var filter = eth.filter({fromBlock:0,toBlock:"latest", address:eth.accounts[1]});
var data = [];
filter.get(function(error,result){
    data.append(eth.getTransaction(result.transactionHash).data);
});

console.log(data)

Alternatively, you could create a contract that simply records all data sent to it:

contract Store {

    bytes[] public data;

    function(){
        data.push(msg.data);
    }
}

Then just fetch the data with store.data(index);

1
  • 1
    This line "var filter = eth.filter({fromBlock:0,toBlock:"latest", address:eth.accounts[1]);" maybe need a "}" no?
    – Gawey
    Commented May 11, 2017 at 10:08

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.