最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uncaught (in promise) Error: No "from" address specified in neither the given options, nor the de

programmeradmin1浏览0评论

I was wondering if anyone can guide me in the right direction regarding a project I'm working on which is part of Udemy's course ( ethereum and solidity the plete developers guide )

So I'm currently working on putting together the front-end of a Kickstarter alternative. The issue I'm facing lies in the new.js file which serves as a JS file representing a new page that contains a button enabling the user to create a new campaign(doing the actual transaction through metamask).

import React, { Component } from 'react';
import { Form, Button, Input } from 'semantic-ui-react';
import Layout from '../../ponents/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;

Now on the page itself, when i try to click on the create campaign button which has an onChange handler that should record the input. The error that es up after i try clicking the button which is hooked with an onEvent handler generates the following:

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.<puted> [as next] (runtime.js?af915c5:114)
    at step (asyncToGenerator.js?210f254:17)
    at asyncToGenerator.js?210f254:28

I'm using web3 1.0.0-beta26 as the course has instructed so we can both be following the same syntax. I updated the truffle HD wallet as well as I thought it might be preventing a proper connection to Metamask so the transaction can run and the campaign can be created. I have no idea what else to do so it would honestly be great if someone can gratefully guide me in the right direction.

I was wondering if anyone can guide me in the right direction regarding a project I'm working on which is part of Udemy's course ( ethereum and solidity the plete developers guide )

So I'm currently working on putting together the front-end of a Kickstarter alternative. The issue I'm facing lies in the new.js file which serves as a JS file representing a new page that contains a button enabling the user to create a new campaign(doing the actual transaction through metamask).

import React, { Component } from 'react';
import { Form, Button, Input } from 'semantic-ui-react';
import Layout from '../../ponents/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;

Now on the page itself, when i try to click on the create campaign button which has an onChange handler that should record the input. The error that es up after i try clicking the button which is hooked with an onEvent handler generates the following:

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.<puted> [as next] (runtime.js?af915c5:114)
    at step (asyncToGenerator.js?210f254:17)
    at asyncToGenerator.js?210f254:28

I'm using web3 1.0.0-beta26 as the course has instructed so we can both be following the same syntax. I updated the truffle HD wallet as well as I thought it might be preventing a proper connection to Metamask so the transaction can run and the campaign can be created. I have no idea what else to do so it would honestly be great if someone can gratefully guide me in the right direction.

Share Improve this question edited Jan 13, 2023 at 16:56 TylerH 21.1k79 gold badges79 silver badges114 bronze badges asked Jan 19, 2020 at 20:13 Karim NabilKarim Nabil 791 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

// in your web3.js try adding a ; at the bottom }

web3 = new Web3(provider);

}; (<-- Add semicolon here)

export default web3;

// And add .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())

This will connect the wallet, but is not a final solution. If more problems after connected to wallet. Remove .enable() again and you should be able to do transactions..

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论