Struggling to publish textual data to a stream?

+1 vote

Apologies, I am new to Multichain and I have some issues when publishing textual data to a stream in Multichain 2.0 Alpha 2.

I have created a stream and I have used these two commands following your API guidelines:

publish stream1 "key1" "{"text":"hello world"}"

publish stream1 "key1" {"text":"hello world"}

But both return an error "data should be hexadecimal string or recognized object"

When you state "textual data", what is it exactly that you mean? Is it not possible to simply associate a string to a key like so:

publish stream1 "key1" "hello world"

Thanks,

Christopher

 

asked Mar 9, 2018 by cs1409

1 Answer

+1 vote
 
Best answer

Assuming you're using multichain-cli on Linux, the correct escaping is:

publish stream1 key1 '{"text":"hello world"}'

answered Mar 11, 2018 by MultiChain
selected Mar 12, 2018 by cs1409
Thanks, me being dumb, I was publishing the key as a string.
When using this through a Java RPC, are we expected to pass in the key as a string and the value as a string in the form as written above?

ArrayList<Object> params = new ArrayList<Object>();

params.add("stream1");
params.add("key3");
params.add("{\"text\":\"hello world\"}"); //value
You would need to consult your Java documentation. In general, the stream name and key are strings. But it is likely you need to pass in an object for the third parameter, rather than a pre-formatted JSON representation of that object.
Exactly what you said, except I needed to call .toString() on the JSON object as I passed it through. Thanks
...