Skip to content

Instantly share code, notes, and snippets.

@agrcrobles
Created January 30, 2018 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agrcrobles/60f1a6f9ce3c32174803611658cd8aed to your computer and use it in GitHub Desktop.
Save agrcrobles/60f1a6f9ce3c32174803611658cd8aed to your computer and use it in GitHub Desktop.
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