Kar*_*bil 5 javascript reactjs blockchain ethereum web3js
我想知道是否有人可以指导我关于我正在从事的项目的正确方向,该项目是 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;
Run Code Online (Sandbox Code Playgroud)
现在在页面本身上,当我尝试单击“创建活动”按钮时,该按钮有一个应记录输入的 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
Run Code Online (Sandbox Code Playgroud)
我按照课程的指示使用 web3 1.0.0-beta26,这样我们就可以遵循相同的语法。我更新了 truffle HD 钱包,并且我认为它可能会阻止与 Metamask 的正确连接,以便可以运行交易并创建活动。我不知道还能做什么,所以说实话,如果有人能够感激地引导我走向正确的方向,那就太好了。
小智 4
;// 在你的 web3.js 中尝试在底部添加一个}
web3 = new Web3(provider);
}; (<-- Add semicolon here)
export default web3;
Run Code Online (Sandbox Code Playgroud)
// 并添加.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())
Run Code Online (Sandbox Code Playgroud)
这将连接钱包,但不是最终的解决方案。如果连接钱包后出现更多问题。再次删除.enable(),您应该能够进行交易。
| 归档时间: |
|
| 查看次数: |
4930 次 |
| 最近记录: |