0
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

contract Lending {
    // calculating the value of loan on the basis of collateral
    uint256 LTV = 20;
    mapping(address => uint256) public addressToAmt;
    mapping(address => uint256) public addressToTime;

    function modifyLTV(uint256 _newVal) public {
        LTV = _newVal;
    }

    // 0.00002(RBTC)*10^8=2000RSAT
    function calculateLoanAmt(uint256 _collateralVal)
        internal
        pure
        returns (uint256)
    {
        uint256 num = _collateralVal * 20;
        uint256 denom = 100;
        return num / denom; // It is returning the value in RSAT
    }

    function requestForLoan(uint256 _collateralVal) internal returns (uint256) {
        uint256 eligibleAmt = calculateLoanAmt(_collateralVal);
        addressToAmt[msg.sender] = eligibleAmt;
        addressToTime[msg.sender] = block.number;

        return eligibleAmt;
    }
}

in the addressToAmt mapping the eligibleAmt value should be added , but everytime I'm querying data in addressToAmt it is returning 0.

Remix output:

"0": "uint256: 0"

Although the return value of requestForLoan() is as expected. Where am I making the mistake?

2
  • your question is not much clear. add some examples or scenarios Jul 16, 2023 at 17:55
  • 1
    How are you checking it on Remix?, you should input the msg.sender address
    – Julissa DC
    Jul 17, 2023 at 16:57

2 Answers 2

0

I've modified the viewing of requestForLoan to public and it worked for me.

function requestForLoan(uint256 _collateralVal) public returns (uint256) {
        uint256 eligibleAmt = calculateLoanAmt(_collateralVal);
        addressToAmt[msg.sender] = eligibleAmt;
        addressToTime[msg.sender] = block.number;

        return eligibleAmt;
    }

enter image description here

0

The code you published is not the same as the Remix example. requestForLoan is marked internal when it clearly has to be external or public.

With that one change, 150 => 30. I get a non-zero addressToTime as well, so I'm not sure what we're trying to solve here.

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.