[英]Return address function from smart contract returns promise object instead of address in truffle test
Hi I have an address return function that works in remix but when I try to run it in a truffle test it gives me a promise object.嗨,我有一个地址返回函数,可以在 remix 中使用,但是当我尝试在 truffle 测试中运行它时,它给了我一个 promise 对象。
If I could have the truffle test return an address like it does in the solidity code that would be ideal or if I can access the promise object to give me my address.如果我可以让 truffle 测试返回一个地址,就像它在 solidity 代码中所做的那样,那将是理想的,或者如果我可以访问 promise 对象来给我我的地址。 I have tried to add ".toString()" to the promise object but it does not give me the address
我试图将“.toString()”添加到 promise 对象,但它没有给我地址
This is how I am trying to call the return function and save it to a variable within the truffle test这就是我尝试调用返回函数并将其保存到松露测试中的变量的方式
const newFractionContractAddress = await mainContract.getFractionContractAddress(0, {from: accounts[0]});
the solidity return function looks like this solidity 返回函数如下所示
function getFractionContractAddress(uint _index) public view returns(address) {
return address(nftDeposits[msg.sender].deposits[_index].fractionContract);
}
Thanks谢谢
Sending EVM transactions and waiting for the result of how they're processed is, by design, asynchronous.按照设计,发送 EVM 事务并等待它们的处理结果是异步的。 JavaScript uses Promises to be able to handle asynchronous operations.
JavaScript 使用 Promises 来处理异步操作。
The Promise
resolves to a string representing the address, which you are correctly retrieving using the await
keyword. Promise
解析为表示地址的字符串,您使用await
关键字正确检索该地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.