我正在尝试从我的函数中取回所有struct
类型记录,solidity contract
请参阅下面的solidity contract
代码片段
struct Record {
uint _id;
string _countryCode;
string _state;
string _postal;
string _location;
string _userId;
string _additionalDetails;
}
Record[] public records;
function getEntries() public view returns (Record[] memory) {
return records;
}
function setRecord(
string memory _countryCode,
string memory _state,
string memory _postal,
string memory _location,
string memory _userId,
string memory _additionalDetails
) public onlyOwner {
Record memory newStruct = Record({
_id: _counter + 1,
_countryCode: _countryCode,
_state: _state,
_postal: _postal,
_location: _location,
_userId: _userId,
_additionalDetails: _additionalDetails
});
records.push(newStruct);
_counter++;
}
我成功地能够在我的代码片段中使用下面的tronweb
in添加新记录nodejs
NodeJs
const walletAddress = "";
const privateKey = "";
const contractAddress = "";
tronweb.setAddress(walletAddress);
tronweb.setPrivateKey(privateKey);
const init = async () => {
let contract = await tronweb.contract().at(contractAddress);
const getRecords = async () => await contract.getEntries().call();
const setRecord = async () => await contract.setRecord(
"USA",
"LA",
"12345",
"Street 1",
"1324-12345-12456-45642",
"Testing notes"
).send({
"from": walletAddress
});
await setRecord();
getRecords().then(result => {
console.log(result); // getting empty array like [ [], [] ]
});
};
init();
这是我的 nodejs 脚本结果的控制台图像,它总是返回一个空的数组数组
这是带有状态的 Shasta Network 交易详情CONFIRMED
有谁能帮助我吗?