Skip to content

Instantly share code, notes, and snippets.

@Zuchos
Created September 28, 2017 07:43
Show Gist options
  • Save Zuchos/c0f1e9a4e7a6d1f09246628e6becaaad to your computer and use it in GitHub Desktop.
Save Zuchos/c0f1e9a4e7a6d1f09246628e6becaaad to your computer and use it in GitHub Desktop.
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