Skip to content

Instantly share code, notes, and snippets.

@bellaj
Created May 22, 2017 17:36
Show Gist options
  • Save bellaj/185ac7557ef9825a6e72034996b671ea to your computer and use it in GitHub Desktop.
Save bellaj/185ac7557ef9825a6e72034996b671ea to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<script>
window.addEventListener('load', function() {
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
if (typeof web3 !== 'undefined') {
// Use Mist/MetaMask's provider
window.web3 = new Web3(web3.currentProvider);
} else {
console.log('No web3? You should consider trying MetaMask!')
// fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail)
window.web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
startApp()
})
function startApp(web3) {
const address = '0x55c77e9c98187ff9123f2becafc66efd9a1218bf'
const abi = [{"constant":true,"inputs":[],"name":"my_method","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"}]
var contract = window.web3.eth.contract(abi).at(address);
contract.my_method(function(error, result){
if(!error)
console.log("result:"+result)
else
console.error("error:"+error);
});
}
</script>
</script>
<h2>Test</h2>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment