1

Hello everybody i'v deployed a erc20 contract on the main network all work fine but when i send ether to the contract adress i have this error : Warning! Error encountered during contract execution [Reverted] i didn't understand why. TxHash: 0x835d9b4106c279e116f97cc6038c6e12004aaac5408ac862436b0d8fc07ea94f contract adress : 0xACdDb1b4a5527af01ED85C74F43F90ecD1276b8E

Thanks,

0

It seems this condition is not met

require(balances[fundsWallet] >= amount);

I checked the rest of the contract code and you don't take into account the msg.value being in Wei, not ETH.

Your buy function

function() payable{
    totalEthInWei = totalEthInWei + msg.value;
    uint256 amount = msg.value * unitsOneEthCanBuy;
    require(balances[fundsWallet] >= amount);

    balances[fundsWallet] = balances[fundsWallet] - amount;
    balances[msg.sender] = balances[msg.sender] + amount;

    Transfer(fundsWallet, msg.sender, amount); // Broadcast a message to the blockchain

    //Transfer ether to fundsWallet
    fundsWallet.transfer(msg.value);                               
}

Should take into account that msg.value is in Wei

uint256 amount = msg.value * unitsOneEthCanBuy / 1000000000000000000;

And you don't need to emit the Transfer() event because it is already emitted in the transfer() function.

Thus your function should be

function() payable{
    totalEthInWei = totalEthInWei + msg.value;
    uint256 amount = msg.value * unitsOneEthCanBuy / 1000000000000000000;
    require(balances[fundsWallet] >= amount);

    balances[fundsWallet] = balances[fundsWallet] - amount;
    balances[msg.sender] = balances[msg.sender] + amount;

    //Transfer ether to fundsWallet
    fundsWallet.transfer(msg.value);                               
}
  • Hello thanks for your response, i have to change my contract even if it s in the main network and i have send token to some peaple? – youyoup Apr 24 '18 at 14:04
  • Or just the account awner of token should have more ether ? – youyoup Apr 24 '18 at 15:48
  • I don't understand the logic of the condition there. What are you trying to achieve with it? – Daniel Luca CleanUnicorn Apr 24 '18 at 20:57
  • verify if the owner of contract got ether more than amount – youyoup Apr 24 '18 at 23:56
  • is this any possibilty to modify contract ? – youyoup Apr 25 '18 at 0:02

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.