Created
September 25, 2018 20:54
-
-
Save merlox/6d953039936f14a675558ff33894e81d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let Contract | |
let contractInstance | |
let contractAddress | |
function start() { | |
document.querySelector('#new-game').addEventListener('click', () => { | |
... | |
}) | |
document.querySelector('#join-game').addEventListener('click', () => { | |
... | |
}) | |
document.querySelector('#button-continue').addEventListener('click', () => { | |
const valueSelected = document.querySelector('#eth-value').value | |
const addressSelected = document.querySelector('#eth-address').value.trim() | |
Contract = web3.eth.contract(abi) | |
if(addressSelected.length === 0) { | |
contractInstance = Contract.new({ | |
value: web3.toWei(valueSelected), | |
data: bytecode.object, | |
gas: 7e6 | |
}, (err, result) => { | |
console.log(err, result) | |
// This callback will be called twice, the second time includes the contract address | |
if(!result.address) { | |
document.querySelector('#display-address').innerHTML = 'The transaction is being processed, wait until the block is mined to see the address here...' | |
} else { | |
document.querySelector('#display-address').innerHTML = 'Contract address: ' + result.address | |
} | |
}) | |
} else { | |
let interval | |
contractInstance = Contract.at(addressSelected) | |
contractInstance.setupPlayer2({ | |
gas: 4e6 | |
}, (err, result) => { | |
interval = setInterval(() => { | |
web3.eth.getTransaction(result, (err, result) => { | |
if(result.blockNumber != null) { | |
document.querySelector('#display-address').innerHTML = 'App ready' | |
clearInterval(interval) | |
} | |
}) | |
}, 1e3) | |
}) | |
} | |
}) | |
} | |
start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment