Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

295
Views
Error : VM Exception while processing transaction: revert

I am getting this error when I am transfering some tokens to the decentralized bank Here is the code

Test.js:

 await decentralbank.stakeTokens(tokens("100"), {
    from: customer,
  });

DecentralBank.sol:

function stakeTokens(uint256 _amount) public {


    tether.transferFrom(msg.sender, address(this), _amount);

    // update staking balance
    stakingBalance[msg.sender] = stakingBalance[msg.sender] + _amount;

    // add user to stakers array *only* if they haven't staked already
    if (!hasStaked[msg.sender]) {
        stakers.push(msg.sender);
    }

    // update stakng status
    isStaking[msg.sender] = true;
    hasStaked[msg.sender] = true;
}

Tether.sol:

 function transferFrom(
    address _from,
    address _to,
    uint256 _value
) public  returns  (bool success) {
    require(_value <= balanceOf[_from]);
    require(_value <= allowance[_from][msg.sender]);
    balanceOf[_from] -= _value;
    balanceOf[_to] += _value;
    allowance[_from][msg.sender] -= _value;
    emit Transfer(_from, _to, _value);
    return true;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

By looking at that i guess you forgot to approve the token transfer before calling the stakeTokens.

await tether.approve(decentralbank.address, tokens("100"), {
  from: costumer,
});

await decentralbank.stakeTokens(tokens("100"), {
  from: customer,
});

Also, one security note, you should call the transferFrom before all the state changes in the contract in order to avoid re-entrancy attacks, or you can just use this library.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!