简体   繁体   English

使用 web3.js 将新合约部署到以太坊网络

[英]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.此外,通过使用 metamask ropsten 测试网使用 Remix 工具进行部署时没有错误。

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? console.log(accounts)是否打印任何内容?

If not, try to set up web3 with the following code:如果没有,请尝试使用以下代码设置 web3:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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