坚固函数返回ethersjs/hardhat上的空数组,而不是在混音中返回吗?
嗨,我正在学习坚固的性能,我有一个问题,即一个功能似乎可以在混音中起作用,但对Etherjs/hardhat不起作用? (ABI也一样)
代码:
function getOwnCards() external view returns(uint[] memory _cards) {
uint[] memory result = new uint[](userToCardsCount[msg.sender]);
uint counter = 0;
for (uint i = 0; i < cards.length; i++) {
if (cardIdToUser[i] == msg.sender) {
result[counter] = cards[i];
counter++;
}
}
return result;
}
混音IDE中的结果:
0:
uint256[]: _cards 62180033277912311002789072835418559502128313467724667052439679862541172075622,31220469133090072532919887703804680190688655804240516732101690706958488894069,35568354368614544905898949308353469583138320508979990175291873927902398948450
Ethersjs中的结果:
[]
Fe代码:
const getCards = async () => {
if (typeof window.ethereum !== 'undefined'){
//@ts-ignore
const provider = new ethers.providers.Web3Provider(window.ethereum)
const contract = new ethers.Contract(cardsAddress, Cards.abi, provider)
try {
const data = await contract.getOwnCards()
console.log(data)
} catch (error) {
console.log(error)
}
}
}
Hi I am learning Solidity and I have the problem that a function seems to work on remix ide but not with etherjs/hardhat? (The abi's are the same too)
The code:
function getOwnCards() external view returns(uint[] memory _cards) {
uint[] memory result = new uint[](userToCardsCount[msg.sender]);
uint counter = 0;
for (uint i = 0; i < cards.length; i++) {
if (cardIdToUser[i] == msg.sender) {
result[counter] = cards[i];
counter++;
}
}
return result;
}
The result in remix ide:
0:
uint256[]: _cards 62180033277912311002789072835418559502128313467724667052439679862541172075622,31220469133090072532919887703804680190688655804240516732101690706958488894069,35568354368614544905898949308353469583138320508979990175291873927902398948450
The result in ethersjs:
[]
The FE code:
const getCards = async () => {
if (typeof window.ethereum !== 'undefined'){
//@ts-ignore
const provider = new ethers.providers.Web3Provider(window.ethereum)
const contract = new ethers.Contract(cardsAddress, Cards.abi, provider)
try {
const data = await contract.getOwnCards()
console.log(data)
} catch (error) {
console.log(error)
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案1:
更改味精为给定参数:
解决方案2:
在fe中呼叫函数正确
Solution 1:
change msg.sender to a given parameter:
Solution 2:
call function in FE Correct