简体   繁体   English

智能合约的返回地址函数返回承诺对象而不是松露测试中的地址

[英]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.

相关问题 松露测试给出“错误:尝试运行调用合同功能的交易,但收件人地址___不是合同地址” - Truffle test gives “Error: Attempting to run transaction which calls a contract function, but recipient address ___ is not a contract address” Web3js-部署后立即返回智能合约地址 - Web3js - Return smart contract address immediately after deployment 如何从js访问智能合约的公共地址? - How to access public address of smart contract from js? 映射动态数组从智能合约起反应,其值包括地址和字符串 - map dynamic array in react from a smart contract with values an address and a string 使用 truffle/hdwallet-provider 调用智能合约 function - Calling a smart contract function using truffle/hdwallet-provider 智能合约返回值 function - Return value of smart contract function 如何将智能合约返回的地址转换为可读的字符串? - How do I convert the address returned from my smart contract into a readable string? 如何在同一个 javascript 程序中部署和获取智能合约的地址 - How to deploy and get address of smart contract in same javascript program 用松露测试我的智能合约时“TypeError: inst.createZombie(...).send is not a function” - “TypeError: inst.createZombie(…).send is not a function” when testing my smart contract with truffle javascript:异步 function 不返回从 ZDB974238714CA8DE634A7CE1D083A4 获取的 object 而是返回 [Fobject promise] - javascript: async function not returning fetched object from API but instead returns [object promise]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM