Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

302
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda