Skip to content

Instantly share code, notes, and snippets.

@simon-jentzsch
Last active August 6, 2021 16:38
Show Gist options
  • Save simon-jentzsch/527f6935008509e57b6873af36fe8133 to your computer and use it in GitHub Desktop.
Save simon-jentzsch/527f6935008509e57b6873af36fe8133 to your computer and use it in GitHub Desktop.
// adjust these values
poleID = '0x2678394866d17d16a619706d5fd36cacf02d259fd901decbb0b27930f48d6325' // the chargingPole-ID
account = web3.eth.accounts[0] // the account to use
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')
// unlock you account with your password
personal.unlockAccount(account)
// 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})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment