Guest User

Untitled

a guest
Apr 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. var Web3 = require('web3');
  2. var contract = require('./PublishService_abi.js');
  3. var PublishServiceContract;
  4. var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:7545"));
  5.  
  6. function init() {
  7. //initializing web3 to access blockchain
  8. initweb3();
  9. }
  10.  
  11. async function initweb3() {
  12. try {
  13. /*//To make sure not to overwrite the already set provider when in mist, check first if the web3 is available
  14. if (typeof web3 !== 'undefined') {
  15. web3 = await new Web3(web3.currentProvider);
  16. console.log("inside if");
  17. } else {
  18. // create an instance of web3 using the HTTP provider
  19. web3 = await new Web3(new Web3.providers.HttpProvider("http://localhost:7545"));
  20. console.log("inside else");
  21. }*/
  22. console.log(web3.eth.accounts[1]);
  23. var PublishServiceContractAddress = "0x0da136781e562e28fb1c0b3efc8ce9d8b4e226f2";
  24. PublishServiceContract = await new web3.eth.Contract(contract,PublishServiceContractAddress);
  25. //console.log(PublishServiceContract.options.jsonInterface);
  26. await addServiceProducer1("LC1","SP1","location:inside;reading:degree","scattr","ngac");
  27. }
  28. catch(err) {
  29. console.log(err);
  30. }
  31. }
  32.  
  33. async function addServiceProducer1(s1,s2,s3,s4,s5) {
  34. try{
  35. console.log(s1 +"n" + s2 +"n" + s3 +"n" + s4 +"n" + s5 +"n" );
  36. const instance = await PublishServiceContract.methods.addEntry(s1,web3.eth.accounts[1],s2,s3,s4,s5).send({from:web3.eth.accounts[1]});
  37. console.log("sp details added successfully");
  38. }
  39. catch(err) {
  40. console.log(err);
  41. }
  42. }
  43.  
  44. init();
Add Comment
Please, Sign In to add comment