5

This is my contract:

pragma solidity ^0.4.22;

contract Test {
  event Deposit( address indexed from, uint amt );
  event Withdrawal( address indexed to, uint amt );

  address owner;

  constructor() public {
    owner = msg.sender;
  }

  function Withdraw(uint amt) public {
    require(msg.sender == owner);
    msg.sender.transfer(amt);
    emit Withdrawal(msg.sender, amt);
  }

  function () payable external {
    emit Deposit(msg.sender, msg.value);
  }

}

I use truffle v4.1.11 and Solidity v0.4.24

I run docker: run -d -p 8545:8545 trufflesuite/ganache-cli:latest -a 10 --debug

I connect with: truffle console

It connects, the contract deploys. And I can send like this:

Test.at('0xd8f24367662cd76f0723271cfd6000ab3d317e40').send(web3.toWei(1,"ether"))
{ tx:
   '0x2b438220d8ab4fe3428409f9d6a9bcb9ab800e0a975b216f06dc8654658c2d45',
  receipt:
   { transactionHash:
      '0x2b438220d8ab4fe3428409f9d6a9bcb9ab800e0a975b216f06dc8654658c2d45',
     transactionIndex: 0,
     blockHash:
      '0xfcdf0b31d4ac77001f1d6c760e2e5759addc184d311756a97b3f4aa3a86dcaa0',
     blockNumber: 27,
     from: '0xb9cd57a299ebf2eca11435ed890d5de0717f2889',
     to: '0xd8f24367662cd76f0723271cfd6000ab3d317e40',
     gasUsed: 21040,
     cumulativeGasUsed: 21040,
     contractAddress: null,
     logs: [],
     status: '0x1',
     logsBloom:
      '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
     v: '0x1b',
     r:
      '0x6f76b56ff878c10c3dfed4315d071c160bb1572194197b9f974b7d168d7e816c',
     s:
      '0x23f68bc8533232aa113aeb0f2ba8e6425f2e0783bcbbc9e6cf825342890d0e73' },
  logs: [] }

It all works, but you will notice that logs is empty - why was the Deposit event not emitted?

2 Answers 2

2

Seeing as nobody else is answering, I could provide you with an answer of some sorts.

First things first: your contract is not valid with the compiler version you are implying in the code (0.4.22) - keyword constructor did not exist back then and you had to use constructors in a different way. But, I see you are in reality using 0.4.24 so all's fine.

If you put the code in Remix everything works just fine. However, Remix gives gas usage of 22489 instead of your 21040.

So my best guess is that the transaction is faulty in some way. It succeeded (status 0x1) but something isn't right. Or perhaps your ganache is too old or something? Or maybe running it in docker interferes with something?

Unfortunately I can't give you a more definite answer, but hopefully it's better than nothing.

1

Code runs fine and does emit an event on Remix IDE. I had to change pragma solidity to 0.5.0, though. Try the following:

  • Update truffle to v5.

  • Change pragma solidity to ^0.5.0.

  • Run a locally installed ganache cli (e.g npm install -g ganache-cli).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.