i´m learning Solidity now, and i saw this code on web but when i try to use the method "Deposito" i receive a error. Someone knows what's that ? (PS.: I try to put the value but every time i chose another value different from 0 don't work).

I was using the remix to test code.

pragma solidity ^0.4.2;


mapping (address => uint) private saldos;

function deposito() public returns (uint) {
    saldos[msg.sender] += msg.value;

    // Sem necessidade de "this." ou "self." para variáveis de estado
    // todos as variáveis são inciadas com seu valor default

    LogRealizacaoDeDeposito(msg.sender, msg.value); // dispara evento

    return saldos[msg.sender];
  • 3
    Since you're trying to deposit "value", your method needs to be "payable", otherwise it cannot accept deposits. – Micky Socaci Feb 27 at 0:30
  • 1
    Thanks, man that solves the problem. I really need to read the documentation with more attention. ^^ – Davi Mello Feb 27 at 0:34
  • Post the solution as an answer – Achala Dissanayake Feb 27 at 5:32

For any contract method to be able to accept value transfers, it needs to have the "payable" modifier assigned to it.

function deposito() public payable returns (uint) {}

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.