简体   繁体   中英

Deploying new contract to etherium network with web3.js

I have tried to run this code with relevant dependencies to get contract address and I received an error

No "from" address specified in neither the given options, nor the default options. from the browser. Additionally, there is no error while deploying with the Remix tool by using metamask ropsten testnet.

onSubmit = async (event) => {
    event.preventDefault();
    this.setState({ loading: true, errorMessage: '' }); 
    try {
        const accounts = await web3.eth.getAccounts();
        console.log(accounts)
        await factory.methods
        .createCampaign(this.state.minimumContribution)
        .send({ from: accounts[0] })
        Router.pushRoute('/');
    } catch (err) {
        this.setState({ errorMessage: err.message }) 
    }
    this.setState({ loading: false });
}

Does console.log(accounts) print anything?

If not, try to set up web3 with the following code:

if (typeof web3 !== 'undefined') {
  window.web3 = new Web3(web3.currentProvider);
  web3.currentProvider.enable();
} else {
  window.web3 = new Web3(new Web3.providers.HttpProvider("..."));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM