0

I am using IPFS to store data [As per suggestion from an answer in ethereum stackexchange ,I couldnt find link to the question:( ]. The hash of file stored in ipfs is inserted into the data field of a transaction. But I couldnt find a way to access these datafields . Tried fetching transaction by using the transactionhash , but the retrieved result does not have a data field . Is there any function similar to eth.filter in web3 v1.0 ?.

function(req,res){
console.log(req.body)
web3.eth.getAccounts(function(e,accounts){

    web3.eth.personal.unlockAccount(accounts[0],req.body.pass, 1000000);
    web3.eth.sendTransaction({
        from:accounts[0],
        to:req.body.address,
        data: req.body.id
    }, function(error, hash){
       console.log(error)
       console.log(hash)
    });


})

}

Running the above code returns a transaction hash . req.body.id is fetched from an api endpoint which returns hash of the uploaded file . To list all transactions , I tried to use web3.eth.filter but it returned an error :

TypeError: web3.eth.filter is not a function

Then I console logged web3.eth and couldnt find any filter function in the log .Is there any function to list all the transactions from/to an address ?

4

2 Answers 2

1

Using web3 v1.0 I sent this transaction

eth.sendTransaction({
  from: account0,
  to: account1,
  value: 0,
  data: web3.utils.toHex("Hello World")
});

Now with the returned hash I can query the transaction (after it is mined) } eth.getTransaction("0x6c2135c..");`. And we get the resulting transaction

{
  blockHash: "0xb69212f..",
  blockNumber: 510,
  from: "0x9bc62f..",
  gas: 90000,
  gasPrice: 100000000000,
  hash: "0x6c2135c..",
  input: "0x48656c6c6f20576f726c64",
  nonce: 11,
  r: "0x49097a7..",
  s: "0x2b6ce95..",
  to: "0x7fe0197..",
  transactionIndex: 0,
  v: "0xec",
  value: 0
}

The field you have to look is input you can decode it web3.utils.toAscii("0x48656c6c6f20576f726c64"), it will return

"Hello World"

2
  • Thank you .But isnt storing transaction hashes to access data against the idea of blockchain .ie I can still manipulate the datastore containing the hashes .right ? Is there any alternative for eth.filter in api v1.0 . Commented Dec 18, 2017 at 10:46
  • I do not follow you but transaction hashes are inmutable, once in the blockchain you cannot change them, you can corrupt an instance of the blockchain but you cannot do this for every instance. I think eth.filter in web3 v0.20 only applies to contracts, the replacement in v1.0 should be web3.eth.subscribe, you should create a new question for that I'm not very familiar with v1.0 yet.
    – Ismael
    Commented Dec 18, 2017 at 12:31
0

To get data of any transaction you can use this API

https://ide.bitquery.io/Transaction-details_1

It gets you complete transaction detail and if you want you can get more details like event, call , transfer, balance update etc.

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.