admin管理员组文章数量:1429091
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 badges1 Answer
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..
本文标签:
版权声明:本文标题:javascript - Uncaught (in promise) Error: No "from" address specified in neither the given options, nor the de 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745515412a2661508.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论