Skip to content

Instantly share code, notes, and snippets.

@bellaj
Created May 22, 2017 17:31
Show Gist options
  • Save bellaj/87c9c48c77de7daef8020ef18bbfa47d to your computer and use it in GitHub Desktop.
Save bellaj/87c9c48c77de7daef8020ef18bbfa47d 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 = '0x9da874fc3562ed2adfac923a59948674939e5e8f'
const abi = [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"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