Truffle console: Sending Ether to the contract through fallback function

Sending Ether to the contract through fallback function:

I have the following contract:

pragma solidity ^0.5.8;
contract  Victim {
   address owner;
   constructor() public{  
      owner = msg.sender;
   }
  
   function deposit()  payable public {}
}

If I wanted to send Ether to the above contract using deposit function, I used to write:

acc1 = accounts[1]

options = { from: acc1, to : victim.address, value: web3.utils.toWei('99', 'ether')}

and then:

contractObj.deposit.sendTransaction(options)

Now suppose that I have a fallback function instead of deposit function, how can I send Ether to the contract?

1 Like

Hi @zak100,

You can send Ether to a contract that accepts Ether using the following:

1 Like