Like Ismael mention, you have to use hexToAscii with web3@^1.0
But looks like you are using it on the transaction.hash and not the transaction.input
EDIT: example:
Submit transaction:
const Tx = require('ethereumjs-tx');
const web3 = require('web3');
const data = web3.utils.toHex('Hello world!');
const rawTx = {
nonce: web3.utils.toHex(nonce),
gasPrice: web3.utils.toHex(gasPrice),
gasLimit: web3.utils.toHex(gasCost),
to: '0x0000000000000000000000000000000000000000',
value: '0x00',
data,
};
const privateKeyWithoutZero = privateKey.startsWith('0x') ? privateKey.slice(2, privateKey.length) : privateKey;
const privateKeyBuffer = new Buffer(privateKeyWithoutZero, 'hex');
const transaction = new Tx(rawTx);
transaction.sign(privateKeyBuffer);
const serializedTx = transaction.serialize();
web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
.on('transactionHash', (txHash) => {
console.log('Transaction hash', txHash);
})
.on('receipt', (receipt) => {
console.log('Transaction sent with sucess. debug:', receipt);
});
Then, getTransaction:
web3.eth.getTransaction('<TRANSACTION-HASH>')
.then((transaction) => {
const inputData = Web3.utils.hexToAscii(transaction.input);
console.log(inputData); // Hello world!
});
"around your parameterweb3.utils.hexToAscii("0x0c485e0f155f7f216d06e70ef85b684392c9b190c2f7c0af67ec1b56d6945498"). In any case it doesn't make much sense to usehexToAsciiwith a transaction hash or atransaction.input. It was intended to use on some fields that were generated byasciiToHexlikeblock.extraData.If you want to parse a transaction input then you need the contract abi and using a library like ethereumjs-abi to read the parameters values of the call.
– Ismael May 07 '18 at 20:29toHex(equivalent to today'sasciiToHex). It doesn't work in your case because it is a raw function call. As I said you will need the contract ABI and a ABI parser to extract info from the parameters of the call. – Ismael May 07 '18 at 21:50