Guest User

Untitled

a guest
Nov 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. pragma solidity ^0.4.11;
  2.  
  3. contract Factory {
  4.  
  5. address[] public pizzas;
  6.  
  7. function Factory() {
  8. // constructor
  9. }
  10.  
  11. function cookPizza() returns (address _pizza) {
  12. Pizza newPizza = new Pizza();
  13. pizzas.push(newPizza);
  14. return newPizza;
  15. }
  16.  
  17. function getPizzas() public constant returns (address[]) {
  18. return pizzas;
  19. }
  20. }
  21.  
  22. contract Pizza {
  23. function Pizza() {
  24. // constructor
  25. }
  26. }
  27.  
  28. truffle(development)> Factory.deployed().then(function(instance) { factory = instance})
  29. undefined
  30. truffle(development)> factory.cookPizza()
  31. truffle(development)> factory.getPizzas()
  32. [ '0xc4f8cf2d5a37e74981fffdab1b2108931822359a' ]
  33.  
  34. Running migration: 1_initial_migration.js
  35. Deploying Migrations...
  36. Migrations: 0x42e40188763019dd09a6166b76805d329bd71111
  37. Saving successful migration to network...
  38. Saving artifacts...
  39. Running migration: 2_deploy_contracts.js
  40. Deploying Factory...
  41. Factory: 0xb9d60d9ddf16e3af3bce774a1e9286ecf5614166
  42. Saving successful migration to network...
  43. Saving artifacts...
  44.  
  45. > sender = eth.accounts[0]
  46. > abi = "abi"
  47. > contract = eth.contract(abi)
  48. > factory = contract.at("0xb9d60d9ddf16e3af3bce774a1e9286ecf5614166")
  49. > factory.cookPizza({from:sender})
  50. "0xf0ce6f4c0a9665f593d3d837eca4977b85d011dcb3620bf3a2428d25225db967"
  51. > factory.getPizzas()
  52. []
Add Comment
Please, Sign In to add comment