Guest User

Untitled

a guest
May 21st, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. contract CampaignFactory {
  2. address[] public deployedCampaigns;
  3.  
  4. function createCampaign (uint minimum) public {
  5. address newCampaign = new Campaign(minimum, msg.sender);
  6. deployedCampaigns.push(newCampaign);
  7. }
  8.  
  9. function GetDeployedCampaigns() public view returns (address[]) {
  10. return deployedCampaigns;
  11. }
  12. }
  13.  
  14. contract Campaign {
  15. address public manager;
  16. uint public minimumContribution;
  17. constructor (uint minimum, address creator) public {
  18. manager = creator;
  19. minimumContribution = minimum;
  20. }
  21. }
  22.  
  23. const accounts = await web3.eth.getAccounts();
  24. await factory.methods.createCampaign("1").send({
  25. from: accounts[0]
  26. });
  27.  
  28. const contarct = new web3.eth.Contract(abi, address)
  29. let web3 = new Web3(new Web3.providers.HttpProvider("https://rinkeby.infura.io/<token>"))
  30. var privateKey = new Buffer('6e4702be2aa6b2c96ca22df40a004c2c9...', 'hex')
  31.  
  32. var functionName = 'createCampaign'
  33. var types = ['uint']
  34. var args = [1]
  35. var fullName = functionName + '(' + types.join() + ')'
  36. var signature = CryptoJS.SHA3(fullName,{outputLength:256}).toString(CryptoJS.enc.Hex).slice(0, 8)
  37. var dataHex = signature + web3.eth.abi.encodeParameters(types, args)
  38. var data = '0x'+ dataHex
  39.  
  40. var nonce = web3.utils.toHex((web3.eth.getTransactionCount('0x46fC1600b1869b3b4F90971...')))
  41. var gasPrice = 100000
  42. var gasLimitHex = web3.utils.toHex(3000000)
  43. var rawTx = { 'nonce': nonce,
  44. 'gasPrice': gasPrice,
  45. 'gasLimit': gasLimitHex,
  46. 'from': '0x46fC1600b1869b3...',
  47. 'to': '0x8be14cf0b28c3d88d229c493...', //Address of deployed contract (CampaignFactory)
  48. 'data': data}
  49. var tx = new Tx(rawTx)
  50. tx.sign(privateKey)
  51. var serializedTx = '0x'+tx.serialize().toString('hex')
  52. web3.eth.sendSignedTransaction(serializedTx, function(err, txHash){ console.log(err, txHash) })
  53.  
  54. null '0x0fad927a77b7f03a32f476d3d8d4027f7daa19270f5c98d1c11156a31360c04b'
Add Comment
Please, Sign In to add comment