0

So I was playing around with the web3, but having problem to get the transactions from a block (following https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethgetblock)

var BlockPromise = web3.eth.getBlock('pending', true);
console.log("Block TX: " + BlockPromise.transactions[0]);

I would expect to get a transaction. However, I am only getting a [object Object]

What is my mistake? FYI: I do not have a coding degree.

  • 1
    [object Object] is what JavaScript prints out when trying to convert an object to a string. Try just console.log(Block.transactions[0]);. That should display the full object structure. – user19510 Jun 27 '18 at 16:47
1

The following works for me:

(async function() {
  var BlockPromise = await web3.eth.getBlock('pending', true);
  console.log("Block TX: " + JSON.stringify(BlockPromise.transactions[0], null, 2));
})();

JSON.stringify(object, null, 2) prints the entire object instead of just [object Object]

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.