Skip to content

Instantly share code, notes, and snippets.

@karlfloersch
Last active August 15, 2016 21:31
Show Gist options
  • Save karlfloersch/d44b7eac44f35c4d59614adb5d4477ef to your computer and use it in GitHub Desktop.
Save karlfloersch/d44b7eac44f35c4d59614adb5d4477ef to your computer and use it in GitHub Desktop.
A basic web3 starter. It requires some work, it's intended use is for the Lotto contract
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hello World</title>
</head>
<body>
<script>
if (typeof web3 !== 'undefined') {
console.log('Web3 found!');
} else {
console.log('Web3 not found, expect errors!');
}
var lottoContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"ticketPrice","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[],"name":"rand","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[],"name":"payout","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"maxTickets","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"currentTickets","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"x","type":"string"}],"name":"logString","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"x","type":"uint256"}],"name":"logUint","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"x","type":"address"}],"name":"logAddress","type":"event"}]);
var lottoContractAddress = ''; // INPUT THE CONTRACT ADDRESS HERE!
var lotto = lottoContract.at(lottoContractAddress);
// Send the lotto a transaction https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethsendtransaction
var myAccountAddress = web3.eth.accounts[0];
web3.eth.sendTransaction({
from: myAccountAddress,
to: lottoContractAddress,
value: 0.1 // Not sure if value is in ETH, may requrie testing to send the right value
}, function (tx) {
console.log(tx);
});
// TODO: Create a button which executes this Javascript
</script>
<h1>Hello World</h1>
<p>
I should be a button but I'm not :(
</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment