From the Truffle docs:
You can trigger the fallback function by sending a transaction to this
function:
const result = instance.sendTransaction({...});
This is promisified like all available contract instance functions,
and has the same API as web3.eth.sendTransaction
without the callback.
The to
value will be automatically filled in for you.
First, add the fallback function to your contract:
function () external payable {}
Then in your truffle console run the following commands:
truffle(development)> const myContract = await Victim.deployed()
truffle(development)> myContract.sendTransaction({from: accounts[1], value: web3.utils.toWei("1", 'ether')})
You will see something like this:
{
tx: '0x22b2161c3d2df23fa3665e17818f18e0ec1aa85e8651b58173eb98c5129422e3',
receipt: {
transactionHash: '0x22b2161c3d2df23fa3665e17818f18e0ec1aa85e8651b58173eb98c5129422e3',
transactionIndex: 0,
blockHash: '0xfad483d89d468baf3f11169b0c7f2ac8d98eb6c0e9ce8d446447997e90fc0813',
blockNumber: 5,
from: '0xed3e91355793f627432d8033df7d9f410a00d77e',
to: '0x7f17856af4f34e7de93683642fc6e2d4bff44f3a',
gasUsed: 21040,
cumulativeGasUsed: 21040,
contractAddress: null,
logs: [],
status: true,
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
rawLogs: []
},
logs: []
}