I want to create a raw transaction (without signing it) and get its hash in hex format. The official TRON API normally returns a JSON for creating transactions. Does anybody know how to do this?
Asked
Active
Viewed 878 times
1
-
Have you got the solution? – Abhishek Pandey Mar 27 '22 at 14:46
-
It seems TRON's wallet-cli can generate it but it didn't work for me. – Foad Mar 29 '22 at 17:24
2 Answers
1
You can just call the api with your transaction details abd get transaction back
const data = {
to_address: toHex(to),
owner_address: toHex(from),
amount: amount,
};
let transaction = await tronWeb.fullNode.request('wallet/createtransaction', data, 'post');

user2800040
- 143
- 2
- 13
1
If I get you right you need the raw hex representation of not signed transaction. For this purpose you can use the tronweb library, they have APIs to create TRX, trc10 or token transfer transaction and return both JSON and hex representation: https://developers.tron.network/v3.7/reference/sendtrx
Here it the example from the mentioned docs:
tronWeb.transactionBuilder.sendTrx("TVDGpn4hCSzJ5nkHPLetk8KQBtwaTppnkr", 100, "TNPeeaaFB7K9cmo4uQpcU32zGK8G1NYqeL");
returns
{
"visible": false,
"txID": "9f62a65d0616c749643c4e2620b7877efd0f04dd5b2b4cd14004570d39858d7e",
"raw_data": {
"contract": [
{
"parameter": {
"value": {
"amount": 100,
"owner_address": "418840e6c55b9ada326d211d818c34a994aeced808",
"to_address": "41d3136787e667d1e055d2cd5db4b5f6c880563049"
},
"type_url": "type.googleapis.com/protocol.TransferContract"
},
"type": "TransferContract"
}
],
"ref_block_bytes": "0add",
"ref_block_hash": "6c2763abadf9ed29",
"expiration": 1581308685000,
"timestamp": 1581308626092
},
"raw_data_hex": "0a020add22086c2763abadf9ed2940c8d5deea822e5a65080112610a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412300a15418840e6c55b9ada326d211d818c34a994aeced808121541d3136787e667d1e055d2cd5db4b5f6c880563049186470ac89dbea822e"
}

Nick
- 144
- 1
- 4