Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. poleID = '0x2678394866d17d16a619706d5fd36cacf02d259fd901decbb0b27930f48d6325'
  2. account = web3.eth.accounts[0]
  3. secondsToCharge = 2 * 3600 //2h
  4. maxCharging = 22000 // 22kwh-charging car
  5.  
  6. tokenContract = web3.eth.contract(
  7. [{type: 'function', name: 'approve', inputs: [{name: '_spender', type: 'address'}, {name: '_amount', type: 'uint256'}], outputs: [{name: 'success', type: 'bool'}], payable: false}]
  8. ).at('0x8262a2a5c61A45Aa074cbeeDE42c808D15ea3ceD')
  9.  
  10. chargingContract = web3.eth.contract(
  11. [{type: 'function', name: 'stop', inputs: [{name: '_poleID', type: 'bytes32'}, {name: '_measuredWatt', type: 'uint32'}], outputs: [], payable: false},
  12. {type: 'function', name: 'costTimebased', constant: true, inputs: [{name: '_poleID', type: 'bytes32'}, {name: '_user', type: 'address'}, {name: '_wattPower', type: 'uint256'}, {name: '_secondsToRent', 'type': 'uint256'}], 'outputs': [{name: 'chargingCost', 'type': 'uint256'}], 'payable': false},
  13. {type: 'function', name: 'start', inputs: [{name: '_poleID', type: 'bytes32'}, {name: '_wattPower', type: 'uint32'}, {name: '_secondsToRent', type: 'uint32'}], outputs: [], payable: true}]
  14. ).at('0x61c810e21659032084A4448D8D2F498789f81CB5')
  15.  
  16. // calculate costs
  17. costs = chargingContract.costTimebased(poleID, account, maxCharging, secondsToCharge)
  18.  
  19. // approve the tokens
  20. tokenContract.approve(chargingContract.address, costs,{from:account})
  21.  
  22. // start the transation
  23. chargingContract.start(poleId,maxCharging,secondsToCharge,{from:account})
  24.  
  25. ...
  26. // stop it again
  27. chargingContract.stop(poleId,0,{from:account})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement