Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

297
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda