繁体   English   中英

未捕获(承诺)错误:既没有在给定选项中也没有在默认选项中指定“发件人”地址

[英]Uncaught (in promise) Error: No "from" address specified in neither the given options, nor the default options

我想知道是否有人可以指导我朝着正确的方向发展我正在从事的项目,该项目是 Udemy 课程的一部分(以太坊和 Solidity 完整的开发人员指南)

所以我目前正在努力整合 Kickstarter 替代方案的前端。 我面临的问题在于new.js文件,它作为一个 JS 文件,代表一个新页面,其中包含一个按钮,使用户能够创建一个新的活动(通过metamask进行实际交易)。

import React, { Component } from 'react';
import { Form, Button, Input } from 'semantic-ui-react';
import Layout from '../../components/Layout';
import factory from '../../ethereum/factory';
import web3 from '../../ethereum/web3';
require('babel-polyfill');

class CampaignNew extends Component {
  state = {
    minimumContribution: ''
  };

  //to record and track user changes and inputs
  onSubmit = async (event) => {
    event.preventDefault();

    const accounts = await web3.eth.getAccounts();
    await factory.methods
      .createCampaign(this.state.minimumContribution)
      .send({ from: accounts[0] });
  };

  render() {
    return (
      <Layout>
        <h3>Create a Campaign</h3>

        <Form onSubmit={this.onSubmit}>
          <Form.Field>
            <label>Minimum Contribution</label>
            <Input
              label="wei"
              labelPosition="right"
              value={this.state.minimumContribution}
              onChange={event =>
                this.setState({ minimumContribution: event.target.value })}
            />
          </Form.Field>

          <Button primary>Create!</Button>
        </Form>
      </Layout>
    );
  }
}

export default CampaignNew;

现在在页面本身上,当我尝试单击具有应记录输入的 onChange 处理程序的创建活动按钮时。 我尝试单击与 onEvent 处理程序挂钩的按钮后出现的错误生成以下内容:

errors.js?207caff:127 Uncaught (in promise) Error: No "from" address specified in neither the given options, nor the default options.
    at Object.ContractNoFromAddressDefinedError (errors.js?207caff:127)
    at Object._executeMethod (index.js?901a092:775)
    at CampaignNew._callee$ (new.js?bfcc6bf:22)
    at tryCatch (runtime.js?af915c5:62)
    at Generator.invoke [as _invoke] (runtime.js?af915c5:296)
    at Generator.prototype.<computed> [as next] (runtime.js?af915c5:114)
    at step (asyncToGenerator.js?210f254:17)
    at asyncToGenerator.js?210f254:28

我正在按照课程的指示使用 web3 1.0.0-beta26,因此我们都可以遵循相同的语法。 我更新了 truffle HD 钱包,并且我认为它可能会阻止与 Metamask 的正确连接,因此可以运行交易并可以创建活动。 我不知道还能做什么,所以老实说,如果有人能心怀感激地将我引导到正确的方向,那就太好了。

// 在你的 web3.js 中尝试添加一个; 在底部}

web3 = new Web3(provider);

}; (<-- Add semicolon here)

export default web3;

// 并添加.enable()

if (typeof window !== 'undefined' && typeof window.web3 !== 'undefined') {
// We are in the browser and Metamask is running
web3 = new Web3(window.web3.currentProvider.enable())

这将连接钱包,但不是最终解决方案。 如果连接到钱包后出现更多问题。 再次删除.enable() ,您应该可以进行交易了..

暂无
暂无

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

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