0

This question already has an answer here:

How do I deploy a contract with MetaMask & truffle-contract? Currently if I want to deploy a contract with truffle-contract I'll have the following code.

var web3 = new Web3(new 
Web3.providers.HttpProvider("http://localhost:8545"));
var provider = new Web3.providers.HttpProvider("http://localhost:8545");
var MyContract = contract(Contract);

MyContract.defaults({
    from: '0x...',
    gas: 4712388,
    gasPrice: 1000000000
})

MyContract.setProvider(provider);

However, when you deploy initialize with MetaMask you what do you set as the provider? Is it window.web3?

if (typeof window.web3 !== 'undefined') {
        window.web3 = new Web3(window.web3.currentProvider);
    } else {
        console.log('No web3? You should consider trying MetaMask!')
        window.web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
    }

    MyContract = contract(Contract);
    MyContract.setProvider(window.web3);        
    const account = window.web3.eth.accounts;

    MyContract.defaults({
        from: account,
        gas: 4712388,
        gasPrice: 1000000000
    }) 

marked as duplicate by Greg Jeanmart, shane, GrandFleet, Ismael, Briomkez Dec 1 '18 at 10:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

The MetaMask provider should be window.web3.currentProvider.

 MyContract.setProvider(window.web3.currentProvider)     

Not the answer you're looking for? Browse other questions tagged or ask your own question.