How to extract Ethereum Blockchain data

0 votes

I am trying to extract the data from Ethereum Blockchain. I have used an event in smart contract to get block data and I’m trying to extract like this:

gopi145@ubuntu:~/EventRegistration-POC/EventRegistration$ truffle console

truffle(development)> web3.eth.getTransaction('0x35e92857102b0dbacd43234d1ea57790405eb9bef956b245c6b7737bc23d011b')

{ hash: '0x35e92857102b0dbacd43234d1ea57790405eb9bef956b245c6b7737bc23d011b',

  nonce: 4,

  blockHash: '0x7c790dae57babfe40d68d8aad94913c2b748501c5734aec86cc3fcf0afc4f154',

  blockNumber: 5,

  transactionIndex: 0,

  from: '0x031e060414a0d2573f5b10bc75c0894d72288292',

  to: '0xa88a366e888bbccfb78092957ffc7760bc7c6db1',

  value: BigNumber { s: 1, e: 18, c: [ 60000 ] },

  gas: 200000,

  gasPrice: BigNumber { s: 1, e: 0, c: [ 1 ] },

  input: '0xa28f161c00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000b6d40676d61696c2e636f6d000000000000000000000000000000000000000000' }

truffle(development)>

But for some reason I am not able to decode the block. Need help.

Jul 30, 2018 in Blockchain by digger
• 26,740 points
1,702 views

1 answer to this question.

0 votes

You are using web3.eth.getTransaction(txHash)

web3.eth.getTransaction(txHash) will only return info like like blockHash, transactionIndex, from, to, etc.

You have to register the event using web3js.

This is the code I used:

Solidity code:

pragma solidity ^0.4.17;

//Contract for storing ticket info

contract TicketRes {

  event on_success_booking(address userId, string bookingId, string emailId);

  //Ticket info having two storage values i.e email and userID

  struct BookingInfo{

     string emailId;

     address userId;

  }

  //Map for saving all the info, assuming all ticket has unique id as key. Value is ticket info

  mapping(bookingId=>BookingInfo) internal info;

  function Book() public {

  }

   //Method will save all basic info, and will raise event.

  function onBookingCompleted(address id, string bookingId, string emailId) public {

       info[bookingId] = BookingInfo(emailId,userId);

       on_success_booking(id, bookingId, emailId);

  }

 //You can get info by using bookingid at any point of time.

 function getBookingInfo(string bookingId) public constant returns(string, address){

       return (info[bookingId].emailId, info[bookingId].userId);

 }

}

Now Javascript code:

// Contract deployed address.

var contractAddress = "0x06433f4fc50423f71329597f50fb0a42cfecb11f";

if (typeof web3 !== 'undefined') {

     web3 = new Web3(web3.currentProvider);

} else {

     // set the provider you want from Web3.providers

     web3 = new Web3(new Web3.providers.HttpProvider("http://127.0.0.1:8545"));

}

//Open build folder and you will find contact json file copy the appropriate JSON and paste it there.

var contractABI = web3.eth.contract(/** ABI Here **/);

//Connected contract to your local network

var contract = contractABI.at(contractAddress);

//Loading booking event function.

var booking_event = web3.sha3('on_success_booking(address,string,string)');

//Watching events, when onBookingCompleted() tran's mined then event get triggered. You can get all previous events also. for that need to apply filters.

booking_event.watch((error, result) => {

   if(error){

       console.log("error",error);

   }

   console.log("Result", result); //result.args holds values, result.args.id, result.args.bookingId and result.args.emailid

 });

answered Jul 30, 2018 by slayer
• 29,370 points

Related Questions In Blockchain

+1 vote
1 answer

How to store state data in Ethereum blockchain?

You won't have to overwrite the whole ...READ MORE

answered Apr 25, 2018 in Blockchain by Shashank
• 10,400 points
971 views
0 votes
0 answers
0 votes
1 answer

How to make sure transactions take no fee in a private Ethereum blockchain?

In a private ethereum network you have ...READ MORE

answered Mar 26, 2018 in Blockchain by Christine
• 15,790 points

edited Mar 26, 2018 by Christine 1,567 views
0 votes
1 answer

How to retrieve data from a block to a blockchain?

web3.eth.getTransaction(txHash) will returns transaction details like blockHash, transactionIndex, ...READ MORE

answered Jun 27, 2018 in Blockchain by Perry
• 17,100 points
3,959 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
0 votes
1 answer

How to create a Genesis Block in a Private Network?

{     "nonce": "0x0000000000000042",     "difficulty": "0x000000100",     "alloc": {     },     "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",     "coinbase": "0x0000000000000000000000000000000000000000",     "timestamp": "0x00",     "parentHash": ...READ MORE

answered Jul 12, 2018 in Blockchain by digger
• 26,740 points
2,002 views
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 26,740 points
1,003 views
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP