2

I use iota/Cliente, to submit a message with some data from a json file. Now i try to get this data using getMessage() with the messageId or Index.

I try this:

const client = new ClientBuilder().build();

const message = await client.getMessage().data("ddd5a550d5df1094e7badddd8a857f64d15a708f1972c81d7a88fbcc8f9b2170") console.log(message);

But only get information from the message, childs, network etc but no data. Any idea?

mihi
  • 7,324
  • 2
  • 15
  • 34
JuanHost
  • 83
  • 6

1 Answers1

2

The data is inside of the indexation payload, you can get it like this

    const message = await client.getMessage().data("ddd5a550d5df1094e7badddd8a857f64d15a708f1972c81d7a88fbcc8f9b2170")
    const decoded = new TextDecoder().decode(new Uint8Array(message.message.payload.data.data));
    console.log(JSON.stringify(JSON.parse(decoded), null, 1));
Thoralf
  • 166
  • 4
  • Thanks men, it work well when i use it in a simple node project. But when i try it in a node API Express project (I'm working now) i have a json error:

    SyntaxError: Unexpected end of JSON input at JSON.parse ()

    It's the same, any idea?

    – JuanHost May 18 '21 at 02:13