Created
January 30, 2018 14:57
-
-
Save agrcrobles/60f1a6f9ce3c32174803611658cd8aed 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
import Contract from 'truffle-contract'; | |
import VotingArtifact from '../build/contracts/Voting.json'; | |
import Web3 from 'web3'; | |
function Star(candidate) { | |
const Voting = Contract(VotingArtifact); | |
var web3Provided; | |
// Supports Metamask and Mist, and other wallets that provide 'web3'. | |
if (typeof web3 !== 'undefined') { | |
// Injected web3 detected. | |
// Use the Mist/wallet provider. | |
// eslint-disable-next-line | |
web3Provided = new Web3(web3.currentProvider); | |
} else { | |
// No web3 instance injected, using Local web3. | |
web3Provided = new Web3(AnySupportedProvidedWithHardcodedAccount); | |
} | |
Voting.setProvider(web3Provided.currentProvider); | |
web3Provided.eth.getAccounts((error, result) => { | |
Voting.deployed().then(contractInstance => { | |
contractInstance.voteForCandidate(candidate, { | |
// configure the priority of the vote | |
gas: 140000, | |
// *** | |
// In a real dapp the coinbase should be provided by your wallet. | |
// *** | |
from: result[0], | |
}); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment