使用 react.js 努力在网页中显示智能合约信息

Struggling to display Smart Contract information in web page using react.js

function App(){
const [PopulateStudent] = useState(0);
const handleGet = asnyc (e) => {
e.preventDefault();
const result = await Certificate.methids.PopulateStudent("parameter1", "parameter2", "parameter3", "parameter4").call();
console.log(result)
}
return(
<div className="App">
<header>
<button onClick = {handleGet} type = "button">Fill</button>
</header>
</div>
);
}
export default App;

这是我在 App.js 中的代码。我正在尝试从 solidity 智能合约调用 PopulateStudent 函数。它有 4 个参数,如下所示。

constructor() public{
PopulateStudent("string", "string", int, int)
Fill();
}
function PopulateStudent(string memory _name, string memory _surname, uint _exam, uint _center) public { 
students[1] = Student({name :_name, surname: _surname, examNumber: _exam, center:_center, qualification:Qualification.Bachelor, level:Level.one});
}

当我在浏览器中 运行 代码并单击 Fill 按钮时,我无法获取要显示的值。当我在 InspectElement 下查看控制台日志时,我看到的唯一操作是单击 Fill 时的 Object { }。 我是 solidity 和 React.js 的新手,所以任何帮助将不胜感激。

与智能合约交互时,主要有两种操作类型。一个(读写)事务和一个(只读)调用。

PopulateStudent() solidity函数需要一个交易,因为它修改合约状态(保存新创建的Student 合约存储结构)。

如果students 属性(PopulateStudent()存储)是public,你可以调用它的自动生成getter 函数(自动生成 - 它不需要在您的合同中)。例如:

// returns `students[1]`
const result = await Certificate.methods.students(1).call();