[英]Solidity function returns empty array to web3.js
Solidity function returns a array of string while executed on Remix as well as truffle console while it returns a empty array when called from JS Solidity函数在Remix和truffle控制台上执行时返回一个字符串数组,当从JS调用时它返回一个空数组
Solidity code Solidity代码
mapping(address => string[]) addressLink;
function getLinks(address a) public view returns (string[] memory)
{
return addressLink[a];
}
JS code JS代码
contract.methods.getLinks(accounts[0]).call().then(res => {
console.log(res)
});
truffle console result and expected results when called from JS 从JS调用时,松露控制台结果和预期结果
[ 'QmTiMLN8X4NE4ho5mqJ9t4bJ17JxfMHAFcg3z66f8vdUh1' ]
Result on browser console(Actual result) 浏览器控制台上的结果(实际结果)
[""]
0: ""
length: 1
You might set the wrong contract address in your javascript code: 您可以在javascript代码中设置错误的合同地址:
const instance = new web3.eth.Contract(
SimpleStorageContract.abi,
deployedNetwork && deployedNetwork.address,
);
The second parameter is contract address, see: https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#new-contract 第二个参数是合同地址,请参阅: https : //web3js.readthedocs.io/en/1.0/web3-eth-contract.html#new-contract
Hope it helps. 希望能帮助到你。
There was a bug in web3.js library. web3.js库中有一个错误。 Which has been closed in the latest beta release 哪个已在最新的测试版中关闭
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.