Skip to content

Instantly share code, notes, and snippets.

@simon-jentzsch
Last active February 12, 2018 13:57
Show Gist options
  • Save simon-jentzsch/38f41fd8d12f56f03a0d63ba17f8ab57 to your computer and use it in GitHub Desktop.
Save simon-jentzsch/38f41fd8d12f56f03a0d63ba17f8ab57 to your computer and use it in GitHub Desktop.
rent the lightshow
// run this on the kovan-network!
const web3 = new Web3('http://localhost:8545')
const contract = new web3.eth.Contract(
[{"constant":false,"inputs":[{"name":"_id","type":"bytes32"},{"name":"_secondsToRent","type":"uint32"},{"name":"_token","type":"address"}],"name":"rent","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},
{"constant":true,"inputs":[{"name":"_id","type":"bytes32"},{"name":"_user","type":"address"},{"name":"_secondsToRent","type":"uint32"},{"name":"_token","type":"address"}],"name":"price","outputs":[{"name":"p","type":"uint128"}],"payable":false,"stateMutability":"view","type":"function"}],
'0xf0fd76A0e709B9cEafF8Ef002E99AdA96d6F4E00')
const deviceId = '0x7c4aa055bcee97a7b3132a2bf5ef2ca1f219564388c1b6220000000000000000' // light@slockit
const secondsToRent = 60
const token = '0x0000000000000000000000000000000000000000'
const user = (await web3.eth.getAccounts())[0]
const price = await contract.price(deviceId, user, secondsToRent, token)
await contract.rent(
deviceId,
secondsToRent,
token,
{from: user, value: price, gas:1800000 }
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment