Created
September 28, 2017 07:43
-
-
Save Zuchos/c0f1e9a4e7a6d1f09246628e6becaaad 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
if (typeof web3 !== 'undefined' && typeof Web3 !== 'undefined') { | |
web3 = new Web3(web3.currentProvider); | |
} else if (typeof Web3 !== 'undefined') { | |
console.log('No web3? You should consider trying MetaMask!') | |
web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')); | |
} | |
myApp.config(function ($provide) { | |
$provide.provider('ethClinet', function () { | |
this.$get = function () { | |
return web3; | |
}; | |
}); | |
}); | |
myApp.service('Petunia', ['ethClinet', '$q', function (ethClinet, $q) { | |
//here we build object that represents petunia smart contract | |
const petunia = ethClinet.eth.contract(contractABI).at(contractAddress); | |
var account = null; | |
//here we fetch accounts that are available e.g. were added to Metamask | |
$q((resolve, reject) => ethClinet.eth.getAccounts(function (e, r) { | |
if (e) { | |
reject(e); | |
} else { | |
account = r[0]; | |
} | |
})); | |
///... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment