Etherscan says there is not enough ether, why? Arguments, which i enter => requestLoan(3,31,3) and after change account, provideGuarantee(0,3)

I have created dApp and how it looks in my code you can see here

this.etherAmount = 3;
await this.bankContract.methods.requestLoan(this.etherAmount, 31, 2).send({from: this.state.borrower}).then(res => console.log("Request loan " + res.status));
await this.bankContract.methods.provideGuarantee(0, 4).send({from: this.state.guarantor, gas: 40000, value: this.etherAmount}).then(res => console.log("Provide guarantee " + res.status));

Link to transaction => https://rinkeby.etherscan.io/tx/0xab31946f54cb86187dd517ff7c8ebc34730714a9717ee33a11ea22d54a31ed11

function requestLoan(uint etherBorrow, uint8 payBackDate, uint8 
etherInterest) public
    Loan memory loan = Loan({loanee: msg.sender, index: loansCount, etherBorrow: etherBorrow,
                                    payBackDate: now + (payBackDate * 1 days), etherInterest: etherInterest,
                                    _isGuaranteeProvided: false, _isLoanProvided: false, _isLoanExist: true});
    loans[loansCount] = loan;

function provideGuarantee(uint index, uint8 guaranteeInterest) public payable // payable means that value should have ether
        index < loansCount,
        "This index does not exist");

    require(loans[index].loanee != msg.sender,
            "The borrower can't provide a guarantee to himself");

    require(lenders[index] != msg.sender,
            "The lender can't provide guarantee for the loan");

        "This loan already has a guarantee");

    require(guaranteesCount < loansCount || !guarantees[index]._isWaitingForHandling, 
        "This guarantee already waiting for handling of borrower");

    require(guaranteeInterest > 0, 
            "Too low interest");

        msg.value == loans[index].etherBorrow,
        "You don't have enough eather to provide guarantee");

        "This loan does not exist");

        "This guarantee does exist");

    Guarantee memory guarantee = Guarantee({guarantor: msg.sender, etherInterest: guaranteeInterest,
                                                loanIndex: index, _isWaitingForHandling: true, _isGuaranteeExist: true});
    guarantees[index] = guarantee;
  • It's impossible to read your code given the combination of horizontal scroll and vertical scroll required in order to view it. – goodvibration Feb 9 at 9:17

You are providing 3 wei as value to your provideGuarantee function - the same amount you are creating a loan for. In your code you check that if the amount is the same (msg.value == loans[index].etherBorrow) then the contract throws that error: Fail with error 'You don&#39;t have enough eather to provide guarantee.

I'm a bit unsure why you have such a condition and what exactly you are trying to do but probably you simply need to provide more Ethers (weis) as the value?

| improve this answer | |

As stated by LauriPeltonen the check that fails is msg.value == loans[index].etherBorrow since you send 3wei then loans[index].etherBorrow is not 3 when index = 0.

Looking at the transaction history the first successful call to requestLoan was at https://rinkeby.etherscan.io/tx/0x879a238d031e81bac5cc2092a8897b6feaa8f269c0be737ad313c812e4aaef22. Withe the following parameters.

  • etherBorrow = 300000000000
  • payBackDate = 31
  • etherInterest = 5

So unless you have some other function to override a loan data calling to provideGuarantee(0, 4) will fail unless you send 300000000000 wei = 300 gwei.

I'd suggest to always generate events when creating a load so looking at the events you can determine things like index that are assigned during execution.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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