Publish Off-Chain Item with On-Chain "notes"

+3 votes
I was reading the "publish" description in the JSON-RPC API and I had a doubt about the possibility of my application. I needed to publish an off-chain item with some metadata information embedded on-chain.

For example: "iPhone 2018, New, $400" on the blockchain while {picture.jpg} goes off-chain, but they are still "together".
asked Feb 21, 2019 by tloriato

1 Answer

+3 votes
Best answer

Your best bet here is to publish two stream items simultaneously in a single transaction – one off-chain and one on-chain. You can have the both in the same stream, or in two different streams. These two items will be naturally associated with each other since they will have the same transaction ID. See the publishmulti API (in MultiChain 2.0) for making this easy.

answered Feb 21, 2019 by MultiChain
selected Feb 21, 2019 by tloriato
I wanted to disable publishing more than one item per transaction, since I wanted to charge a fixed fee for stream publishing, but I guess I'll do it using stream filters.

Is it possible to have a filter that on publishmulti that forces the user to publish those two streams, one on-chain and one off-chain?

If not, could you point me somewhere in the source code that could guide me to the respective functions?
You would do this as a transaction filter, not a stream filter, since a stream filter only works on the level of a single stream item. Inside the transaction filter all the information you need will be returned by the getfiltertransaction() callback. If you use testtxfilter (or the Web Demo) you can see the response of this callback for the different situations.
What if I use the "keys" properties as an "on-chain" storage in an off-chain item? The blockchain could assume keys[0] = Property1, keys[1] = Property2, etc... and all nodes could agree on this "standard format" for publishing item, right?
Yes, that would also be OK if it works for you. You can decide which approach is more neat for your particular case.