总是返回空数组,尽管它在 Shasta Network 上显示交易成功
Always returning empty array of arrays, although it's showing successful transaction on Shasta Network
我正在尝试从我的 solidity contract
函数中取回所有 struct
类型的记录,请参阅下面的 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++;
}
我在 NodeJs
代码段 NodeJs
下面的 nodejs
中使用 tronweb
成功添加了一条新记录
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 脚本结果的控制台图像,它总是返回一个空数组
这是状态为 CONFIRMED
的 Shasta Network 交易详情
有没有人可以帮助我?
在 ABI 中,结构类型的任何 return 值都将被解释为 tuple
。在你的例子中,它的类型是 tuple[]
.
图书馆不知道你的tuple
是什么,有多长,是什么类型。
您应该手动解析 return 数据。
{
"constant_result": [
"000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000005800000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000003555341000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024c4100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000053132333435000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000853747265657420310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016313332342d31323334352d31323435362d343536343200000000000000000000000000000000000000000000000000000000000000000000000000000000000d54657374696e67206e6f74657300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000003555341000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024c4100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000053132333435000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000853747265657420310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016313332342d31323334352d31323435362d343536343200000000000000000000000000000000000000000000000000000000000000000000000000000000000d54657374696e67206e6f74657300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000003555341000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024c4100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000053132333435000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000853747265657420310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016313332342d31323334352d31323435362d343536343200000000000000000000000000000000000000000000000000000000000000000000000000000000001254657374696e672077697468204a616d65730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000003555341000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024c4100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000053132333435000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000853747265657420310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016313332342d31323334352d31323435362d343536343200000000000000000000000000000000000000000000000000000000000000000000000000000000001e54657374696e672077697468204a616d6573206e65772076657273696f6e0000"
],
"result": {
"code": "SUCCESS",
"message": "",
"result": true
}
}
解析 constant_result:
- 按 64 字符边界(256 位)对齐
- 通常这些值是偏移量或长度
- 详情请参考ETH ABI文档
0000000000000000000000000000000000000000000000000000000000000020 offset of first parm
0000000000000000000000000000000000000000000000000000000000000004
0000000000000000000000000000000000000000000000000000000000000080
0000000000000000000000000000000000000000000000000000000000000300
0000000000000000000000000000000000000000000000000000000000000580
0000000000000000000000000000000000000000000000000000000000000800
0000000000000000000000000000000000000000000000000000000000000001 #first
0000000000000000000000000000000000000000000000000000000000000100
0000000000000000000000000000000000000000000000000000000000000140
0000000000000000000000000000000000000000000000000000000000000180
00000000000000000000000000000000000000000000000000000000000001c0
0000000000000000000000000000000000000000000000000000000000000200
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000240
0000000000000000000000000000000000000000000000000000000000000003 a string with 3 chars
5553410000000000000000000000000000000000000000000000000000000000 "USA"
0000000000000000000000000000000000000000000000000000000000000002 a string with 2 chars
4c41000000000000000000000000000000000000000000000000000000000000 "LA"
0000000000000000000000000000000000000000000000000000000000000005
3132333435000000000000000000000000000000000000000000000000000000 '12345'
0000000000000000000000000000000000000000000000000000000000000008
5374726565742031000000000000000000000000000000000000000000000000 'Street 1'
0000000000000000000000000000000000000000000000000000000000000016
313332342d31323334352d31323435362d343536343200000000000000000000 '1324-12345-12456-45642'
000000000000000000000000000000000000000000000000000000000000000d
54657374696e67206e6f74657300000000000000000000000000000000000000 'Testing notes'
0000000000000000000000000000000000000000000000000000000000000002 #second
0000000000000000000000000000000000000000000000000000000000000100
0000000000000000000000000000000000000000000000000000000000000140
0000000000000000000000000000000000000000000000000000000000000180
00000000000000000000000000000000000000000000000000000000000001c0
0000000000000000000000000000000000000000000000000000000000000200
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000240
0000000000000000000000000000000000000000000000000000000000000003
5553410000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000002
4c41000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000005
3132333435000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000008
5374726565742031000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000016
313332342d31323334352d31323435362d343536343200000000000000000000
000000000000000000000000000000000000000000000000000000000000000d
54657374696e67206e6f74657300000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000003 #third
0000000000000000000000000000000000000000000000000000000000000100
0000000000000000000000000000000000000000000000000000000000000140
0000000000000000000000000000000000000000000000000000000000000180
00000000000000000000000000000000000000000000000000000000000001c0
0000000000000000000000000000000000000000000000000000000000000200
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000240
0000000000000000000000000000000000000000000000000000000000000003
5553410000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000002
4c41000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000005
3132333435000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000008
5374726565742031000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000016
313332342d31323334352d31323435362d343536343200000000000000000000
0000000000000000000000000000000000000000000000000000000000000012
54657374696e672077697468204a616d65730000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000004 #fourth
0000000000000000000000000000000000000000000000000000000000000100
0000000000000000000000000000000000000000000000000000000000000140
0000000000000000000000000000000000000000000000000000000000000180
00000000000000000000000000000000000000000000000000000000000001c0
0000000000000000000000000000000000000000000000000000000000000200
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000240
0000000000000000000000000000000000000000000000000000000000000003
5553410000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000002
4c41000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000005
3132333435000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000008
5374726565742031000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000016
313332342d31323334352d31323435362d343536343200000000000000000000
000000000000000000000000000000000000000000000000000000000000001e
54657374696e672077697468204a616d6573206e65772076657273696f6e0000
我正在尝试从我的 solidity contract
函数中取回所有 struct
类型的记录,请参阅下面的 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++;
}
我在 NodeJs
代码段 NodeJs
下面的 nodejs
中使用 tronweb
成功添加了一条新记录
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 脚本结果的控制台图像,它总是返回一个空数组
这是状态为 CONFIRMED
有没有人可以帮助我?
在 ABI 中,结构类型的任何 return 值都将被解释为 tuple
。在你的例子中,它的类型是 tuple[]
.
图书馆不知道你的tuple
是什么,有多长,是什么类型。
您应该手动解析 return 数据。
{
"constant_result": [
"000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000005800000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000003555341000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024c4100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000053132333435000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000853747265657420310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016313332342d31323334352d31323435362d343536343200000000000000000000000000000000000000000000000000000000000000000000000000000000000d54657374696e67206e6f74657300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000003555341000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024c4100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000053132333435000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000853747265657420310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016313332342d31323334352d31323435362d343536343200000000000000000000000000000000000000000000000000000000000000000000000000000000000d54657374696e67206e6f74657300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000003555341000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024c4100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000053132333435000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000853747265657420310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016313332342d31323334352d31323435362d343536343200000000000000000000000000000000000000000000000000000000000000000000000000000000001254657374696e672077697468204a616d65730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000003555341000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024c4100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000053132333435000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000853747265657420310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016313332342d31323334352d31323435362d343536343200000000000000000000000000000000000000000000000000000000000000000000000000000000001e54657374696e672077697468204a616d6573206e65772076657273696f6e0000"
],
"result": {
"code": "SUCCESS",
"message": "",
"result": true
}
}
解析 constant_result:
- 按 64 字符边界(256 位)对齐
- 通常这些值是偏移量或长度
- 详情请参考ETH ABI文档
0000000000000000000000000000000000000000000000000000000000000020 offset of first parm
0000000000000000000000000000000000000000000000000000000000000004
0000000000000000000000000000000000000000000000000000000000000080
0000000000000000000000000000000000000000000000000000000000000300
0000000000000000000000000000000000000000000000000000000000000580
0000000000000000000000000000000000000000000000000000000000000800
0000000000000000000000000000000000000000000000000000000000000001 #first
0000000000000000000000000000000000000000000000000000000000000100
0000000000000000000000000000000000000000000000000000000000000140
0000000000000000000000000000000000000000000000000000000000000180
00000000000000000000000000000000000000000000000000000000000001c0
0000000000000000000000000000000000000000000000000000000000000200
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000240
0000000000000000000000000000000000000000000000000000000000000003 a string with 3 chars
5553410000000000000000000000000000000000000000000000000000000000 "USA"
0000000000000000000000000000000000000000000000000000000000000002 a string with 2 chars
4c41000000000000000000000000000000000000000000000000000000000000 "LA"
0000000000000000000000000000000000000000000000000000000000000005
3132333435000000000000000000000000000000000000000000000000000000 '12345'
0000000000000000000000000000000000000000000000000000000000000008
5374726565742031000000000000000000000000000000000000000000000000 'Street 1'
0000000000000000000000000000000000000000000000000000000000000016
313332342d31323334352d31323435362d343536343200000000000000000000 '1324-12345-12456-45642'
000000000000000000000000000000000000000000000000000000000000000d
54657374696e67206e6f74657300000000000000000000000000000000000000 'Testing notes'
0000000000000000000000000000000000000000000000000000000000000002 #second
0000000000000000000000000000000000000000000000000000000000000100
0000000000000000000000000000000000000000000000000000000000000140
0000000000000000000000000000000000000000000000000000000000000180
00000000000000000000000000000000000000000000000000000000000001c0
0000000000000000000000000000000000000000000000000000000000000200
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000240
0000000000000000000000000000000000000000000000000000000000000003
5553410000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000002
4c41000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000005
3132333435000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000008
5374726565742031000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000016
313332342d31323334352d31323435362d343536343200000000000000000000
000000000000000000000000000000000000000000000000000000000000000d
54657374696e67206e6f74657300000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000003 #third
0000000000000000000000000000000000000000000000000000000000000100
0000000000000000000000000000000000000000000000000000000000000140
0000000000000000000000000000000000000000000000000000000000000180
00000000000000000000000000000000000000000000000000000000000001c0
0000000000000000000000000000000000000000000000000000000000000200
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000240
0000000000000000000000000000000000000000000000000000000000000003
5553410000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000002
4c41000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000005
3132333435000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000008
5374726565742031000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000016
313332342d31323334352d31323435362d343536343200000000000000000000
0000000000000000000000000000000000000000000000000000000000000012
54657374696e672077697468204a616d65730000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000004 #fourth
0000000000000000000000000000000000000000000000000000000000000100
0000000000000000000000000000000000000000000000000000000000000140
0000000000000000000000000000000000000000000000000000000000000180
00000000000000000000000000000000000000000000000000000000000001c0
0000000000000000000000000000000000000000000000000000000000000200
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000240
0000000000000000000000000000000000000000000000000000000000000003
5553410000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000002
4c41000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000005
3132333435000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000008
5374726565742031000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000016
313332342d31323334352d31323435362d343536343200000000000000000000
000000000000000000000000000000000000000000000000000000000000001e
54657374696e672077697468204a616d6573206e65772076657273696f6e0000