0

I pay for goods with tokens. But after the first call to the function, tokens are not removed from the wallet. Please tell me why when I call the function for the first time, tokens are removed, but are not removed during the next calls? Thanks

function placeBid(uint amount)  public notOwner returns(bool) {
    require(auctionState == State.Running);
    require(count>=amount);
    goods[msg.sender].add(amount);
    startPrice = startPrice*100000000*amount;
    bids[msg.sender].add(startPrice);

    trc20.approve(msg.sender, address(this), startPrice);
    // Move to tokens to contract address
    trc20.transferFrom(msg.sender, address(this), startPrice);
    count = count-amount;
    startPrice=0;
    return true;
}
0

A bit difficult to say as this is a part of a bigger contract. But here's my guess.

At the end of the function you are setting your startPrice to be zero. Next time the function is executed the multiplication of startPrice = startPrice*100000000*amount gives always 0 so you always approve the move of 0 tokens.

| improve this answer | |
  • You were right, thanks) – malysh Feb 10 at 11:59
1

To begin with, change this:

goods[msg.sender].add(amount);

To this:

goods[msg.sender] = goods[msg.sender].add(amount);

And this:

bids[msg.sender].add(startPrice);

To this:

bids[msg.sender] = bids[msg.sender].add(startPrice);

You probably also want to change this:

startPrice = startPrice*100000000*amount

To this:

startPrice = startPrice.mul(100000000).mul(amount)

And this:

count = count-amount

To this:

count = count.sub(amount)
| improve this answer | |
  • Thanks for the amendment. I'm new here) – malysh Feb 10 at 11:45
  • @malysh: You're welcome. Please note that you have posted very partial information, for example, what is startPrice and how it is initialized (and it goes for all the other variables in your code), which makes it rather impossible to actually pinpoint all the problems in your code. I pointed out only the obvious ones. – goodvibration Feb 10 at 11:48

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.