I am able to send a transaction to the network but how can I get back that transaction especially it payload data?
You can get all transactions using GetBlockItems
endpoint.
If the transaction is in a block.
Do you mean getBlockItemStatus? And would it recover the data stored as a Register data?
For register data you can use GetBlockItemStatus
which will in particular return the data that was registered. See Protocol Documentation, the data_registered
variant.
I have tried retrieving the data but the data I sent is a simple text and now I am getting back a bunch of number like "“54657374”
Here is my retrieval function snippet:
const blockItem : BlockItemStatus = await client.getBlockItemStatus(transactionId);
if (blockItem.status !== 'finalized') {
return false;
}
const trxSummary: BlockItemSummary = blockItem.outcome.summary;
if (trxSummary.type !== 'accountTransaction') {
return false;
}
const trx = trxSummary.transactionType;
if (trx !== 'registerData') {
return false;
}
const data = trxSummary.dataRegistered.data.toString();
return data;
The data
is a byte array conceptually, represented as a hex string.
The hex string 54657374
when you decode it is the string Test
.
So the dataRegistered.data
is a hex string. You want to do something like
let str = Buffer::from(dataRegistered.data, 'hex').toString('utf8');
assuming you know the data it contains is a valid UTF8 string.
Thanks a lot. It worked.