繁体   English   中英

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

[英]Deploying new contract to etherium network with web3.js

我已尝试使用相关依赖项运行此代码以获取合约地址,但收到错误消息

No "from" address specified in neither the given options, nor the default options. 从浏览器。 此外,通过使用 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 });
}

console.log(accounts)是否打印任何内容?

如果没有,请尝试使用以下代码设置 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