0

1) First, I got the input

console.log(web3.eth.getTransaction('0x725fc75264726f409793164e336e7d5ed35df8d2be469a0cc1a3a8cc4756b9b9').then((i) => console.log(i) ));

2) I manually pasted the input from the data, in both abi encoder and toAscii methods

console.log(abiDecoder.decodeMethod("0x0b3ee5dc000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000119fbd8f9c700000000000000000000000000000000000000000000000000000000000000036d64760000000000000000000000000000000000000000000000000000000000");

 console.log(web3.utils.toAscii("0x0b3ee5dc000000000000000000000000000000000000000000000000000000000000........................."))

my output

>åÜ@ûØùÇmdv

but I have inserted

"mdv",1233

my solidity code

 pragma solidity ^0.4.17;

contract hotelbooking {

struct hotel {
  string HotelName;
  uint256 BookingNumber;
}

hotel[] HotelBookings;

function  HotelTranscation(string _HotelName,uint256 _BookingNumber) public {

  hotel memory temphotel = hotel(_HotelName,_BookingNumber);
  HotelBookings.push(temphotel);
}

    function GetHotelBooking(uint _num) public view returns(string, uint256) {
        return (HotelBookings[_num].HotelName, HotelBookings[_num].BookingNumber);

    }

1) Everything is working fine when using index for getting the data.

2) But I want to get the data by using transaction hash, please help me.

3) I have used online compiler remix to develop the code.

  • Are you sure, your input for uint256 _BookingNumber parameter was '1233'? I'm getting 1211111111111 for this input. – sp4c3 Jan 21 '19 at 12:04
0

You need ABI of you contract to get data correctly. This code snippet might help. I'll add more details when I have some time.

const abi = require('ethereumjs-abi');

function checkDecoding() {
  const abi = require('ethereumjs-abi');
  let params = ["mdv",1233]
  let contractABI = [ 'string', 'uint256']
  let encoded = abi.rawEncode(contractABI, params)
  let data = Buffer.from(encoded)
  let decoded = abi.rawDecode(contractABI, data)
  console.log(`Decoded: ${JSON.stringify(decoded, null, '  ')}`)
}
| improve this answer | |
  • Thanks but i want to get data from transcationhash which we get from the etherscan – md venkatesh Jan 21 '19 at 12:54

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.