Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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