0

I'm working on a new Smart Contract for TRON. I need to sum each amount of paying. But when I get the value, I got a REVERT error:

pragma solidity ^0.8.0;

contract Test {

    uint counter = 0;


    function add() public payable {
        counter += msg.value;
    }


    function getCounter() public view returns(uint){
        return counter;
    }

}

The "getCounter" return REVERT error. Why? How can I manage sum of msg.value's ?

Klode
  • 353
  • 3
  • 18
  • Are you sending any `value` along with the transaction that executes the `getCounter()` function? – Petr Hejda Sep 22 '21 at 15:42
  • Of course, with TronIDE.io I send 100 TRX, not sun. The transaction is correct, and the balance of my Testnet TRX address was paid of 100 TRX. – Klode Sep 23 '21 at 05:08
  • I have seen the transaction on tronscan.org, txnID:26f39a8cf32e17ab808fbd939e6a0adf768876ca7aff2f11c2a2ce9db2352a2b - I've seen the contract TC2w4X2AmSrpphp2xPHorCGF8ywTHwuKeL in the Shasta Network, and the read contract method getCounter() return me `root:"100000000"`. So the issue is in the TRON-IDE Interface. – Klode Sep 23 '21 at 05:26

1 Answers1

1

When you're executing the add() function sending along non-zero value, it executes correctly because the function is payable.

However the getCounter() is not payable so you need to execute it with zero value (or add the payable modifier` to the function).

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100