CRYPTO NEWS

My function returns [object Object] instead of a value (ethers.js)(hardhat)

Like the question says, my function returns an object instead of a uint.

This is what I wrote in my script:

   console.log("output of getDefaultLosses:",       (await defaultLedger.getDefaultLosses(4, 200).toString())     ); 

This is what came out in the console:

output of getDefaultLosses: [object Promise] 

This is the code for my smart contract:

    function getDefaultLosses(uint256 currentTime, uint256 amountRepayed) public returns (uint256) {         uint256 defaultLosses;          if (numBorrowersPayingAt[currentTime] == 0) {             totalDefaultLosses -= amountRepayed;             defaultLosses = 0;         }         if (numBorrowersPayingAt[currentTime] == 1) {             numBorrowersPayingAt[currentTime] -= 1;              uint256 totalPaymentExpectedFromInterval = getTotalPaymentsExpectedSinceLastSlice();              defaultLosses =             totalPaymentExpectedFromInterval - amountRepayed;              decreaseExpectedPaymentAt(currentTime, amountRepayed);         }         if (numBorrowersPayingAt[currentTime] > 1) {             decreaseExpectedPaymentAt(currentTime, amountRepayed);             numBorrowersPayingAt[currentTime] -= 1;             defaultLosses = 0;         }          return defaultLosses;     }   function getTotalPaymentsExpectedSinceLastSlice() internal view returns (uint256) {         uint256[] memory tempArr = getTimesForDefaults();         uint256 length = tempArr.length;         uint256 totalPaymentsExpectedFromInterval;         for (uint256 i = 0; i< length; i++){             totalPaymentsExpectedFromInterval += paymentExpectedAt[tempArr[i]];         }         return totalPaymentsExpectedFromInterval;     } 

If I remove toString() from my script, I get this instead:

output of getDefaultLosses: {   hash: '0x20cb4302fe6e330c50fe07f58305add7873b2b34f1bcc0dc77b7c03c1416ca6a',   type: 2,   accessList: [],   blockHash: '0x7996e5cc8dee004399baddb967b8dc621980420e711fd5b8a59a9ff44c7ab033',   blockNumber: 13,   transactionIndex: 0,   confirmations: 1,   from: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',   gasPrice: BigNumber { value: "1179831850" },   maxPriorityFeePerGas: BigNumber { value: "1000000000" },   maxFeePerGas: BigNumber { value: "1359663700" },   gasLimit: BigNumber { value: "29021656" },   to: '0x5FbDB2315678afecb367f032d93F642f64180aa3',   value: BigNumber { value: "0" },   nonce: 12,   data: '0xdaee3958000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000c8',   r: '0x6315d0b0df3cd7435dd54452e40b23fe4d3554badabda5e618cf9ab06938409a',   s: '0x083326bf4ddf593db563cfdea3101512f5b2c9e1f486b1b403e12cc257825640',   v: 0,   creates: null,   chainId: 31337,   wait: [Function (anonymous)] }   

My function returns [object Object] instead of a value (ethers.js)(hardhat)

Shopping cart
There are no products in the cart!
Continue shopping
0