Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. const Web3 = require("web3");
  2. const fs = require("fs");
  3. const solc = require("solc");
  4. var web3 = new Web3('ws://localhost:7545');
  5.  
  6. // Compile the source code
  7. const input = fs.readFileSync('helloworld.sol');
  8. const output = solc.compile(input.toString(), 1);
  9. const bytecode = output.contracts[':Greeter'].bytecode;
  10. const abi = JSON.parse(output.contracts[':Greeter'].interface);
  11.  
  12. var options = {
  13. data: '0x' + bytecode,
  14. from: '0xB922118304784e9EbA04700Be74798e33B331590',
  15. gas: 90000*2
  16. };
  17.  
  18. var jsonint = [{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"greet","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"payable":false,"type":"constructor"}];
  19.  
  20.  
  21. // Contract object
  22. const contract = new web3.eth.Contract(jsonint, options);
  23.  
  24. console.log(contract.options.data);
  25.  
  26. const cb = (newContractInstance) =>
  27. {
  28. console.log(newContractInstance.options.address) // instance with the new contract address
  29. newContractInstance.methods.greet().call({from:'0xB922118304784e9EbA04700Be74798e33B331590'}, function(error, result){
  30. console.log(result);
  31. });
  32. }
  33.  
  34. contract.deploy({arguments:['Hello, World!']})
  35. .send({
  36. from: '0xB922118304784e9EbA04700Be74798e33B331590',
  37. gas: 1500000,
  38. gasPrice: '30000000000000'
  39. })
  40. .then(cb);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement