Remix中struct入参
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
contract StructDemo {
struct Student {
uint256 id;
string name;
}
// 初始化一个结构体
Student public student;
function initStudent5(Student memory _stu) public {
student = _stu;
}
}
结构体最终其实也是数组,所以在remix中传参就是传入一个数组[1,"coco"]
传入错误的类型就会提示异常
transact to StructDemo.initStudent5 errored: Error encoding arguments: Error: types/values length mismatch (count={"types":1,"values":4}, value={"types":["tuple(uint256,string)"],"values":["{\\",":101,\\",":\\","}"]}, code=INVALID_ARGUMENT, version=abi/5.7.0)