Help with Streams Create

+1 vote

Hello - I am working with streams and want to know if a sample code can be available on how to use the custom fields options during stream creation. If you could also highlight possible usages of these fields .

createtype=stream name open
({"custom-field-1":"x",...})

 

 
Thanks
asked Oct 24, 2016 by 06arnab

1 Answer

0 votes

Here's an example of how to use it:

create stream stream1 true '{"key1":"value1","key2","value2"}'

answered Oct 25, 2016 by MultiChain
Hi, i'm having trouble with curl command for creating streams with custom fields, I think its because of the single and double quotes.

please correct command below:

not working: curl --user multichainrpc:DgUzSVgbjgiyM9q6UxLVgKqVqaMgryxBJ5fP65QvZ1Y7 --data-binary '{"jsonrpc": "1.0", "id":"chain1", "method": "create", "params": ["stream", "stream_test", false, "{\"register_num\"=\"1\",\"transnum\"=\"22\"}"] }' -H 'content-type: text/plain;' http://127.0.0.1:9262

not working: curl --user multichainrpc:DgUzSVgbjgiyM9q6UxLVgKqVqaMgryxBJ5fP65QvZ1Y7 --data-binary '{"jsonrpc": "1.0", "id":"chain1", "method": "create", "params": ["stream", "stream_test", false, "'{\"register_num\"=\"1\",\"transnum\"=\"22\"}'"] }' -H 'content-type: text/plain;' http://127.0.0.1:9262

not working: curl --user multichainrpc:DgUzSVgbjgiyM9q6UxLVgKqVqaMgryxBJ5fP65QvZ1Y7 --data-binary '{"jsonrpc": "1.0", "id":"chain1", "method": "create", "params": ["stream", "stream_test", false, "\'{\"register_num\"=\"1\",\"transnum\"=\"22\"}\'"] }' -H 'content-type: text/plain;' http://127.0.0.1:9262

not working:
curl --user multichainrpc:DgUzSVgbjgiyM9q6UxLVgKqVqaMgryxBJ5fP65QvZ1Y7 --data-binary '{"jsonrpc": "1.0", "id":"chain1", "method": "create", "params": ["stream", "stream_test", false, "{register_num=1,transnum=22}"] }' -H 'content-type: text/plain;' http://127.0.0.1:9262

not working:
curl --user multichainrpc:DgUzSVgbjgiyM9q6UxLVgKqVqaMgryxBJ5fP65QvZ1Y7 --data-binary '{"jsonrpc": "1.0", "id":"chain1", "method": "create", "params": ["stream", "stream_test", false, "'{register_num=1,transnum=22}'"] }' -H 'content-type: text/plain;' http://127.0.0.1:9262

it works without the custom fields:
curl --user multichainrpc:DgUzSVgbjgiyM9q6UxLVgKqVqaMgryxBJ5fP65QvZ1Y7 --data-binary '{"jsonrpc": "1.0", "id":"chain1", "method": "create", "params": ["stream", "stream_test", false] }' -H 'content-type: text/plain;' http://127.0.0.1:9262

TIA
You're sending a JSON payload in the API request, so you don't need further escaping. Try:

curl --user multichainrpc:DgUzSVgbjgiyM9q6UxLVgKqVqaMgryxBJ5fP65QvZ1Y7 --data-binary '{"jsonrpc": "1.0", "id":"chain1", "method": "create", "params": ["stream", "stream_test", false, {"register_num":1,"transnum":22}] }' -H 'content-type: text/plain;' http://127.0.0.1:9262

In general you can always look at the first line output by multichain-cli to see the format of the JSON request to send.
tried it with no avail. parse error
Sorry, with MultiChain 1.0 you can only have textual custom fields for describing a stream. This worked for us:

curl --user multichainrpc:DgUzSVgbjgiyM9q6UxLVgKqVqaMgryxBJ5fP65QvZ1Y7 --data-binary '{"jsonrpc": "1.0", "id":"chain1", "method": "create", "params": ["stream", "stream_test", false, {"register_num":"1","transnum":"22"}] }' -H 'content-type: text/plain;' http://127.0.0.1:9262
...