How to get rawTx by txHash

Hi Team,
I am expecting to get rawTx from “eth_getTransactionByHash” but i don’t think it’s returned. or Could you share the API, which returns rawTx?

Hi @amol.damodar

By raw transaction do you mean the raw data of the transaction?

1 Like

Hi @johnversus, thank you for your response.

Same like response from https://etherscan.io/getRawTx?tx=0xcebf187a246c4aafc4137231a611d9bbaf121827d12f5a41176bbdc7f0e3fe03

and as i want to do it for ETH, BNB, MATIC, AVAX, expecting it from Moralis.

also, as i don’t see any APIs, i thought of building rawTx, but it’s not building perfectly, because when i try to decode build rawTx and try to get from , it fails

			EthTransaction transactionResponse = web3.ethGetTransactionByHash(transactionHash).send();
			Optional<Transaction> optionalTransaction = transactionResponse.getTransaction();

			if (optionalTransaction.isPresent()) {
				Transaction transaction = optionalTransaction.get();

				BigInteger nonce = transaction.getNonce();
				BigInteger gasPrice = transaction.getGasPrice();
				BigInteger gasLimit = transaction.getGas();
				String to = transaction.getTo();
				BigInteger value = transaction.getValue();
				String input = transaction.getInput();
				long chainId = transaction.getChainId();
				String maxFeePerGas = transaction.getMaxFeePerGas() != null ? transaction.getMaxFeePerGas() : null;
				String maxPriorityFeePerGas = transaction.getMaxPriorityFeePerGas() != null ? transaction.getMaxPriorityFeePerGas() : null;
				byte[] r = Numeric.hexStringToByteArray(transaction.getR());
				byte[] s = Numeric.hexStringToByteArray(transaction.getS());
				long v = transaction.getV();

				RawTransaction rawTransaction;

				if (maxFeePerGas != null && maxPriorityFeePerGas != null) {

					if(input == null || input.equals("0x")){
						rawTransaction = RawTransaction.createEtherTransaction(
								chainId,
								nonce,
								gasLimit,
								to,
								value,
								new BigInteger(maxPriorityFeePerGas),
								new BigInteger(maxFeePerGas)
						);
					}
					rawTransaction = RawTransaction.createTransaction(
							chainId,
							nonce,
							gasLimit,
							to,
							value,
							input,
							new BigInteger(maxPriorityFeePerGas),
							new BigInteger(maxFeePerGas)
					);
				} else {
					// Legacy transaction
					rawTransaction = RawTransaction.createTransaction(
							nonce,
							gasPrice,
							gasLimit,
							to,
							value,
							input
					);
				}

I think the RPC method which you are looking for is getRawTransactionByHash. We dont support this method in our RPC nodes.

The method getTransactionByHash decoded the raw hex data into readable data.

yes, we are expecting rawTx in response.

@johnversus do Moralis has any other API available?

Hi @amol.damodar No, we dont have any API to get the raw data. Our web3api focus on returning enriched data rather than raw data.

I remember @esther598 replied with below API, and it worked for me with quicknode. Thanks to @esther598.

Request:

curl --location 'https://d' \
--header 'Content-Type: application/json' \
--data '{
    "jsonrpc": "2.0",
    "method": "eth_getRawTransactionByHash",
    "params": [
        "0xef08b7a5a85b5b39608c3237d56d5a565b3a55dc3a506b403a663ce74c6423cd"
    ],
    "id": 1
}'

Response:

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": "0x02f90a1c8189058507004b33368507004b33658305e15694a7fd99748ce527eadc0bdac60cba8a4ef4090f7c880f15e8c0d5e8a000b909a4998183780000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000008c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000803000101000501000007c4000000000000000000000000000f15e8c0d5e8a000cb7f0bdcb06f954b5d5268310323eff71cc9605b57814f596584aa5c037f4507a4d73041008100000011951b667c1eced1c7d7d343c9de4593bd46cf68de706dd21199fecbb25f91f365df8866a3ac08eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeef128bfc3fbf9832181a25ac0d207842d66b715df6ea08cf52f025b9e2ed28788c277b1ccdb58d36aef599d259b7fc27171157a1cb4d6c7a58ed7927da34c26696b8b193d4419a095e826781f8853cab89d3ddeb72d738da93948069fca3389b900000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000006c90600000000000000000000005873429e52d338b0985319a5b203db21795cd816003201000000000000c800000000000000000000000000000000000000000000000000000efcee47256c00000000000000000000000000000000000000000d4b000000000f011806182b70000000000000000000000000000000000000000c5f000000000f0541c50aeae0000000000000000000000000000000000000000c47000000000f096b83fdaa50000000000000000000000000000000000000000c67000000000f0d9542f069c0000000000000000000000000000000000000000c41000000000f11bf01e32930000000000000000000000000000000000000000c6a000000000f15e8c0d5e8a0000000000000000000000000000000000000000c44000000000f1a127fc8a810000000000000000000000000000000000000000c49000000000f1e3c3ebb6780000000000000000000000000000000000000000c4d000000000f2265fdae26f0000000000000000000000000000000000000000c48000000000f268fbca0e660000000000000000000000000000000000000000c4c000000000f2ab97b93a5d0000000000000000000000000000000000000000c4e000000000f2ee33a866540000000000000000000000000000000000000000c5c000000000f330cf97924b0000000000000000000000000000000000000000c50000000000f3736b86be420000000000000000000000000000000000000000c5b000000000f3b60775ea390000000000000000000000000000000000000000c54000000000f3f8a36516300000000000000000000000000000000000000000c58000000000f43b3f5442270000000000000000000000000000000000000000c56000000000f47ddb436e1e0000000000000000000000000000000000000000c78000000000f4c077329a150000000000000000000000000000000000000000c7d000000000f5031321c60c0000000000000000000000000000000000000000c28000000000f545af10f202ed40000000000000000000000000000000000000c4f000000000f5884b001dfa0000000000000000000000000000000000000000c36000000000f5cae6ef49f0f380000000000000000000000000000000000000c20000000000f60d82de75e80000000000000000000000000000000000000000c25000000000f6501ecda1df0000000000000000000000000000000000000000c53000000000f692babccdd60000000000000000000000000000000000000000c26000000000f6d556abf9cd0000000000000000000000000000000000000000c55000000000f717f29b25c40000000000000000000000000000000000000000c34000000000f75a8e8a51bb0000000000000000000000000000000000000000c30000000000f79d2a797db20000000000000000000000000000000000000000c2a000000000f7dfc668a9a90000000000000000000000000000000000000000c29000000000f8226257d59ff9c0000000000000000000000000000000000000c22000000000f864fe4701970000000000000000000000000000000000000000c21000000000f8a79a362d8e0000000000000000000000000000000000000000c3e000000000f8ea362559850000000000000000000000000000000000000000c43000000000f92cd214857c0000000000000000000000000000000000000000c2f000000000f96f6e03b1730000000000000000000000000000000000000000c2d000000000f9b209f2dd6a0000000000000000000000000000000000000000c2e000000000f9f4a5e20960f380000000000000000000000000000000000000c27000000000fa3741d135580000000000000000000000000000000000000000c2c000000000fa79ddc0614f0000000000000000000000000000000000000000c11000000000fabc79af8d460000000000000000000000000000000000000000c0a000000000faff159eb93d0000000000000000000000000000000000000000bcd000000000fb41b18de5340000000000000000000000000000000000000000c00000000000fb844d7d112b0000000000000000000000000000000000000000c15000000000fbc6e96c3d220000000000000000000000000000000000000000c03000000000fc09855b69190000000000000000000000000000000000000000c1b000000000fc4c214a95100000000000000000000000000000000000000000c16000000000fc8ebd39c1070c80000000000000000000000000000000000000c1866838cf96c9ab6476e5cdf37abca8710b835cdbd8bf02a66d6ea9dd93d6cc160c71804e25d2ea9aa2c78db644dab241c1d3675dc5d13b60eb140a19ec527fd4de39eea131c000000450000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b400010100cbb25f91f365df88f128bfc3fbf9832181a25ac0d1c7d7d343c9de4593bd46cf68de706dd21199fe5873429e52d338b0985319a5b203db21795cd8160000000000000000000000000000000000000000000000000000000000000c4400000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000f15e8c0d5e8a0000000000000000000000000000000000000000000000000000000000000000000c001a0d77c07b3cfeb3319a48c1dfe1a0a55cfa3a3dd5236c95b40101451a1f3d93d16a034ea4300121edfb0dea5d3ed01bc35d6e1dfaf92e1a08d46c1225379114567bc"
}
1 Like