Sae*_*ion 14 javascript reactjs solidity next.js semantic-ui-react
我正在使用 React、Next.Js、semantic-ui-react 和 Solidity。我的目标是打印出用户地址(来自 MetaMask)和一个 ProjectTitle(由用户设置)作为语义 ui-react 卡片的元信息。打印“标题”中的地址是有效的,但我无法将 ProjectTitle 打印为“元”。标题应该是一个字符串,但我收到了一个对象承诺。
static async getInitialProps() {
const projects = await factory.methods.getDeployedProjects().call();
return {
projects
};
}
async getProjectTitle(address) {
let title;
try {
title = await factory.methods.projectTitle(address).call();
} catch (err) {
console.log('err');
}
return title;
}
renderProjects() {
const items = this.props.projects.map(address => {
return {
header: address,
color: 'green',
description: (
<Link route={`/projects/${address}`}>
<a>View Project</a>
</Link>
),
**meta: this.getProjectTitle(address)**,
fluid: true,
style: { overflowWrap: 'break-word' }
};
}, );
return <Card.Group items={items} />
}
Run Code Online (Sandbox Code Playgroud)
Solidity 合约的一部分:
address[] public deployedProjects;
mapping(address => string) public projectTitle;
function createProject(string startup, string title, string deadline, string description, uint wage) public {
address newProject = new Project(startup, title, deadline, description, wage, msg.sender);
projectTitle[newProject] = title;
deployedProjects.push(newProject);
}
function getDeployedProjects() public view returns (address[]) {
return (
deployedProjects
);
}
Run Code Online (Sandbox Code Playgroud)
基本框架来自 Stephen Grider 的 Udemy 课程“Ethereum 和 Solidity:完整的开发人员指南”。
| 归档时间: |
|
| 查看次数: |
38946 次 |
| 最近记录: |