Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- poleID = '0x2678394866d17d16a619706d5fd36cacf02d259fd901decbb0b27930f48d6325'
- account = web3.eth.accounts[0]
- secondsToCharge = 2 * 3600 //2h
- maxCharging = 22000 // 22kwh-charging car
- tokenContract = web3.eth.contract(
- [{type: 'function', name: 'approve', inputs: [{name: '_spender', type: 'address'}, {name: '_amount', type: 'uint256'}], outputs: [{name: 'success', type: 'bool'}], payable: false}]
- ).at('0x8262a2a5c61A45Aa074cbeeDE42c808D15ea3ceD')
- chargingContract = web3.eth.contract(
- [{type: 'function', name: 'stop', inputs: [{name: '_poleID', type: 'bytes32'}, {name: '_measuredWatt', type: 'uint32'}], outputs: [], payable: false},
- {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},
- {type: 'function', name: 'start', inputs: [{name: '_poleID', type: 'bytes32'}, {name: '_wattPower', type: 'uint32'}, {name: '_secondsToRent', type: 'uint32'}], outputs: [], payable: true}]
- ).at('0x61c810e21659032084A4448D8D2F498789f81CB5')
- // calculate costs
- costs = chargingContract.costTimebased(poleID, account, maxCharging, secondsToCharge)
- // approve the tokens
- tokenContract.approve(chargingContract.address, costs,{from:account})
- // start the transation
- chargingContract.start(poleId,maxCharging,secondsToCharge,{from:account})
- ...
- // stop it again
- chargingContract.stop(poleId,0,{from:account})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement