Guest User

Untitled

a guest
Apr 14th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. let multichain = require("multichain-node")({
  2. port: 7752, // check in params.dat “default-rpc-port” settings
  3. host: '127.0.0.1',
  4. user: "multichainrpc",
  5. pass: "45H3cZVZf5LfNaAEsHJVzvQJQBHu4FTtvgS2bWg3sSpF"
  6. });
  7.  
  8.  
  9. function writeInStream(key, InputString){
  10.  
  11. let bufStr = Buffer.from(InputString, 'utf8');
  12. hexstring = bufStr.toString('hex')
  13.  
  14. console.log("converting to hexa :", hexstring);
  15.  
  16. multichain.publish({
  17. stream: "stream1",
  18. "key": key,
  19. data: hexstring
  20. },(err,res)=>{
  21.  
  22. if(err!=null){
  23. console.log("error",err);
  24. }else{
  25. console.log("response :",res);
  26. }
  27.  
  28. }
  29. );
  30.  
  31. }
  32.  
  33. function readFromStream(key){
  34.  
  35. multichain.listStreamKeyItems(
  36. {
  37. stream:"stream1",
  38. key:key,
  39. verbose:true,
  40. count: 10,
  41. start:0
  42. }, (err,res)=> {
  43. data = res[res.length-1].data;
  44. stringval = Buffer.from(data, 'hex').toString();
  45. console.log(stringval);
  46. }
  47. );
  48. }
  49.  
  50. writeInStream("mykey","rangasthalam");
  51. readFromStream("mykey")
Add Comment
Please, Sign In to add comment