In case of invalid opcode
, use a local variable of type address payable
as workaround:
address payable self = address(this);
uint256 balance = self.balance;
In solidity 0.5.14
, I get an invalid opcode
, debugging showed me, that it is exactly here:
address(this).balance
Test result:
Error: Returned error: VM Exception while processing transaction: invalid opcode
at PromiEvent (node_modules/truffle/build/webpack:/packages/contract/lib/promievent.js:6:1)
at TruffleContract.destroy (node_modules/truffle/build/webpack:/packages/contract/lib/execute.js:158:1)
at Context.it (test/1_PactaTest.js:108:17)
at web3.eth.getBlockNumber.then.result (node_modules/truffle/build/webpack:/packages/core/lib/testing/testrunner.js:161:1)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
Debugging:
debug(development:0x7655ecf8...)>
Pacta.sol:
115: // move whole balance to the owner
116: function withdraw() public managers isActive {
117: uint256 part = address(this).balance / beneficiaries.length;
^^^^^^^^^^^^^^^^^^^^^
debug(development:0x7655ecf8...)>
Transaction halted with a RUNTIME ERROR.
This is likely due to an intentional halting expression, like assert(), require() or revert(). It can also be due to out-of-gas exceptions. Please inspect your transaction parameters and contract code to determine the meaning of this error.