remix 中,结构体显示为 tuple,使用'[]'标识一个对象;
合约示例:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
contract tupleTest {
struct Man {
string name;
uint256 age;
}
Man[] persons;
constructor() {
persons.push(Man("name1",11));
persons.push(Man("name2",22));
}
// ["a1",1]
function addMan(Man memory man) public{
persons.push(man);
}
// [["a1",1],["a2",2]]
function addMen(Man[] memory men) public{
for(uint i=0;i<men.length;i++){
persons.push(men[i]);
}
}
function getMen() view public returns(Man[] memory){
return persons;
}
function getMen(uint id) view public returns(Man memory){
return
本文介绍了如何在 Remix IDE 中处理 struct 类型的参数。在 Remix 中,struct 类型显示为 tuple,并通过 '[]' 来表示一个对象。通过一个合约示例展示了在 Remix 中部署和调用含有 struct 参数的智能合约的操作流程。
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



